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