api/internal: also transplant youtube HEAD requests

This commit is contained in:
jj
2025-03-06 17:16:13 +00:00
parent 187b1f8f05
commit 068ae2f2e7

View File

@ -53,14 +53,25 @@ async function handleYoutubeStream(streamInfo, res) {
const cleanup = () => (res.end(), closeRequest(streamInfo.controller)); const cleanup = () => (res.end(), closeRequest(streamInfo.controller));
try { try {
const req = await fetch(streamInfo.url, { let req, attempts = 3;
headers: getHeaders('youtube'), while (attempts--) {
method: 'HEAD', req = await fetch(streamInfo.url, {
dispatcher: streamInfo.dispatcher, headers: getHeaders('youtube'),
signal method: 'HEAD',
}); dispatcher: streamInfo.dispatcher,
signal
});
streamInfo.url = req.url;
if (req.status === 403 && streamInfo.transplant) {
try {
await streamInfo.transplant(streamInfo.dispatcher);
} catch {
break;
}
} else break;
}
streamInfo.url = req.url;
const size = BigInt(req.headers.get('content-length')); const size = BigInt(req.headers.get('content-length'));
if (req.status !== 200 || !size) { if (req.status !== 200 || !size) {