xref: /MusicFree/src/types/plugin.d.ts (revision 2aa881935ca35b8fb1abc4206e0dc35149231456)
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 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            quality: IMusic.IQualityKey,
59        ) => Promise<IMediaSourceResult | null>;
60        /** 根据主键去查询歌曲信息 */
61        getMusicInfo?: (
62            musicBase: ICommon.IMediaBase,
63        ) => Promise<Partial<IMusic.IMusicItem> | null>;
64        /** 获取歌词 */
65        getLyric?: (
66            musicItem: IMusic.IMusicItemBase,
67        ) => Promise<ILyric.ILyricSource | null>;
68        /** 获取专辑信息,里面的歌曲不要分页 */
69        getAlbumInfo?: (
70            albumItem: IAlbum.IAlbumItemBase,
71        ) => Promise<IAlbum.IAlbumItem | null>;
72        /** 获取作品,有分页 */
73        getArtistWorks?: IGetArtistWorksFunc;
74        /** 导入歌单 */
75        // todo: 数据结构应该是IMusicSheetItem
76        importMusicSheet?: (
77            urlLike: string,
78        ) => Promise<IMusic.IMusicItem[] | null>;
79        /** 导入单曲 */
80        importMusicItem?: (
81            urlLike: string,
82        ) => Promise<IMusic.IMusicItem | null>;
83        /** 获取榜单 */
84        getTopLists?: () => Promise<IMusic.IMusicTopListGroupItem[]>;
85        // todo:分页
86        /** 获取榜单详情 */
87        getTopListDetail?: (
88            topListItem: IMusic.IMusicTopListItem,
89        ) => Promise<ICommon.WithMusicList<IMusic.IMusicTopListItem>>;
90    }
91
92    export interface IPluginInstance extends IPluginDefine {
93        /** 内部属性 */
94        /** 插件路径 */
95        _path: string;
96    }
97
98    type R = Required<IPluginInstance>;
99    export type IPluginInstanceMethods = {
100        [K in keyof R as R[K] extends (...args: any) => any ? K : never]: R[K];
101    };
102
103    /** 插件其他属性 */
104    export type IPluginMeta = {
105        order: number;
106        userEnv: Record<string, string>;
107    };
108}
109