1declare namespace IPlugin { 2 export interface IMediaSourceResult { 3 headers?: Record<string, string>; 4 /** 兜底播放 */ 5 url?: string; 6 /** 标准音质 */ 7 urlST?: string; 8 /** 高品质 */ 9 urlHQ?: string; 10 /** 超高音质 */ 11 urlSQ?: string; 12 userAgent?: string; 13 } 14 15 export interface ISearchResult<T extends ICommon.SupportMediaType> { 16 isEnd?: boolean; 17 data: ICommon.SupportMediaItemBase[T][]; 18 } 19 20 export type ISearchResultType = ICommon.SupportMediaType; 21 22 type ISearchFunc = <T extends ICommon.SupportMediaType>( 23 query: string, 24 page: number, 25 type: T, 26 ) => Promise<ISearchResult<T>>; 27 28 type IGetArtistWorksFunc = <T extends IArtist.ArtistMediaType>( 29 artistItem: IArtist.IArtistItem, 30 page: number, 31 type: T, 32 ) => Promise<ISearchResult<T>>; 33 34 interface IUserEnv { 35 key: string; 36 name: string; 37 } 38 39 interface IPluginDefine { 40 /** 来源名 */ 41 platform: string; 42 /** 匹配的版本号 */ 43 appVersion?: string; 44 /** 插件版本 */ 45 version?: string; 46 /** 远程更新的url */ 47 srcUrl?: string; 48 /** 主键,会被存储到mediameta中 */ 49 primaryKey?: string[]; 50 /** 默认搜索类型 */ 51 defaultSearchType?: ICommon.SupportMediaType; 52 /** 插件缓存控制 */ 53 cacheControl?: 'cache' | 'no-cache' | 'no-store'; 54 /** 用户自定义输入 */ 55 userEnv?: IUserEnv[]; 56 /** 搜索 */ 57 search?: ISearchFunc; 58 /** 获取根据音乐信息获取url */ 59 getMediaSource?: ( 60 musicItem: IMusic.IMusicItemBase, 61 ) => Promise<IMediaSourceResult | null>; 62 /** 根据主键去查询歌曲信息 */ 63 getMusicInfo?: ( 64 musicBase: ICommon.IMediaBase, 65 ) => Promise<Partial<IMusic.IMusicItem> | null>; 66 /** 获取歌词 */ 67 getLyric?: ( 68 musicItem: IMusic.IMusicItemBase, 69 ) => Promise<ILyric.ILyricSource | null>; 70 /** 获取专辑信息,里面的歌曲不要分页 */ 71 getAlbumInfo?: ( 72 albumItem: IAlbum.IAlbumItemBase, 73 ) => Promise<IAlbum.IAlbumItem | null>; 74 /** 获取作品,有分页 */ 75 getArtistWorks?: IGetArtistWorksFunc; 76 /** 导入歌单 */ 77 // todo: 数据结构应该是IMusicSheetItem 78 importMusicSheet?: ( 79 urlLike: string, 80 ) => Promise<IMusic.IMusicItem[] | null>; 81 /** 导入单曲 */ 82 importMusicItem?: ( 83 urlLike: string, 84 ) => Promise<IMusic.IMusicItem | null>; 85 } 86 87 export interface IPluginInstance extends IPluginDefine { 88 /** 内部属性 */ 89 /** 插件路径 */ 90 _path: string; 91 } 92 93 type R = Required<IPluginInstance>; 94 export type IPluginInstanceMethods = { 95 [K in keyof R as R[K] extends (...args: any) => any ? K : never]: R[K]; 96 }; 97 98 /** 插件其他属性 */ 99 export type IPluginMeta = { 100 order: number; 101 userEnv: Record<string, string>; 102 }; 103} 104