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