'更新'
This commit is contained in:
+9
-4
@@ -6,7 +6,7 @@ const { fetchLyric, mergeLrc, parseCredits } = require('./lyrics');
|
||||
const { fetchNeteaseAlbumDetail, fetchNeteaseSongDetail } = require('./metadata');
|
||||
const { downloadFile, fetchJSON } = require('./network');
|
||||
const { embedCover } = require('./tagging');
|
||||
const { sanitize, sleep } = require('./utils');
|
||||
const { sanitize, formatPersonNames, sleep } = require('./utils');
|
||||
|
||||
async function downloadSong(songId, level, {
|
||||
downloadLyric = true,
|
||||
@@ -42,7 +42,8 @@ async function downloadSongOnce(songId, level, {
|
||||
const result = await fetchJSON(`${API.music}?id=${songId}&level=${level}`);
|
||||
if (result.code !== 200 || !result.data?.url) throw new Error(result.msg || 'API 返回错误');
|
||||
|
||||
const { name, artist, album, url: audioUrl, br, size, level: actualLevel, picUrl } = result.data;
|
||||
const { name, artist: rawArtist, album, url: audioUrl, br, size, level: actualLevel, picUrl } = result.data;
|
||||
const artist = formatPersonNames(rawArtist);
|
||||
const ext = audioUrl.match(/\.(mp3|flac|m4a|wav|aac)(\?|$)/i)?.[1] || 'mp3';
|
||||
const baseName = sanitize(outputBaseName || `${artist} - ${name}`);
|
||||
const fileName = `${baseName}.${ext}`;
|
||||
@@ -105,10 +106,10 @@ async function downloadSongOnce(songId, level, {
|
||||
if (detail) {
|
||||
if (detail.trackNo) tagMeta.trackNo = detail.trackNo;
|
||||
if (detail.disc) tagMeta.disc = detail.disc;
|
||||
const albumArtist = detail.artists?.map(item => item.name).join(' / ');
|
||||
if (albumArtist) tagMeta.albumArtist = albumArtist;
|
||||
if (detail.album?.id) {
|
||||
const albumDetail = await fetchNeteaseAlbumDetail(detail.album.id);
|
||||
if (albumDetail?.albumArtist) tagMeta.albumArtist = albumDetail.albumArtist;
|
||||
if (albumDetail?.isCompilation) tagMeta.compilation = true;
|
||||
if (albumDetail?.publishTime) {
|
||||
const date = new Date(albumDetail.publishTime);
|
||||
tagMeta.year = date.getFullYear();
|
||||
@@ -118,6 +119,10 @@ async function downloadSongOnce(songId, level, {
|
||||
if (albumDetail?.company) tagMeta.publisher = albumDetail.company;
|
||||
if (tagMeta.trackNo && albumDetail?.size) tagMeta.trackNo = `${tagMeta.trackNo}/${albumDetail.size}`;
|
||||
}
|
||||
if (!tagMeta.albumArtist) {
|
||||
const fallbackAlbumArtist = detail.artists?.map(item => item.name).join(' / ');
|
||||
if (fallbackAlbumArtist) tagMeta.albumArtist = fallbackAlbumArtist;
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
await embedCover(dest, picUrl, tagMeta);
|
||||
|
||||
Reference in New Issue
Block a user