fix: youtube stream failing midway

This commit is contained in:
Daniel Wykerd 2023-04-29 12:54:04 +02:00
parent 0d868e0bd3
commit c73beab5ba
No known key found for this signature in database
GPG Key ID: 232F3D855CE6281E
2 changed files with 4 additions and 3 deletions

View File

@ -33,6 +33,6 @@
"node-cache": "^5.1.2", "node-cache": "^5.1.2",
"url-pattern": "1.0.3", "url-pattern": "1.0.3",
"xml-js": "^1.6.11", "xml-js": "^1.6.11",
"youtubei.js": "4.1.1" "youtubei.js": "^5.0.0"
} }
} }

View File

@ -1,5 +1,5 @@
import { spawn } from "child_process"; import { spawn } from "child_process";
import { Constants as YTConstants } from "youtubei.js"; import { Constants as YTConstants, Utils } from "youtubei.js";
import ffmpeg from "ffmpeg-static"; import ffmpeg from "ffmpeg-static";
import got from "got"; import got from "got";
import { ffmpegArgs, genericUserAgent } from "../config.js"; import { ffmpegArgs, genericUserAgent } from "../config.js";
@ -63,7 +63,8 @@ function createYoutubeStream(format_url) {
const chunk = got.get(`${format_url}&range=${chunk_start}-${chunk_end || ''}`, { const chunk = got.get(`${format_url}&range=${chunk_start}-${chunk_end || ''}`, {
headers: { headers: {
...YTConstants.STREAM_HEADERS ...YTConstants.STREAM_HEADERS,
'User-Agent': Utils.getRandomUserAgent('desktop'),
}, },
isStream: true, isStream: true,
responseType: 'buffer', responseType: 'buffer',