From e10fad3d4e447fee3fe2ad924885016de80a4d76 Mon Sep 17 00:00:00 2001 From: wukko Date: Fri, 14 Mar 2025 08:53:26 +0600 Subject: [PATCH 1/4] api/config: add `CUSTOM_INNERTUBE_CLIENT` env --- api/src/config.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/src/config.js b/api/src/config.js index 191e8441..bff1eda3 100644 --- a/api/src/config.js +++ b/api/src/config.js @@ -1,3 +1,4 @@ +import { Constants } from "youtubei.js"; import { getVersion } from "@imput/version-info"; import { services } from "./processing/service-config.js"; import { supportsReusePort } from "./misc/cluster.js"; @@ -52,6 +53,7 @@ const env = { keyReloadInterval: 900, enabledServices, + customInnertubeClient: process.env.CUSTOM_INNERTUBE_CLIENT, } const genericUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"; @@ -74,6 +76,12 @@ if (env.instanceCount > 1 && !env.redisURL) { throw new Error('SO_REUSEPORT is not supported'); } +if (env.customInnertubeClient && !Constants.SUPPORTED_CLIENTS.includes(env.customInnertubeClient)) { + console.error("CUSTOM_INNERTUBE_CLIENT is invalid. Provided client is not supported."); + console.error(`Supported clients are: ${Constants.SUPPORTED_CLIENTS.join(', ')}\n`); + throw new Error("Invalid CUSTOM_INNERTUBE_CLIENT"); +} + export { env, genericUserAgent, From d2d098dbfb37ad2745c3fef6958fae6b36c3b94b Mon Sep 17 00:00:00 2001 From: wukko Date: Fri, 14 Mar 2025 08:54:42 +0600 Subject: [PATCH 2/4] api/youtube: use custom innertube client env & decipher for more clients --- api/src/processing/services/youtube.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/src/processing/services/youtube.js b/api/src/processing/services/youtube.js index b12d2cee..fc712e24 100644 --- a/api/src/processing/services/youtube.js +++ b/api/src/processing/services/youtube.js @@ -41,6 +41,8 @@ const hlsCodecList = { } } +const clientsWithNoCipher = ['IOS', 'ANDROID', 'YTSTUDIO_ANDROID', 'YTMUSIC_ANDROID']; + const videoQualities = [144, 240, 360, 480, 720, 1080, 1440, 2160, 4320]; const transformSessionData = (cookie) => { @@ -149,7 +151,7 @@ export default async function (o) { useHLS = false; } - let innertubeClient = o.innertubeClient || "ANDROID"; + let innertubeClient = o.innertubeClient || env.customInnertubeClient || "ANDROID"; if (cookie) { useHLS = false; @@ -478,7 +480,7 @@ export default async function (o) { urls = audio.uri; } - if (innertubeClient === "WEB" && innertube) { + if (!clientsWithNoCipher.includes(innertubeClient) && innertube) { urls = audio.decipher(innertube.session.player); } @@ -513,7 +515,7 @@ export default async function (o) { filenameAttributes.resolution = `${video.width}x${video.height}`; filenameAttributes.extension = codecList[codec].container; - if (innertubeClient === "WEB" && innertube) { + if (!clientsWithNoCipher.includes(innertubeClient) && innertube) { video = video.decipher(innertube.session.player); audio = audio.decipher(innertube.session.player); } else { From f103bcfaa35384f247649fa6f4bb86ee07bd60d6 Mon Sep 17 00:00:00 2001 From: wukko Date: Fri, 14 Mar 2025 09:05:58 +0600 Subject: [PATCH 3/4] docs/run-an-instance: add info about CUSTOM_INNERTUBE_CLIENT --- docs/run-an-instance.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/run-an-instance.md b/docs/run-an-instance.md index ea31cfc5..fe8316f5 100644 --- a/docs/run-an-instance.md +++ b/docs/run-an-instance.md @@ -80,6 +80,7 @@ sudo service nscd start | `API_REDIS_URL` | ➖ | `redis://localhost:6379` | when set, cobalt uses redis instead of internal memory for the tunnel cache. | | `API_INSTANCE_COUNT` | ➖ | `2` | supported only on Linux and node.js `>=23.1.0`. when configured, cobalt will spawn multiple sub-instances amongst which requests will be balanced. | | `DISABLED_SERVICES` | ➖ | `bilibili,youtube` | comma-separated list which disables certain services from being used. | +| `CUSTOM_INNERTUBE_CLIENT` | ➖ | `IOS` | innertube client that will be used instead of the default one. | \* the higher the nice value, the lower the priority. [read more here](https://en.wikipedia.org/wiki/Nice_(Unix)). From a940eb13fde4a9222e5eca0e66753cbb8fb92496 Mon Sep 17 00:00:00 2001 From: wukko Date: Fri, 14 Mar 2025 09:17:01 +0600 Subject: [PATCH 4/4] api/package: bump version to 10.7.10 it's kind of ridiculous at this point --- api/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/package.json b/api/package.json index 1e8f506a..4f2b21dc 100644 --- a/api/package.json +++ b/api/package.json @@ -1,7 +1,7 @@ { "name": "@imput/cobalt-api", "description": "save what you love", - "version": "10.7.9", + "version": "10.7.10", "author": "imput", "exports": "./src/cobalt.js", "type": "module",