xref: /MusicFree/src/types/plugin.d.ts (revision ddece18e7942a667c4a0b92c4f164e9a18b0ceee)
1declare namespace IPlugin {
2    export interface IMediaSourceResult {
3        headers?: Record<string, string>;
4        /** 兜底播放 */
5        url?: string;
6        /** UA */
7        userAgent?: string;
8        /** 音质 */
9        quality?: IMusic.IQualityKey;
10    }
11
12    export interface ISearchResult<T extends ICommon.SupportMediaType> {
13        isEnd?: boolean;
14        data: ICommon.SupportMediaItemBase[T][];
15    }
16
17    export type ISearchResultType = ICommon.SupportMediaType;
18
19    type ISearchFunc = <T extends ICommon.SupportMediaType>(
20        query: string,
21        page: number,
22        type: T,
23    ) => Promise<ISearchResult<T>>;
24
25    type IGetArtistWorksFunc = <T extends IArtist.ArtistMediaType>(
26        artistItem: IArtist.IArtistItem,
27        page: number,
28        type: T,
29    ) => Promise<ISearchResult<T>>;
30
31    interface IUserEnv {
32        key: string;
33        name: string;
34    }
35
36    interface IAlbumInfoResult {
37        isEnd?: boolean;
38        albumItem?: IAlbum.IAlbumItemBase;
39        musicList?: IMusic.IMusicItem[];
40    }
41
42    interface ISheetInfoResult {
43        isEnd?: boolean;
44        sheetItem?: IMusic.IMusicSheetItemBase;
45        musicList?: IMusic.IMusicItem[];
46    }
47
48    interface IGetRecommendSheetTagsResult {
49        // 固定的tag
50        pinned?: IMusic.IMusicSheetItemBase[];
51        data?: IMusic.IMusicSheetGroupItem[];
52    }
53
54    interface IPluginDefine {
55        /** 来源名 */
56        platform: string;
57        /** 匹配的版本号 */
58        appVersion?: string;
59        /** 插件版本 */
60        version?: string;
61        /** 远程更新的url */
62        srcUrl?: string;
63        /** 主键,会被存储到mediameta中 */
64        primaryKey?: string[];
65        /** 默认搜索类型 */
66        defaultSearchType?: ICommon.SupportMediaType;
67        /** 插件缓存控制 */
68        cacheControl?: 'cache' | 'no-cache' | 'no-store';
69        /** 用户自定义输入 */
70        userEnv?: IUserEnv[];
71        /** 提示文本 */
72        hints?: Record<string, string[]>;
73        /** 搜索 */
74        search?: ISearchFunc;
75        /** 获取根据音乐信息获取url */
76        getMediaSource?: (
77            musicItem: IMusic.IMusicItemBase,
78            quality: IMusic.IQualityKey,
79        ) => Promise<IMediaSourceResult | null>;
80        /** 根据主键去查询歌曲信息 */
81        getMusicInfo?: (
82            musicBase: ICommon.IMediaBase,
83        ) => Promise<Partial<IMusic.IMusicItem> | null>;
84        /** 获取歌词 */
85        getLyric?: (
86            musicItem: IMusic.IMusicItemBase,
87        ) => Promise<ILyric.ILyricSource | null>;
88        /** 获取专辑信息,里面的歌曲分页 */
89        getAlbumInfo?: (
90            albumItem: IAlbum.IAlbumItemBase,
91            page: number,
92        ) => Promise<IAlbumInfoResult | null>;
93        /** 获取歌单信息,有分页 */
94        getMusicSheetInfo?: (
95            sheetItem: IMusic.IMusicSheetItem,
96            page: number,
97        ) => Promise<ISheetInfoResult | null>;
98        /** 获取作品,有分页 */
99        getArtistWorks?: IGetArtistWorksFunc;
100        /** 导入歌单 */
101        // todo: 数据结构应该是IMusicSheetItem
102        importMusicSheet?: (
103            urlLike: string,
104        ) => Promise<IMusic.IMusicItem[] | null>;
105        /** 导入单曲 */
106        importMusicItem?: (
107            urlLike: string,
108        ) => Promise<IMusic.IMusicItem | null>;
109        /** 获取榜单 */
110        getTopLists?: () => Promise<IMusic.IMusicSheetGroupItem[]>;
111        // todo:分页
112        /** 获取榜单详情 */
113        getTopListDetail?: (
114            topListItem: IMusic.IMusicSheetItemBase,
115        ) => Promise<ICommon.WithMusicList<IMusic.IMusicSheetItemBase>>;
116        /** 获取热门歌单tag */
117        getRecommendSheetTags?: () => Promise<IGetRecommendSheetTagsResult>;
118        /** 歌单列表 */
119        getRecommendSheetsByTag?: (
120            tag: ICommon.IUnique,
121            page?: number,
122        ) => Promise<ICommon.PaginationResponse<IMusic.IMusicSheetItemBase>>;
123    }
124
125    export interface IPluginInstance extends IPluginDefine {
126        /** 内部属性 */
127        /** 插件路径 */
128        _path: string;
129    }
130
131    type R = Required<IPluginInstance>;
132    export type IPluginInstanceMethods = {
133        [K in keyof R as R[K] extends (...args: any) => any ? K : never]: R[K];
134    };
135
136    /** 插件其他属性 */
137    export type IPluginMeta = {
138        order: number;
139        userEnv: Record<string, string>;
140    };
141}
142