@@ -8,6 +8,10 @@ import { qqMusicMatch } from "@/api/qqmusic";
88import { songLevelData } from "@/utils/meta" ;
99import { getPlayerInfoObj } from "@/utils/format" ;
1010import { LyricProcessor , type LyricProcessorOptions , type LyricResult } from "./LyricProcessor" ;
11+ import { albumDetail } from "@/api/album" ;
12+
13+ const albumArtistCache = new Map < number , string [ ] | Promise < string [ ] > > ( ) ;
14+ const MAX_ALBUM_ARTIST_CACHE_SIZE = 100 ;
1115
1216interface DownloadConfig {
1317 fileName : string ;
@@ -19,6 +23,7 @@ interface DownloadConfig {
1923 saveMetaFile : boolean ;
2024 songData : SongType ;
2125 lyric : string ;
26+ albumArtists : string [ ] ;
2227 skipIfExist : boolean ;
2328 threadCount : number ;
2429 referer ?: string ;
@@ -55,6 +60,7 @@ class SongDownloadStrategy implements DownloadStrategy {
5560 private basicLyric = "" ;
5661 private ttmlLyric = "" ;
5762 private yrcLyric = "" ;
63+ private albumArtists : string [ ] = [ ] ;
5864
5965 constructor (
6066 public readonly song : SongType ,
@@ -125,6 +131,44 @@ class SongDownloadStrategy implements DownloadStrategy {
125131 this . yrcLyric = verbatim . yrc ;
126132 }
127133 }
134+
135+ // 处理专辑艺术家信息
136+ if ( this . settingStore . downloadMeta ) {
137+ const album = this . song . album ;
138+ if ( typeof album !== "string" ) {
139+ const cached = albumArtistCache . get ( album . id ) ;
140+ if ( cached instanceof Array ) {
141+ this . albumArtists = cached ;
142+ } else if ( cached instanceof Promise ) {
143+ this . albumArtists = await cached ;
144+ } else {
145+ const promise = albumDetail ( album . id )
146+ . then ( ( res ) => {
147+ if ( res . code === 200 ) {
148+ const artistName = res ?. album ?. artists ?. map ( ( a ) => a . name ) || [ ] ;
149+ albumArtistCache . set ( album . id , artistName ) ;
150+ // 控制缓存大小
151+ if ( albumArtistCache . size > MAX_ALBUM_ARTIST_CACHE_SIZE ) {
152+ for ( const [ k , v ] of albumArtistCache ) {
153+ if ( v instanceof Array ) {
154+ albumArtistCache . delete ( k ) ;
155+ if ( albumArtistCache . size < MAX_ALBUM_ARTIST_CACHE_SIZE ) break ;
156+ }
157+ }
158+ }
159+ return artistName ;
160+ }
161+ return [ ] ;
162+ } )
163+ . catch ( ( e ) => {
164+ console . error ( `获取专辑艺术家失败: ${ album . id } ` , e ) ;
165+ return [ ] ;
166+ } ) ;
167+ albumArtistCache . set ( album . id , promise ) ;
168+ this . albumArtists = await promise ;
169+ }
170+ }
171+ }
128172 }
129173 /**
130174 * 获取下载配置
@@ -146,6 +190,7 @@ class SongDownloadStrategy implements DownloadStrategy {
146190 saveMetaFile : downloadMeta && saveMetaFile ,
147191 songData : cloneDeep ( this . song ) ,
148192 lyric : this . basicLyric ,
193+ albumArtists : this . albumArtists ,
149194 skipIfExist : true ,
150195 threadCount : downloadThreadCount ,
151196 enableDownloadHttp2 : enableDownloadHttp2 ,
0 commit comments