mirror of
https://github.com/wukko/cobalt.git
synced 2025-03-25 18:54:53 +01:00
api: remove code & docs related to youtube oauth
it hasn't been functional for a while, unfortunately
This commit is contained in:
parent
d1b5983e49
commit
073b169a93
6 changed files with 1 additions and 124 deletions
|
@ -11,7 +11,6 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node src/cobalt",
|
"start": "node src/cobalt",
|
||||||
"test": "node src/util/test",
|
"test": "node src/util/test",
|
||||||
"token:youtube": "node src/util/generate-youtube-tokens",
|
|
||||||
"token:jwt": "node src/util/generate-jwt-secret"
|
"token:jwt": "node src/util/generate-jwt-secret"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -13,7 +13,6 @@ const VALID_SERVICES = new Set([
|
||||||
'reddit',
|
'reddit',
|
||||||
'twitter',
|
'twitter',
|
||||||
'youtube',
|
'youtube',
|
||||||
'youtube_oauth'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const invalidCookies = {};
|
const invalidCookies = {};
|
||||||
|
|
|
@ -4,8 +4,8 @@ import { fetch } from "undici";
|
||||||
import { Innertube, Session } from "youtubei.js";
|
import { Innertube, Session } from "youtubei.js";
|
||||||
|
|
||||||
import { env } from "../../config.js";
|
import { env } from "../../config.js";
|
||||||
|
import { getCookie } from "../cookie/manager.js";
|
||||||
import { getYouTubeSession } from "../helpers/youtube-session.js";
|
import { getYouTubeSession } from "../helpers/youtube-session.js";
|
||||||
import { getCookie, updateCookieValues } from "../cookie/manager.js";
|
|
||||||
|
|
||||||
const PLAYER_REFRESH_PERIOD = 1000 * 60 * 15; // ms
|
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 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 cloneInnertube = async (customFetch) => {
|
||||||
const shouldRefreshPlayer = lastRefreshedAt + PLAYER_REFRESH_PERIOD < new Date();
|
const shouldRefreshPlayer = lastRefreshedAt + PLAYER_REFRESH_PERIOD < new Date();
|
||||||
|
|
||||||
|
@ -102,32 +81,6 @@ const cloneInnertube = async (customFetch) => {
|
||||||
innertube.session.cache
|
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);
|
const yt = new Innertube(session);
|
||||||
return yt;
|
return yt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
|
|
@ -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.
|
|
|
@ -10,8 +10,5 @@
|
||||||
],
|
],
|
||||||
"twitter": [
|
"twitter": [
|
||||||
"auth_token=<replace_this>; ct0=<replace_this>"
|
"auth_token=<replace_this>; ct0=<replace_this>"
|
||||||
],
|
|
||||||
"youtube_oauth": [
|
|
||||||
"<output from running `pnpm run token:youtube` in `api` folder goes here>"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue