Update youtubeExtractor.ts

This commit is contained in:
CK 2026-03-05 21:39:26 +05:30 committed by GitHub
parent 5fa02d7c53
commit a2a801d68a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -416,9 +416,20 @@ async function collectAllFormats(
const adaptiveAudio: StreamCandidate[] = [];
const hlsManifests: Array<{ clientKey: string; priority: number; url: string }> = [];
for (const client of CLIENTS) {
try {
const resp = await fetchPlayerResponse(videoId, client, apiKey, visitorData);
// Fire all client requests in parallel — same approach as Kotlin coroutines
const results = await Promise.allSettled(
CLIENTS.map(client => fetchPlayerResponse(videoId, client, apiKey, visitorData)
.then(resp => ({ client, resp }))
)
);
for (const result of results) {
if (result.status === 'rejected') {
logger.warn('YouTubeExtractor', `Client request rejected:`, result.reason);
continue;
}
const { client, resp } = result.value;
if (!resp) continue;
const status = resp.playabilityStatus?.status;
@ -499,9 +510,6 @@ async function collectAllFormats(
}
logger.info('YouTubeExtractor', `[${client.key}] progressive=${nProg} video=${nVid} audio=${nAud} hls=${sd.hlsManifestUrl ? 1 : 0}`);
} catch (err) {
logger.warn('YouTubeExtractor', `[${client.key}] Failed:`, err);
}
}
return { progressive, adaptiveVideo, adaptiveAudio, hlsManifests };