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