youtube: introduce YOUTUBE_PLAYER_ID envvar

This commit is contained in:
jj
2026-03-07 14:20:38 +00:00
parent e1ce1dbf69
commit 2283901dc2
3 changed files with 17 additions and 0 deletions

View File

@@ -121,6 +121,7 @@ export const loadEnvs = (env = process.env) => {
ytSessionReloadInterval: 300,
ytSessionInnertubeClient: env.YOUTUBE_SESSION_INNERTUBE_CLIENT,
ytAllowBetterAudio: env.YOUTUBE_ALLOW_BETTER_AUDIO !== "0",
ytPlayerIds: env.YOUTUBE_PLAYER_ID?.split(',')?.map(p => p.trim()),
// "never" | "session" | "always"
forceLocalProcessing: env.FORCE_LOCAL_PROCESSING ?? "never",

View File

@@ -77,12 +77,20 @@ const cloneInnertube = async (customFetch, useSession) => {
}
if (!innertube || shouldRefreshPlayer) {
let player_id;
if (env.ytPlayerIds) {
player_id = env.ytPlayerIds[
Math.floor(Math.random() * env.ytPlayerIds.length)
];
}
innertube = await Innertube.create({
fetch: customFetch,
retrieve_player,
cookie,
po_token: useSession ? sessionTokens?.potoken : undefined,
visitor_data: useSession ? sessionTokens?.visitor_data : undefined,
player_id,
});
lastRefreshedAt = +new Date();
}

View File

@@ -68,6 +68,7 @@ this document is not final and will expand over time. feel free to improve it!
| YOUTUBE_SESSION_INNERTUBE_CLIENT | `WEB_EMBEDDED` |
| YOUTUBE_ALLOW_BETTER_AUDIO | `1` |
| ENABLE_DEPRECATED_YOUTUBE_HLS | `key` |
| YOUTUBE_PLAYER_ID | `abcdefff` |
[*view details*](#service-specific)
@@ -271,6 +272,13 @@ innertube client that's compatible with botguard's (web) `poToken` and `visitor_
the value is a string.
### YOUTUBE_PLAYER_ID
a comma-separated-list of player IDs to use for youtube fetching.
if defined, cobalt chooses one of them at each client initialization, otherwise
defaults to the current latest player ID.
the value is a string.
### YOUTUBE_ALLOW_BETTER_AUDIO
when set to `1`, cobalt will try to use higher quality audio if user requests it via `youtubeBetterAudio`. will negatively impact the rate limit of a secondary youtube client with a session.