- Netease-sync/server.js
- 新增 buildDownloadHeadersForUrl(url, source)
- 当直链域名包含 qqmusic 时,自动带上
- Referer: https://y.qq.com/
- Origin: https://y.qq.com
- Range: bytes=0-
- 直链下载时使用该头部
This commit is contained in:
@@ -271,6 +271,33 @@ function buildDownloadHeaders(source) {
|
|||||||
return headers;
|
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) {
|
function getPreferredQualities(types) {
|
||||||
const preference = ['flac24bit', 'flac', '320k', '128k'];
|
const preference = ['flac24bit', 'flac', '320k', '128k'];
|
||||||
if (!Array.isArray(types) || types.length === 0) {
|
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}`);
|
const finalFile = path.join(MUSIC_DIR, `${baseName}.${ext}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await downloadFile(directUrl, tempFile, downloadHeaders);
|
const resolvedHeaders = buildDownloadHeadersForUrl(directUrl, source);
|
||||||
|
await downloadFile(directUrl, tempFile, resolvedHeaders);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Try to download cover image
|
// Try to download cover image
|
||||||
let coverPath = null;
|
let coverPath = null;
|
||||||
try {
|
try {
|
||||||
const coverUrl = `${TUNEHUB_API_URL}/api/?source=${source}&id=${song.id}&type=pic`;
|
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`);
|
coverPath = path.join(MUSIC_DIR, `temp_cover_${Date.now()}_${song.id}.jpg`);
|
||||||
await downloadFile(coverUrl, coverPath, downloadHeaders);
|
await downloadFile(coverUrl, coverPath, downloadHeaders);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(`[Sync] Failed to download cover for ${song.name}:`, e.message);
|
console.warn(`[Sync] Failed to download cover for ${song.name}:`, e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write Metadata (Title, Artist, Album, Cover)
|
// Write Metadata (Title, Artist, Album, Cover)
|
||||||
await writeMetadata(tempFile, finalFile, {
|
await writeMetadata(tempFile, finalFile, {
|
||||||
|
|||||||
Reference in New Issue
Block a user