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 IAlbumInfoResult { 37 isEnd?: boolean; 38 albumItem?: IAlbum.IAlbumItemBase; 39 musicList?: IMusic.IMusicItem[]; 40 } 41 42 interface ISheetInfoResult { 43 isEnd?: boolean; 44 sheetItem?: IMusic.IMusicSheetItemBase; 45 musicList?: IMusic.IMusicItem[]; 46 } 47 48 interface IGetRecommendSheetTagsResult { 49 // 固定的tag 50 pinned?: IMusic.IMusicSheetItemBase[]; 51 data?: IMusic.IMusicSheetGroupItem[]; 52 } 53 54 interface IPluginDefine { 55 /** 来源名 */ 56 platform: string; 57 /** 匹配的版本号 */ 58 appVersion?: string; 59 /** 插件版本 */ 60 version?: string; 61 /** 远程更新的url */ 62 srcUrl?: string; 63 /** 主键,会被存储到mediameta中 */ 64 primaryKey?: string[]; 65 /** 默认搜索类型 */ 66 defaultSearchType?: ICommon.SupportMediaType; 67 /** 有效搜索类型 */ 68 supportedSearchType?: ICommon.SupportMediaType[]; 69 /** 插件缓存控制 */ 70 cacheControl?: 'cache' | 'no-cache' | 'no-store'; 71 /** 用户自定义输入 */ 72 userEnv?: IUserEnv[]; 73 /** 提示文本 */ 74 hints?: Record<string, string[]>; 75 /** 搜索 */ 76 search?: ISearchFunc; 77 /** 获取根据音乐信息获取url */ 78 getMediaSource?: ( 79 musicItem: IMusic.IMusicItemBase, 80 quality: IMusic.IQualityKey, 81 ) => Promise<IMediaSourceResult | null>; 82 /** 根据主键去查询歌曲信息 */ 83 getMusicInfo?: ( 84 musicBase: ICommon.IMediaBase, 85 ) => Promise<Partial<IMusic.IMusicItem> | null>; 86 /** 获取歌词 */ 87 getLyric?: ( 88 musicItem: IMusic.IMusicItemBase, 89 ) => Promise<ILyric.ILyricSource | null>; 90 /** 获取专辑信息,里面的歌曲分页 */ 91 getAlbumInfo?: ( 92 albumItem: IAlbum.IAlbumItemBase, 93 page: number, 94 ) => Promise<IAlbumInfoResult | null>; 95 /** 获取歌单信息,有分页 */ 96 getMusicSheetInfo?: ( 97 sheetItem: IMusic.IMusicSheetItem, 98 page: number, 99 ) => Promise<ISheetInfoResult | null>; 100 /** 获取作品,有分页 */ 101 getArtistWorks?: IGetArtistWorksFunc; 102 /** 导入歌单 */ 103 // todo: 数据结构应该是IMusicSheetItem 104 importMusicSheet?: ( 105 urlLike: string, 106 ) => Promise<IMusic.IMusicItem[] | null>; 107 /** 导入单曲 */ 108 importMusicItem?: ( 109 urlLike: string, 110 ) => Promise<IMusic.IMusicItem | null>; 111 /** 获取榜单 */ 112 getTopLists?: () => Promise<IMusic.IMusicSheetGroupItem[]>; 113 // todo:分页 114 /** 获取榜单详情 */ 115 getTopListDetail?: ( 116 topListItem: IMusic.IMusicSheetItemBase, 117 ) => Promise<ICommon.WithMusicList<IMusic.IMusicSheetItemBase>>; 118 /** 获取热门歌单tag */ 119 getRecommendSheetTags?: () => Promise<IGetRecommendSheetTagsResult>; 120 /** 歌单列表 */ 121 getRecommendSheetsByTag?: ( 122 tag: ICommon.IUnique, 123 page?: number, 124 ) => Promise<ICommon.PaginationResponse<IMusic.IMusicSheetItemBase>>; 125 } 126 127 export interface IPluginInstance extends IPluginDefine { 128 /** 内部属性 */ 129 /** 插件路径 */ 130 _path: string; 131 } 132 133 type R = Required<IPluginInstance>; 134 export type IPluginInstanceMethods = { 135 [K in keyof R as R[K] extends (...args: any) => any ? K : never]: R[K]; 136 }; 137 138 /** 插件其他属性 */ 139 export type IPluginMeta = { 140 order: number; 141 userEnv: Record<string, string>; 142 }; 143} 144