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 IUserEnv { 32 key: string; 33 name: string; 34 } 35 36 interface IPluginDefine { 37 /** 来源名 */ 38 platform: string; 39 /** 匹配的版本号 */ 40 appVersion?: string; 41 /** 插件版本 */ 42 version?: string; 43 /** 远程更新的url */ 44 srcUrl?: string; 45 /** 主键,会被存储到mediameta中 */ 46 primaryKey?: string[]; 47 /** 默认搜索类型 */ 48 defaultSearchType?: ICommon.SupportMediaType; 49 /** 插件缓存控制 */ 50 cacheControl?: 'cache' | 'no-cache' | 'no-store'; 51 /** 用户自定义输入 */ 52 userEnv?: IUserEnv[]; 53 /** 提示文本 */ 54 hints?: Record<string, string[]>; 55 /** 搜索 */ 56 search?: ISearchFunc; 57 /** 获取根据音乐信息获取url */ 58 getMediaSource?: ( 59 musicItem: IMusic.IMusicItemBase, 60 quality: IMusic.IQualityKey, 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 getTopLists?: () => Promise<IMusic.IMusicTopListGroupItem[]>; 87 // todo:分页 88 /** 获取榜单详情 */ 89 getTopListDetail?: ( 90 topListItem: IMusic.IMusicTopListItem, 91 ) => Promise<ICommon.WithMusicList<IMusic.IMusicTopListItem>>; 92 } 93 94 export interface IPluginInstance extends IPluginDefine { 95 /** 内部属性 */ 96 /** 插件路径 */ 97 _path: string; 98 } 99 100 type R = Required<IPluginInstance>; 101 export type IPluginInstanceMethods = { 102 [K in keyof R as R[K] extends (...args: any) => any ? K : never]: R[K]; 103 }; 104 105 /** 插件其他属性 */ 106 export type IPluginMeta = { 107 order: number; 108 userEnv: Record<string, string>; 109 }; 110} 111