Skip to content

Commit 49dbce6

Browse files
authored
Merge pull request #932 from MoYingJi/pr/dba
fix(download): 正确地设置了 Album Artist
2 parents 1490a2a + 6b46d04 commit 49dbce6

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

electron/main/services/DownloadService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class DownloadService {
3333
downloadLyric?: boolean;
3434
saveMetaFile?: boolean;
3535
lyric?: string;
36+
albumArtists?: string[];
3637
songData?: any;
3738
skipIfExist?: boolean;
3839
threadCount?: number;
@@ -54,6 +55,7 @@ export class DownloadService {
5455
fileType,
5556
path,
5657
lyric,
58+
albumArtists,
5759
downloadMeta,
5860
downloadCover,
5961
downloadLyric,
@@ -97,6 +99,7 @@ export class DownloadService {
9799
if (downloadMeta && songData) {
98100
const artistNames = getArtistNames(songData.artists);
99101
const artist = artistNames.join(", ") || "未知艺术家";
102+
const albumArtist = albumArtists?.join(", ");
100103
const coverUrl =
101104
downloadCover && (songData.coverSize?.l || songData.cover)
102105
? songData.coverSize?.l || songData.cover
@@ -107,6 +110,7 @@ export class DownloadService {
107110
album:
108111
(typeof songData.album === "string" ? songData.album : songData.album?.name) ||
109112
"未知专辑",
113+
albumArtist: albumArtist && albumArtist !== "" ? albumArtist : undefined,
110114
coverUrl: coverUrl,
111115
lyric: downloadLyric && lyric ? lyric : undefined,
112116
description: songData.alia || "",

src/core/resource/DownloadManager.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { qqMusicMatch } from "@/api/qqmusic";
88
import { songLevelData } from "@/utils/meta";
99
import { getPlayerInfoObj } from "@/utils/format";
1010
import { 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

1216
interface 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

Comments
 (0)