xref: /MusicFree/src/types/plugin.d.ts (revision 6704747af84cebd842b258efac7143542722fac5)
1declare namespace IPlugin {
2  export interface IMusicTrackResult {
3    headers?: Record<string, string>;
4    url: string;
5    userAgent?: string;
6  }
7
8  export interface ISearchResult<T extends ICommon.SupportMediaType> {
9    isEnd?: boolean;
10    data: ICommon.SupportMediaItemBase[T][];
11  }
12
13  export type ISearchResultType = ICommon.SupportMediaType;
14
15  type ISearchFunc = <T extends ICommon.SupportMediaType>(
16    query: string,
17    page: number,
18    type: T,
19  ) => Promise<ISearchResult<T>>;
20
21  type IQueryArtistWorksFunc = <
22    T extends IArtist.ArtistMediaType,
23  >(
24    artistItem: IArtist.IArtistItem,
25    page: number,
26    type: T,
27  ) => Promise<ISearchResult<T>>;
28
29  interface IPluginDefine {
30    /** 来源名 */
31    platform: string;
32    /** 匹配的版本号 */
33    appVersion?: string;
34    /** 主键,会被存储到mediameta中 */
35    primaryKey: string[];
36    /** 默认搜索类型 */
37    defaultSearchType?: ICommon.SupportMediaType;
38    /** 搜索 */
39    search?: ISearchFunc;
40    /** 获取根据音乐信息获取url */
41    getMusicTrack?: (
42      musicItem: IMusic.IMusicItemBase,
43    ) => Promise<IMusicTrackResult | null>;
44    /** 根据主键去查询歌曲信息 */
45    getMusicInfo?: (musicBase: ICommon.IMediaBase) => Promise<IMusic.IMusicItem | null>;
46    /** 获取歌词 */
47    getLyric?: (musicItem: IMusic.IMusicItemBase) => Promise<ILyric.ILyricSource | null>;
48    /** 获取专辑信息,里面的歌曲不要分页 */
49    getAlbumInfo?: (
50      albumItem: IAlbum.IAlbumItemBase,
51    ) => Promise<IAlbum.IAlbumItem | null>;
52    /** 获取作品,有分页 */
53    queryArtistWorks?: IQueryArtistWorksFunc;
54  }
55
56  export interface IPluginInstance extends IPluginDefine {
57    /** 内部属性 */
58    /** 插件路径 */
59    _path: string;
60  }
61
62  type R = Required<IPluginInstance>;
63  export type IPluginInstanceMethods = {
64    [K in keyof R as R[K] extends (...args: any) => any ? K : never]: R[K];
65  };
66}
67