xref: /MusicFree/src/types/plugin.d.ts (revision b7048bd186614b21df0139d0ea098fdf91a74107)
1declare namespace IPlugin {
2    export interface IMediaSourceResult {
3        headers?: Record<string, string>;
4        /** 兜底播放 */
5        url?: string;
6        /** UA */
7        userAgent?: string;
8        /** 音质 */
9        qualities?: IMusic.IQuality;
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 IPluginDefine {
37        /** 来源名 */
38        platform: string;
39        /** 匹配的版本号 */
40        appVersion?: string;
41        /** 插件版本 */
42        version?: string;
43        /** 远程更新的url */
44        srcUrl?: string;
45        /** 主键,会被存储到mediameta中 */
46        primaryKey?: string[];
47        /** 默认搜索类型 */
48        defaultSearchType?: ICommon.SupportMediaType;
49        /** 插件缓存控制 */
50        cacheControl?: 'cache' | 'no-cache' | 'no-store';
51        /** 用户自定义输入 */
52        userEnv?: IUserEnv[];
53        /** 搜索 */
54        search?: ISearchFunc;
55        /** 获取根据音乐信息获取url */
56        getMediaSource?: (
57            musicItem: IMusic.IMusicItemBase,
58        ) => Promise<IMediaSourceResult | null>;
59        /** 根据主键去查询歌曲信息 */
60        getMusicInfo?: (
61            musicBase: ICommon.IMediaBase,
62        ) => Promise<Partial<IMusic.IMusicItem> | null>;
63        /** 获取歌词 */
64        getLyric?: (
65            musicItem: IMusic.IMusicItemBase,
66        ) => Promise<ILyric.ILyricSource | null>;
67        /** 获取专辑信息,里面的歌曲不要分页 */
68        getAlbumInfo?: (
69            albumItem: IAlbum.IAlbumItemBase,
70        ) => Promise<IAlbum.IAlbumItem | null>;
71        /** 获取作品,有分页 */
72        getArtistWorks?: IGetArtistWorksFunc;
73        /** 导入歌单 */
74        // todo: 数据结构应该是IMusicSheetItem
75        importMusicSheet?: (
76            urlLike: string,
77        ) => Promise<IMusic.IMusicItem[] | null>;
78        /** 导入单曲 */
79        importMusicItem?: (
80            urlLike: string,
81        ) => Promise<IMusic.IMusicItem | null>;
82    }
83
84    export interface IPluginInstance extends IPluginDefine {
85        /** 内部属性 */
86        /** 插件路径 */
87        _path: string;
88    }
89
90    type R = Required<IPluginInstance>;
91    export type IPluginInstanceMethods = {
92        [K in keyof R as R[K] extends (...args: any) => any ? K : never]: R[K];
93    };
94
95    /** 插件其他属性 */
96    export type IPluginMeta = {
97        order: number;
98        userEnv: Record<string, string>;
99    };
100}
101