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