xref: /MusicFree/src/types/plugin.d.ts (revision 7fb901109d23a379901d3a07c4fcb24021621c5d)
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        ) => Promise<ILyric.ILyricSource | null>;
102        /** 获取专辑信息,里面的歌曲分页 */
103        getAlbumInfo?: (
104            albumItem: IAlbum.IAlbumItemBase,
105            page: number,
106        ) => Promise<IAlbumInfoResult | null>;
107        /** 获取歌单信息,有分页 */
108        getMusicSheetInfo?: (
109            sheetItem: IMusic.IMusicSheetItem,
110            page: number,
111        ) => Promise<ISheetInfoResult | null>;
112        /** 获取作品,有分页 */
113        getArtistWorks?: IGetArtistWorksFunc;
114        /** 导入歌单 */
115        // todo: 数据结构应该是IMusicSheetItem
116        importMusicSheet?: (
117            urlLike: string,
118        ) => Promise<IMusic.IMusicItem[] | null>;
119        /** 导入单曲 */
120        importMusicItem?: (
121            urlLike: string,
122        ) => Promise<IMusic.IMusicItem | null>;
123        /** 获取榜单 */
124        getTopLists?: () => Promise<IMusic.IMusicSheetGroupItem[]>;
125        /** 获取榜单详情 */
126        getTopListDetail?: (
127            topListItem: IMusic.IMusicSheetItemBase,
128            page: number,
129        ) => Promise<ITopListInfoResult>;
130        /** 获取热门歌单tag */
131        getRecommendSheetTags?: () => Promise<IGetRecommendSheetTagsResult>;
132        /** 歌单列表 */
133        getRecommendSheetsByTag?: (
134            tag: ICommon.IUnique,
135            page?: number,
136        ) => Promise<ICommon.PaginationResponse<IMusic.IMusicSheetItemBase>>;
137        /** 获取评论 */
138        getMusicComments?: (
139            musicItem: IMusic.IMusicItem,
140        ) => Promise<ICommon.PaginationResponse<IMedia.IComment>>;
141        /** 迁移插件 */
142        migrateFromOtherPlugin?: (
143            mediaItem: ICommon.IMediaBase,
144            fromPlatform: string,
145        ) => Promise<{
146            isOk: boolean; // 是否迁移成功
147            data?: ICommon.IMediaBase; // 迁移后的数据
148        }>;
149    }
150
151    export interface IPluginInstance extends IPluginDefine {
152        /** 内部属性 */
153        /** 插件路径 */
154        _path: string;
155    }
156
157    type R = Required<IPluginInstance>;
158    export type IPluginInstanceMethods = {
159        [K in keyof R as R[K] extends (...args: any) => any ? K : never]: R[K];
160    };
161
162    /** 插件其他属性 */
163    export type IPluginMeta = {
164        order: number;
165        userVariables: Record<string, string>;
166        enabled?: boolean;
167    };
168}
169