Skip to content

Commit

Permalink
api/internal: also transplant youtube HEAD requests
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbmoron committed Mar 6, 2025
1 parent 187b1f8 commit 068ae2f
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions api/src/stream/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,25 @@ async function handleYoutubeStream(streamInfo, res) {
const cleanup = () => (res.end(), closeRequest(streamInfo.controller));

try {
const req = await fetch(streamInfo.url, {
headers: getHeaders('youtube'),
method: 'HEAD',
dispatcher: streamInfo.dispatcher,
signal
});
let req, attempts = 3;
while (attempts--) {
req = await fetch(streamInfo.url, {
headers: getHeaders('youtube'),
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'));

if (req.status !== 200 || !size) {
Expand Down

0 comments on commit 068ae2f

Please sign in to comment.