From 0ff4769eb0d658beef524a6f7f0b52c86be4bf4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=82=A6?= Date: Tue, 13 Jan 2026 11:34:16 +0800 Subject: [PATCH] =?UTF-8?q?=20=20-=20Netease-sync/server.js=20=20=20=20=20?= =?UTF-8?q?=20=20-=20=E6=96=B0=E5=A2=9E=20buildDownloadHeadersForUrl(url,?= =?UTF-8?q?=20source)=20=20=20=20=20=20=20-=20=E5=BD=93=E7=9B=B4=E9=93=BE?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E5=8C=85=E5=90=AB=20qqmusic=20=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E8=87=AA=E5=8A=A8=E5=B8=A6=E4=B8=8A=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20-=20Referer:=20https://y.qq.com/=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20-=20Origin:=20https://y.qq.com=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20-=20Range:=20bytes=3D0-=20=20=20=20=20=20=20-?= =?UTF-8?q?=20=E7=9B=B4=E9=93=BE=E4=B8=8B=E8=BD=BD=E6=97=B6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=AF=A5=E5=A4=B4=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netease-sync/server.js | 44 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/Netease-sync/server.js b/Netease-sync/server.js index a2b3754..488e6ea 100644 --- a/Netease-sync/server.js +++ b/Netease-sync/server.js @@ -271,6 +271,33 @@ function buildDownloadHeaders(source) { return headers; } +function buildDownloadHeadersForUrl(url, source) { + const headers = buildDownloadHeaders(source); + if (!url) return headers; + + try { + const parsed = new URL(url); + const host = parsed.host || ''; + + if (host.includes('qqmusic')) { + headers['Referer'] = 'https://y.qq.com/'; + headers['Origin'] = 'https://y.qq.com'; + headers['Accept'] = '*/*'; + headers['Range'] = 'bytes=0-'; + } else if (host.includes('music.163.com')) { + headers['Referer'] = 'https://music.163.com/'; + headers['Origin'] = 'https://music.163.com'; + } else if (host.includes('kuwo')) { + headers['Referer'] = 'https://www.kuwo.cn/'; + headers['Origin'] = 'https://www.kuwo.cn'; + } + } catch (e) { + return headers; + } + + return headers; +} + function getPreferredQualities(types) { const preference = ['flac24bit', 'flac', '320k', '128k']; if (!Array.isArray(types) || types.length === 0) { @@ -383,18 +410,19 @@ async function tryDownloadWithCandidates(song, source, baseName, candidates, dow const finalFile = path.join(MUSIC_DIR, `${baseName}.${ext}`); try { - await downloadFile(directUrl, tempFile, downloadHeaders); + const resolvedHeaders = buildDownloadHeadersForUrl(directUrl, source); + await downloadFile(directUrl, tempFile, resolvedHeaders); try { // Try to download cover image let coverPath = null; - try { - const coverUrl = `${TUNEHUB_API_URL}/api/?source=${source}&id=${song.id}&type=pic`; - coverPath = path.join(MUSIC_DIR, `temp_cover_${Date.now()}_${song.id}.jpg`); - await downloadFile(coverUrl, coverPath, downloadHeaders); - } catch (e) { - console.warn(`[Sync] Failed to download cover for ${song.name}:`, e.message); - } + try { + const coverUrl = `${TUNEHUB_API_URL}/api/?source=${source}&id=${song.id}&type=pic`; + coverPath = path.join(MUSIC_DIR, `temp_cover_${Date.now()}_${song.id}.jpg`); + await downloadFile(coverUrl, coverPath, downloadHeaders); + } catch (e) { + console.warn(`[Sync] Failed to download cover for ${song.name}:`, e.message); + } // Write Metadata (Title, Artist, Album, Cover) await writeMetadata(tempFile, finalFile, {