| 
1 | 1 | import HLS from "hls-parser";  | 
2 | 2 | 
 
  | 
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";  | 
5 | 5 | 
 
  | 
6 | 6 | import { env } from "../../config.js";  | 
7 | 7 | import { getCookie } from "../cookie/manager.js";  | 
8 | 8 | import { getYouTubeSession } from "../helpers/youtube-session.js";  | 
9 | 9 | 
 
  | 
 | 10 | +// https://github.com/LuanRT/YouTube.js/pull/1052  | 
 | 11 | +Platform.shim.eval = async (data, env) => {  | 
 | 12 | +  const properties = [];  | 
 | 13 | + | 
 | 14 | +  if (env.n) {  | 
 | 15 | +    properties.push(`n: exportedVars.nFunction("${env.n}")`)  | 
 | 16 | +  }  | 
 | 17 | + | 
 | 18 | +  if (env.sig) {  | 
 | 19 | +    properties.push(`sig: exportedVars.sigFunction("${env.sig}")`)  | 
 | 20 | +  }  | 
 | 21 | + | 
 | 22 | +  const code = `${data.output}\nreturn { ${properties.join(', ')} }`;  | 
 | 23 | + | 
 | 24 | +  return new Function(code)();  | 
 | 25 | +}  | 
 | 26 | + | 
10 | 27 | const PLAYER_REFRESH_PERIOD = 1000 * 60 * 15; // ms  | 
11 | 28 | 
 
  | 
12 | 29 | let innertube, lastRefreshedAt;  | 
@@ -206,10 +223,24 @@ export default async function (o) {  | 
206 | 223 |     let yt;  | 
207 | 224 |     try {  | 
208 | 225 |         yt = await cloneInnertube(  | 
209 |  | -            (input, init) => fetch(input, {  | 
210 |  | -                ...init,  | 
211 |  | -                dispatcher: o.dispatcher  | 
212 |  | -            }),  | 
 | 226 | +            (input, init) => {  | 
 | 227 | +                const url = typeof input === 'string'  | 
 | 228 | +                          ? new URL(input)  | 
 | 229 | +                          : input instanceof URL  | 
 | 230 | +                            ? input  | 
 | 231 | +                            : new URL(input.url);  | 
 | 232 | + | 
 | 233 | +                const request = new Request(  | 
 | 234 | +                    url,  | 
 | 235 | +                    input instanceof Platform.shim.Request  | 
 | 236 | +                    ? input : undefined  | 
 | 237 | +                );  | 
 | 238 | + | 
 | 239 | +                return fetch(request, {  | 
 | 240 | +                    ...init,  | 
 | 241 | +                    dispatcher: o.dispatcher  | 
 | 242 | +                });  | 
 | 243 | +            },  | 
213 | 244 |             useSession  | 
214 | 245 |         );  | 
215 | 246 |     } catch (e) {  | 
@@ -529,7 +560,7 @@ export default async function (o) {  | 
529 | 560 |         }  | 
530 | 561 | 
 
  | 
531 | 562 |         if (!clientsWithNoCipher.includes(innertubeClient) && innertube) {  | 
532 |  | -            urls = audio.decipher(innertube.session.player);  | 
 | 563 | +            urls = await audio.decipher(innertube.session.player);  | 
533 | 564 |         }  | 
534 | 565 | 
 
  | 
535 | 566 |         let cover = `https://i.ytimg.com/vi/${o.id}/maxresdefault.jpg`;  | 
@@ -576,8 +607,8 @@ export default async function (o) {  | 
576 | 607 |             filenameAttributes.extension = o.container === "auto" ? codecList[codec].container : o.container;  | 
577 | 608 | 
 
  | 
578 | 609 |             if (!clientsWithNoCipher.includes(innertubeClient) && innertube) {  | 
579 |  | -                video = video.decipher(innertube.session.player);  | 
580 |  | -                audio = audio.decipher(innertube.session.player);  | 
 | 610 | +                video = await video.decipher(innertube.session.player);  | 
 | 611 | +                audio = await audio.decipher(innertube.session.player);  | 
581 | 612 |             } else {  | 
582 | 613 |                 video = video.url;  | 
583 | 614 |                 audio = audio.url;  | 
 | 
0 commit comments