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