youtube: use the freebind dispatcher if available
This commit is contained in:
parent
d8913472ad
commit
d5aa27f5f9
1 changed files with 23 additions and 2 deletions
|
@ -1,8 +1,9 @@
|
||||||
import { Innertube } from 'youtubei.js';
|
import { Innertube, Session } from 'youtubei.js';
|
||||||
import { maxVideoDuration } from '../../config.js';
|
import { maxVideoDuration } from '../../config.js';
|
||||||
import { cleanString } from '../../sub/utils.js';
|
import { cleanString } from '../../sub/utils.js';
|
||||||
|
import { fetch } from 'undici'
|
||||||
|
|
||||||
const yt = await Innertube.create();
|
const ytBase = await Innertube.create();
|
||||||
|
|
||||||
const codecMatch = {
|
const codecMatch = {
|
||||||
h264: {
|
h264: {
|
||||||
|
@ -22,7 +23,27 @@ const codecMatch = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cloneInnertube = (customFetch) => {
|
||||||
|
const session = new Session(
|
||||||
|
ytBase.session.context,
|
||||||
|
ytBase.session.key,
|
||||||
|
ytBase.session.api_version,
|
||||||
|
ytBase.session.account_index,
|
||||||
|
ytBase.session.player,
|
||||||
|
undefined,
|
||||||
|
customFetch ?? ytBase.session.http.fetch,
|
||||||
|
ytBase.session.cache
|
||||||
|
);
|
||||||
|
|
||||||
|
const yt = new Innertube(session);
|
||||||
|
return yt;
|
||||||
|
}
|
||||||
|
|
||||||
export default async function(o) {
|
export default async function(o) {
|
||||||
|
const yt = cloneInnertube(
|
||||||
|
(input, init) => fetch(input, { ...init, dispatcher: o.dispatcher })
|
||||||
|
);
|
||||||
|
|
||||||
let info, isDubbed, format = o.format || "h264";
|
let info, isDubbed, format = o.format || "h264";
|
||||||
let quality = o.quality === "max" ? "9000" : o.quality; // 9000(p) - max quality
|
let quality = o.quality === "max" ? "9000" : o.quality; // 9000(p) - max quality
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue