xref: /MusicFree/src/types/plugin.d.ts (revision ceb900cd812eb1b086ac040a306ddf325339e920)
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 IGetRecommendSheetTagsResult {
43        // 固定的tag
44        pinned?: IMusic.IMusicSheetItemBase[];
45        data?: IMusic.IMusicSheetGroupItem[];
46    }
47
48    interface IPluginDefine {
49        /** 来源名 */
50        platform: string;
51        /** 匹配的版本号 */
52        appVersion?: string;
53        /** 插件版本 */
54        version?: string;
55        /** 远程更新的url */
56        srcUrl?: string;
57        /** 主键,会被存储到mediameta中 */
58        primaryKey?: string[];
59        /** 默认搜索类型 */
60        defaultSearchType?: ICommon.SupportMediaType;
61        /** 插件缓存控制 */
62        cacheControl?: 'cache' | 'no-cache' | 'no-store';
63        /** 用户自定义输入 */
64        userEnv?: IUserEnv[];
65        /** 提示文本 */
66        hints?: Record<string, string[]>;
67        /** 搜索 */
68        search?: ISearchFunc;
69        /** 获取根据音乐信息获取url */
70        getMediaSource?: (
71            musicItem: IMusic.IMusicItemBase,
72            quality: IMusic.IQualityKey,
73        ) => Promise<IMediaSourceResult | null>;
74        /** 根据主键去查询歌曲信息 */
75        getMusicInfo?: (
76            musicBase: ICommon.IMediaBase,
77        ) => Promise<Partial<IMusic.IMusicItem> | null>;
78        /** 获取歌词 */
79        getLyric?: (
80            musicItem: IMusic.IMusicItemBase,
81        ) => Promise<ILyric.ILyricSource | null>;
82        /** 获取专辑信息,里面的歌曲分页 */
83        getAlbumInfo?: (
84            albumItem: IAlbum.IAlbumItemBase,
85            page: number,
86        ) => Promise<IAlbumInfoResult | null>;
87        /** 获取作品,有分页 */
88        getArtistWorks?: IGetArtistWorksFunc;
89        /** 导入歌单 */
90        // todo: 数据结构应该是IMusicSheetItem
91        importMusicSheet?: (
92            urlLike: string,
93        ) => Promise<IMusic.IMusicItem[] | null>;
94        /** 导入单曲 */
95        importMusicItem?: (
96            urlLike: string,
97        ) => Promise<IMusic.IMusicItem | null>;
98        /** 获取榜单 */
99        getTopLists?: () => Promise<IMusic.IMusicSheetGroupItem[]>;
100        // todo:分页
101        /** 获取榜单详情 */
102        getTopListDetail?: (
103            topListItem: IMusic.IMusicSheetItemBase,
104        ) => Promise<ICommon.WithMusicList<IMusic.IMusicSheetItemBase>>;
105        /** 获取热门歌单tag */
106        getRecommendSheetTags?: () => Promise<IGetRecommendSheetTagsResult>;
107        /** 歌单列表 */
108        getRecommendSheetsByTag?: (
109            tag: ICommon.IUnique,
110            page?: number,
111        ) => Promise<ICommon.PaginationResponse<IMusic.IMusicSheetItemBase>>;
112    }
113
114    export interface IPluginInstance extends IPluginDefine {
115        /** 内部属性 */
116        /** 插件路径 */
117        _path: string;
118    }
119
120    type R = Required<IPluginInstance>;
121    export type IPluginInstanceMethods = {
122        [K in keyof R as R[K] extends (...args: any) => any ? K : never]: R[K];
123    };
124
125    /** 插件其他属性 */
126    export type IPluginMeta = {
127        order: number;
128        userEnv: Record<string, string>;
129    };
130}
131