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