Skip to content

Commit 35197b9

Browse files
committed
youtube: fix custom fetch breakage
LuanRT/YouTube.js#962 (comment)
1 parent a7b1d4f commit 35197b9

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

api/src/processing/services/youtube.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import HLS from "hls-parser";
22

3-
import { fetch } from "undici";
4-
import { Innertube, Session } from "youtubei.js";
3+
import { fetch, Request } from "undici";
4+
import { Innertube, Platform, Session } from "youtubei.js";
55

66
import { env } from "../../config.js";
77
import { getCookie } from "../cookie/manager.js";
@@ -206,10 +206,24 @@ export default async function (o) {
206206
let yt;
207207
try {
208208
yt = await cloneInnertube(
209-
(input, init) => fetch(input, {
210-
...init,
211-
dispatcher: o.dispatcher
212-
}),
209+
(input, init) => {
210+
const url = typeof input === 'string'
211+
? new URL(input)
212+
: input instanceof URL
213+
? input
214+
: new URL(input.url);
215+
216+
const request = new Request(
217+
url,
218+
input instanceof Platform.shim.Request
219+
? input : undefined
220+
);
221+
222+
return fetch(request, {
223+
...init,
224+
dispatcher: o.dispatcher
225+
});
226+
},
213227
useSession
214228
);
215229
} catch (e) {

0 commit comments

Comments
 (0)