plugin.d.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. type WithMusicList<T> = T & {
  2. musicList?: IMusic.IMusicItem[];
  3. };
  4. declare namespace ICommon {
  5. export type SupportMediaType = "music" | "album" | "artist" | 'sheet';
  6. export type SupportMediaItemBase = {
  7. music: Partial<IMusic.IMusicItem>;
  8. album: Partial<IAlbum.IAlbumItem>;
  9. artist: Partial<IArtist.IArtistItem>;
  10. sheet: Partial<IMusicSheet.IMusicSheetItem>;
  11. };
  12. export type IMediaBase = {
  13. id: string;
  14. platform: string;
  15. [k: string]: any;
  16. };
  17. }
  18. declare namespace IMusic {
  19. type IQualityKey = "low" | "standard" | "high" | "super";
  20. type IQuality = Record<
  21. IQualityKey,
  22. {
  23. url?: string;
  24. size?: string | number;
  25. }
  26. >;
  27. }
  28. declare namespace ILyric {
  29. interface ILyricSource {
  30. lrc?: string;
  31. rawLrc?: string;
  32. }
  33. }
  34. declare namespace IMusicSheet {
  35. interface IMusicSheetItem {
  36. /** 封面图 */
  37. coverImg?: string;
  38. /** 标题 */
  39. title: string;
  40. /** 歌单id */
  41. id: string;
  42. /** 描述 */
  43. description: string;
  44. [k: string]: any;
  45. }
  46. interface IMusicTopListGroupItem {
  47. /** 分组标题 */
  48. title?: string;
  49. /** 数据 */
  50. data: Array<IMusicSheetItem>;
  51. }
  52. }
  53. declare namespace IPlugin {
  54. type ICacheControl = "cache" | "no-cache" | "no-store";
  55. interface ISearchResult<T extends ICommon.SupportMediaType> {
  56. isEnd?: boolean;
  57. data: ICommon.SupportMediaItemBase[T][];
  58. }
  59. type ISearchFunc = <T extends ICommon.SupportMediaType>(
  60. query: string,
  61. page: number,
  62. type: T
  63. ) => Promise<ISearchResult<T>>;
  64. interface ISearchResult<T extends ICommon.SupportMediaType> {
  65. isEnd?: boolean;
  66. data: ICommon.SupportMediaItemBase[T][];
  67. }
  68. interface IMediaSourceResult {
  69. headers?: Record<string, string>;
  70. /** 兜底播放 */
  71. url?: string;
  72. /** UA */
  73. userAgent?: string;
  74. /** 音质 */
  75. quality?: IMusic.IQualityKey;
  76. }
  77. interface IUserVariable {
  78. /** 变量键名 */
  79. key: string;
  80. /** 变量名 */
  81. name?: string;
  82. }
  83. interface IPluginDefine {
  84. /** 插件名 */
  85. platform: string;
  86. /** 匹配的版本号 */
  87. appVersion?: string;
  88. /** 插件版本 */
  89. version?: string;
  90. /** 远程更新的url */
  91. srcUrl?: string;
  92. /** 主键,会被存储到mediameta中 */
  93. primaryKey?: string[];
  94. /** 默认搜索类型 */
  95. defaultSearchType?: ICommon.SupportMediaType;
  96. /** 插件缓存控制 */
  97. cacheControl?: ICacheControl;
  98. /** 用户自定义输入 */
  99. userVariables?: IUserVariable[];
  100. /** 搜索 */
  101. search?: ISearchFunc;
  102. /** 获取根据音乐信息获取url */
  103. getMediaSource?: (
  104. musicItem: IMusic.IMusicItem,
  105. quality: IMusic.IQualityKey
  106. ) => Promise<IMediaSourceResult | null>;
  107. /** 根据主键去查询歌曲信息 */
  108. getMusicInfo?: (
  109. musicBase: ICommon.IMediaBase
  110. ) => Promise<Partial<IMusic.IMusicItem> | null>;
  111. /** 获取歌词 */
  112. getLyric?: (
  113. musicItem: IMusic.IMusicItem
  114. ) => Promise<ILyric.ILyricSource | null>;
  115. /** 获取专辑信息,里面的歌曲分页 */
  116. getAlbumInfo?: (
  117. albumItem: IAlbum.IAlbumItem,
  118. page: number
  119. ) => Promise<IAlbum.IAlbumInfoResult | null>;
  120. /** 获取作品,有分页 */
  121. getArtistWorks?: <T extends Exclude<ICommon.SupportMediaType, "artist">>(
  122. artistItem: IArtist.IArtistItem,
  123. page: number,
  124. type: T
  125. ) => Promise<ISearchResult<T>>;
  126. /** 导入歌单 */
  127. importMusicSheet?: (urlLike: string) => Promise<IMusic.IMusicItem[] | null>;
  128. /** 导入单曲 */
  129. importMusicItem?: (urlLike: string) => Promise<IMusic.IMusicItem | null>;
  130. /** 获取榜单 */
  131. getTopLists?: () => Promise<IMusicSheet.IMusicTopListGroupItem[]>;
  132. /** 获取榜单详情 */
  133. getTopListDetail?: (
  134. topListItem: IMusicSheet.IMusicSheetItem
  135. ) => Promise<WithMusicList<IMusicSheet.IMusicSheetItem>>;
  136. }
  137. }