fix(backend): download via default client (web_music media 403s); add optional proxy

The PO token provider works (web_music gets a token) but web_music's media URLs
still 403 from a datacenter IP. Prefer the default player clients for the
DOWNLOAD (their URLs go through with a PO token), keeping web_music only as a
fallback for Art-Track extraction; the YTM search still leads with web_music.

Also add an optional YTDLP_PROXY (--proxy) — the durable fix if the IP stays
flagged (403/429) even with a PO token. Empty → unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Opus 4.8 committed 2026-08-17 17:07:34 +02:00
1 parent 4daf87b550
commit 31d4a72e62
3 files changed
+15 -4

No files matched your search

+3
View File
@@ -13,6 +13,9 @@ const CONFIG = {
// provider service; set its URL here (e.g. http://bgutil-provider:4416). Empty → no PO token used // provider service; set its URL here (e.g. http://bgutil-provider:4416). Empty → no PO token used
// (yt-dlp runs exactly as before). See docker-compose.yml. // (yt-dlp runs exactly as before). See docker-compose.yml.
potProviderUrl: process.env.POT_PROVIDER_URL || '', potProviderUrl: process.env.POT_PROVIDER_URL || '',
// Optional proxy for yt-dlp (e.g. a residential/rotating proxy) — the durable fix when the
// datacenter IP stays flagged (403/429) even with a PO token. Empty → yt-dlp runs directly.
ytdlpProxy: process.env.YTDLP_PROXY || '',
}; };
module.exports = CONFIG; module.exports = CONFIG;
+11 -4
View File
@@ -142,6 +142,10 @@ async function downloadTrack({ jobId, artist, rawArtist, albumArtist, title, alb
? ['--extractor-args', `youtubepot-bgutilhttp:base_url=${CONFIG.potProviderUrl}`] ? ['--extractor-args', `youtubepot-bgutilhttp:base_url=${CONFIG.potProviderUrl}`]
: []; : [];
// Optional proxy — the durable fix when a datacenter IP stays flagged (403/429) even with a PO
// token. Route yt-dlp through a residential/rotating proxy via YTDLP_PROXY. Empty → not used.
const proxyArgs = () => (CONFIG.ytdlpProxy ? ['--proxy', CONFIG.ytdlpProxy] : []);
const baseArgs = [ const baseArgs = [
'--extract-audio', '--extract-audio',
'--audio-format', CONFIG.audioFmt, '--audio-format', CONFIG.audioFmt,
@@ -152,11 +156,13 @@ async function downloadTrack({ jobId, artist, rawArtist, albumArtist, title, alb
'--newline', '--newline',
// Hard upper size limit — prevents saving a wrong 28-min video as a ~52 MB mp3 // Hard upper size limit — prevents saving a wrong 28-min video as a ~52 MB mp3
'--max-filesize', '30M', '--max-filesize', '30M',
// Use the web_music player client (falling back to default) so YouTube Music // For the DOWNLOAD, prefer the default clients (their media URLs go through with a PO token from
// "Art Track" / topic uploads are reachable. The android_vr client returns // a datacenter IP) and keep web_music only as a fallback for Art Tracks that only it can extract.
// "This video is not available" for many YTM tracks that play fine in the browser. // web_music's own media URLs 403 from datacenter IPs even with a valid PO token. (The YTM *search*
'--extractor-args', 'youtube:player_client=web_music,default', // in getYtmVideoUrls still leads with web_music, which is where Art-Track discovery matters.)
'--extractor-args', 'youtube:player_client=default,web_music',
...potArgs(), ...potArgs(),
...proxyArgs(),
]; ];
const spawnYtdlp = (args) => new Promise((resolve, reject) => { const spawnYtdlp = (args) => new Promise((resolve, reject) => {
@@ -230,6 +236,7 @@ async function downloadTrack({ jobId, artist, rawArtist, albumArtist, title, alb
// native Songs shelf (where the actual artist track lives). // native Songs shelf (where the actual artist track lives).
'--extractor-args', 'youtube:player_client=web_music,default', '--extractor-args', 'youtube:player_client=web_music,default',
...potArgs(), ...potArgs(),
...proxyArgs(),
], { env: { ...process.env, PYTHONUNBUFFERED: '1' } }); ], { env: { ...process.env, PYTHONUNBUFFERED: '1' } });
proc.stdout.on('data', d => { proc.stdout.on('data', d => {
const text = d.toString(); const text = d.toString();
+1
View File
@@ -535,6 +535,7 @@ app.post('/api/youtube/resolve', async (req, res) => {
'--playlist-items', '1-50', '--playlist-items', '1-50',
// PO token provider (if configured) to get past YouTube's datacenter-IP block. Empty → omitted. // PO token provider (if configured) to get past YouTube's datacenter-IP block. Empty → omitted.
...(CONFIG.potProviderUrl ? ['--extractor-args', `youtubepot-bgutilhttp:base_url=${CONFIG.potProviderUrl}`] : []), ...(CONFIG.potProviderUrl ? ['--extractor-args', `youtubepot-bgutilhttp:base_url=${CONFIG.potProviderUrl}`] : []),
...(CONFIG.ytdlpProxy ? ['--proxy', CONFIG.ytdlpProxy] : []),
url, url,
], { timeout: 45000, maxBuffer: 20 * 1024 * 1024 }, (err, out, stderr) => { ], { timeout: 45000, maxBuffer: 20 * 1024 * 1024 }, (err, out, stderr) => {
if (err && !out?.trim()) return reject(new Error(stderr?.trim() || err.message)); if (err && !out?.trim()) return reject(new Error(stderr?.trim() || err.message));