Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

youtube: don't block api startup waiting for innertube to activate #532

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/modules/processing/services/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { env } from '../../config.js';
import { cleanString } from '../../sub/utils.js';
import { fetch } from 'undici'

const ytBase = await Innertube.create();
const ytBase = Innertube.create().catch(e => e);

const codecMatch = {
h264: {
Expand All @@ -23,24 +23,29 @@ const codecMatch = {
}
}

const cloneInnertube = (customFetch) => {
const cloneInnertube = async (customFetch) => {
const innertube = await ytBase;
if (innertube instanceof Error) {
throw innertube;
}

const session = new Session(
ytBase.session.context,
ytBase.session.key,
ytBase.session.api_version,
ytBase.session.account_index,
ytBase.session.player,
innertube.session.context,
innertube.session.key,
innertube.session.api_version,
innertube.session.account_index,
innertube.session.player,
undefined,
customFetch ?? ytBase.session.http.fetch,
ytBase.session.cache
customFetch ?? innertube.session.http.fetch,
innertube.session.cache
);

const yt = new Innertube(session);
return yt;
}

export default async function(o) {
const yt = cloneInnertube(
const yt = await cloneInnertube(
(input, init) => fetch(input, { ...init, dispatcher: o.dispatcher })
);

Expand Down