Skip to content

best way to save what you love

api: remove code & docs related to youtube oauth

wukko073b169a939b
diff --git a/api/package.json b/api/package.json
index 4f2b21dc..ed78546c 100644
--- a/api/package.json
+++ b/api/package.json
@@ -11,7 +11,6 @@
"scripts": {
"start": "node src/cobalt",
"test": "node src/util/test",
- "token:youtube": "node src/util/generate-youtube-tokens",
"token:jwt": "node src/util/generate-jwt-secret"
},
"repository": {
diff --git a/api/src/processing/cookie/manager.js b/api/src/processing/cookie/manager.js
index 25f41c2c..9e23374b 100644
--- a/api/src/processing/cookie/manager.js
+++ b/api/src/processing/cookie/manager.js
@@ -13,7 +13,6 @@ const VALID_SERVICES = new Set([
'reddit',
'twitter',
'youtube',
- 'youtube_oauth'
]);
const invalidCookies = {};
diff --git a/api/src/processing/services/youtube.js b/api/src/processing/services/youtube.js
index ca46d22f..49de7758 100644
--- a/api/src/processing/services/youtube.js
+++ b/api/src/processing/services/youtube.js
@@ -4,8 +4,8 @@ import { fetch } from "undici";
import { Innertube, Session } from "youtubei.js";
import { env } from "../../config.js";
+import { getCookie } from "../cookie/manager.js";
import { getYouTubeSession } from "../helpers/youtube-session.js";
-import { getCookie, updateCookieValues } from "../cookie/manager.js";
const PLAYER_REFRESH_PERIOD = 1000 * 60 * 15; // ms
@@ -46,27 +46,6 @@ const clientsWithNoCipher = ['IOS', 'ANDROID', 'YTSTUDIO_ANDROID', 'YTMUSIC_ANDR
const videoQualities = [144, 240, 360, 480, 720, 1080, 1440, 2160, 4320];
-const transformSessionData = (cookie) => {
- if (!cookie)
- return;
-
- const values = { ...cookie.values() };
- const REQUIRED_VALUES = ['access_token', 'refresh_token'];
-
- if (REQUIRED_VALUES.some(x => typeof values[x] !== 'string')) {
- return;
- }
-
- if (values.expires) {
- values.expiry_date = values.expires;
- delete values.expires;
- } else if (!values.expiry_date) {
- return;
- }
-
- return values;
-}
-
const cloneInnertube = async (customFetch) => {
const shouldRefreshPlayer = lastRefreshedAt + PLAYER_REFRESH_PERIOD < new Date();
@@ -102,32 +81,6 @@ const cloneInnertube = async (customFetch) => {
innertube.session.cache
);
- const oauthCookie = getCookie('youtube_oauth');
- const oauthData = transformSessionData(oauthCookie);
-
- if (!session.logged_in && oauthData) {
- await session.oauth.init(oauthData);
- session.logged_in = true;
- }
-
- if (session.logged_in && oauthData) {
- if (session.oauth.shouldRefreshToken()) {
- await session.oauth.refreshAccessToken();
- }
-
- const cookieValues = oauthCookie.values();
- const oldExpiry = new Date(cookieValues.expiry_date);
- const newExpiry = new Date(session.oauth.oauth2_tokens.expiry_date);
-
- if (oldExpiry.getTime() !== newExpiry.getTime()) {
- updateCookieValues(oauthCookie, {
- ...session.oauth.client_id,
- ...session.oauth.oauth2_tokens,
- expiry_date: newExpiry.toISOString()
- });
- }
- }
-
const yt = new Innertube(session);
return yt;
}
diff --git a/api/src/util/generate-youtube-tokens.js b/api/src/util/generate-youtube-tokens.js
deleted file mode 100644
index 5585705a..00000000
--- a/api/src/util/generate-youtube-tokens.js
+++ /dev/null
@@ -1,38 +0,0 @@
-import { Innertube } from 'youtubei.js';
-import { Red } from '../misc/console-text.js'
-
-const bail = (...msg) => {
- console.error(...msg);
- throw new Error(msg);
-};
-
-const tube = await Innertube.create();
-
-tube.session.once(
- 'auth-pending',
- ({ verification_url, user_code }) => {
- console.log(`${Red('[!]')} The token generated by this script is sensitive and you should not share it with anyone!`);
- console.log(` By using this token, you are risking your Google account getting terminated.`);
- console.log(` You should ${Red('NOT')} use your personal account!`);
- console.log();
- console.log(`Open ${verification_url} in a browser and enter ${user_code} when asked for the code.`);
- }
-);
-
-tube.session.once('auth-error', (err) => bail('An error occurred:', err));
-tube.session.once('auth', ({ credentials }) => {
- if (!credentials.access_token) {
- bail('something went wrong');
- }
-
- console.log(
- 'add this cookie to the youtube_oauth array in your cookies file:',
- JSON.stringify(
- Object.entries(credentials)
- .map(([k, v]) => `${k}=${v instanceof Date ? v.toISOString() : v}`)
- .join('; ')
- )
- );
-});
-
-await tube.session.signIn();
\ No newline at end of file
diff --git a/docs/configure-for-youtube.md b/docs/configure-for-youtube.md
deleted file mode 100644
index fe286d86..00000000
--- a/docs/configure-for-youtube.md
+++ /dev/null
@@ -1,33 +0,0 @@
-# how to configure a cobalt instance for youtube
-if you get various errors when attempting to download videos that are:
-publicly available, not region locked, and not age-restricted;
-then your instance's ip address may have bad reputation.
-
-in this case you have to use disposable google accounts.
-there's no other known workaround as of time of writing this document.
-
-> [!CAUTION]
-> **NEVER** use your personal google account for downloading videos via any means.
-> you can use any google accounts that you're willing to sacrifice,
-> but be prepared to have them **permanently suspended**.
->
-> we recommend that you use accounts that don't link back to your personal google account or identity, just in case.
->
-> use incognito mode when signing in.
-> we also recommend using vpn/proxy services (such as [mullvad](https://mullvad.net/)).
-
-1. if you haven't done it already, clone the cobalt repo, go to the cloned directory, and run `pnpm install`
-
-2. run `pnpm -C api token:youtube`
-
-3. follow instructions, use incognito mode in your browser when signing in.
-i cannot stress this enough, but again, **DO NOT USE YOUR PERSONAL GOOGLE ACCOUNT**.
-
-4. once you have the oauth token, add it to `youtube_oauth` in your cookies file.
-you can see an [example here](/docs/examples/cookies.example.json).
-you can have several account tokens in this file, if you like.
-
-5. all done! enjoy freedom.
-
-### liability
-you're responsible for any damage done to any of your google accounts or any other damages. you do this by yourself and at your own risk.
diff --git a/docs/examples/cookies.example.json b/docs/examples/cookies.example.json
index 7996adeb..73f3378d 100644
--- a/docs/examples/cookies.example.json
+++ b/docs/examples/cookies.example.json
@@ -10,8 +10,5 @@
],
"twitter": [
"auth_token=<replace_this>; ct0=<replace_this>"
- ],
- "youtube_oauth": [
- "<output from running `pnpm run token:youtube` in `api` folder goes here>"
]
}