plugin.d.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 IPluginDefine {
  78. /** 插件名 */
  79. platform: string;
  80. /** 匹配的版本号 */
  81. appVersion?: string;
  82. /** 插件版本 */
  83. version?: string;
  84. /** 远程更新的url */
  85. srcUrl?: string;
  86. /** 主键,会被存储到mediameta中 */
  87. primaryKey?: string[];
  88. /** 默认搜索类型 */
  89. defaultSearchType?: ICommon.SupportMediaType;
  90. /** 插件缓存控制 */
  91. cacheControl?: ICacheControl;
  92. /** 搜索 */
  93. search?: ISearchFunc;
  94. /** 获取根据音乐信息获取url */
  95. getMediaSource?: (
  96. musicItem: IMusic.IMusicItem,
  97. quality: IMusic.IQualityKey
  98. ) => Promise<IMediaSourceResult | null>;
  99. /** 根据主键去查询歌曲信息 */
  100. getMusicInfo?: (
  101. musicBase: ICommon.IMediaBase
  102. ) => Promise<Partial<IMusic.IMusicItem> | null>;
  103. /** 获取歌词 */
  104. getLyric?: (
  105. musicItem: IMusic.IMusicItem
  106. ) => Promise<ILyric.ILyricSource | null>;
  107. /** 获取专辑信息,里面的歌曲分页 */
  108. getAlbumInfo?: (
  109. albumItem: IAlbum.IAlbumItem,
  110. page: number
  111. ) => Promise<IAlbum.IAlbumInfoResult | null>;
  112. /** 获取作品,有分页 */
  113. getArtistWorks?: <T extends Exclude<ICommon.SupportMediaType, "artist">>(
  114. artistItem: IArtist.IArtistItem,
  115. page: number,
  116. type: T
  117. ) => Promise<ISearchResult<T>>;
  118. /** 导入歌单 */
  119. importMusicSheet?: (urlLike: string) => Promise<IMusic.IMusicItem[] | null>;
  120. /** 导入单曲 */
  121. importMusicItem?: (urlLike: string) => Promise<IMusic.IMusicItem | null>;
  122. /** 获取榜单 */
  123. getTopLists?: () => Promise<IMusicSheet.IMusicTopListGroupItem[]>;
  124. /** 获取榜单详情 */
  125. getTopListDetail?: (
  126. topListItem: IMusicSheet.IMusicSheetItem
  127. ) => Promise<WithMusicList<IMusicSheet.IMusicSheetItem>>;
  128. }
  129. }