Skip to content

Commit 5be23f9

Browse files
authored
Merge branch 'develop' into bug/tumblr
2 parents e66ff20 + 91989b8 commit 5be23f9

File tree

7 files changed

+68
-28
lines changed

7 files changed

+68
-28
lines changed

api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@imput/cobalt-api",
33
"description": "save what you love",
4-
"version": "11.4.3",
4+
"version": "11.5",
55
"author": "imput",
66
"exports": "./src/cobalt.js",
77
"type": "module",
@@ -39,7 +39,7 @@
3939
"set-cookie-parser": "2.6.0",
4040
"undici": "^6.21.3",
4141
"url-pattern": "1.0.3",
42-
"youtubei.js": "15.0.1",
42+
"youtubei.js": "16.0.0",
4343
"zod": "^3.23.8"
4444
},
4545
"optionalDependencies": {

api/src/processing/cookie/manager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const VALID_SERVICES = new Set([
1313
'reddit',
1414
'twitter',
1515
'youtube',
16+
'vimeo_bearer',
1617
]);
1718

1819
const invalidCookies = {};

api/src/processing/helpers/youtube-session.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ const defaultAgent = new Agent();
99
let session;
1010

1111
const validateSession = (sessionResponse) => {
12+
sessionResponse.visitor_data ??= sessionResponse.contentBinding;
13+
sessionResponse.potoken ??= sessionResponse.poToken;
14+
sessionResponse.updated ??= new Date().getTime();
15+
1216
if (!sessionResponse.potoken) {
1317
throw "no poToken in session response";
1418
}
@@ -33,11 +37,11 @@ const updateSession = (newSession) => {
3337

3438
const loadSession = async () => {
3539
const sessionServerUrl = new URL(env.ytSessionServer);
36-
sessionServerUrl.pathname = "/token";
40+
sessionServerUrl.pathname = "/get_pot";
3741

3842
const newSession = await fetch(
3943
sessionServerUrl,
40-
{ dispatcher: defaultAgent }
44+
{ method: 'POST', dispatcher: defaultAgent }
4145
).then(a => a.json());
4246

4347
validateSession(newSession);

api/src/processing/services/vimeo.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import HLS from "hls-parser";
22
import { env } from "../../config.js";
33
import { merge } from '../../misc/utils.js';
4+
import { getCookie } from "../cookie/manager.js";
45

56
const resolutionMatch = {
67
"3840": 2160,
@@ -25,7 +26,8 @@ const genericHeaders = {
2526
let bearer = '';
2627

2728
const getBearer = async (refresh = false) => {
28-
if (bearer && !refresh) return bearer;
29+
const cookie = getCookie('vimeo_bearer')?.values?.()?.access_token;
30+
if ((bearer || cookie) && !refresh) return bearer || cookie;
2931

3032
const oauthResponse = await fetch(
3133
'https://api.vimeo.com/oauth/authorize/client',

api/src/processing/services/youtube.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
import HLS from "hls-parser";
22

3-
import { fetch } from "undici";
4-
import { Innertube, Session } from "youtubei.js";
3+
import { fetch, Request } from "undici";
4+
import { Innertube, Platform, Session } from "youtubei.js";
55

66
import { env } from "../../config.js";
77
import { getCookie } from "../cookie/manager.js";
88
import { getYouTubeSession } from "../helpers/youtube-session.js";
99

10+
// https://github.com/LuanRT/YouTube.js/pull/1052
11+
Platform.shim.eval = async (data, env) => {
12+
const properties = [];
13+
14+
if (env.n) {
15+
properties.push(`n: exportedVars.nFunction("${env.n}")`)
16+
}
17+
18+
if (env.sig) {
19+
properties.push(`sig: exportedVars.sigFunction("${env.sig}")`)
20+
}
21+
22+
const code = `${data.output}\nreturn { ${properties.join(', ')} }`;
23+
24+
return new Function(code)();
25+
}
26+
1027
const PLAYER_REFRESH_PERIOD = 1000 * 60 * 15; // ms
1128

1229
let innertube, lastRefreshedAt;
@@ -206,10 +223,24 @@ export default async function (o) {
206223
let yt;
207224
try {
208225
yt = await cloneInnertube(
209-
(input, init) => fetch(input, {
210-
...init,
211-
dispatcher: o.dispatcher
212-
}),
226+
(input, init) => {
227+
const url = typeof input === 'string'
228+
? new URL(input)
229+
: input instanceof URL
230+
? input
231+
: new URL(input.url);
232+
233+
const request = new Request(
234+
url,
235+
input instanceof Platform.shim.Request
236+
? input : undefined
237+
);
238+
239+
return fetch(request, {
240+
...init,
241+
dispatcher: o.dispatcher
242+
});
243+
},
213244
useSession
214245
);
215246
} catch (e) {
@@ -529,7 +560,7 @@ export default async function (o) {
529560
}
530561

531562
if (!clientsWithNoCipher.includes(innertubeClient) && innertube) {
532-
urls = audio.decipher(innertube.session.player);
563+
urls = await audio.decipher(innertube.session.player);
533564
}
534565

535566
let cover = `https://i.ytimg.com/vi/${o.id}/maxresdefault.jpg`;
@@ -576,8 +607,8 @@ export default async function (o) {
576607
filenameAttributes.extension = o.container === "auto" ? codecList[codec].container : o.container;
577608

578609
if (!clientsWithNoCipher.includes(innertubeClient) && innertube) {
579-
video = video.decipher(innertube.session.player);
580-
audio = audio.decipher(innertube.session.player);
610+
video = await video.decipher(innertube.session.player);
611+
audio = await audio.decipher(innertube.session.player);
581612
} else {
582613
video = video.url;
583614
audio = audio.url;

docs/examples/cookies.example.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
],
1414
"youtube": [
1515
"cookie=<replace_this>; b=<replace_this>"
16+
],
17+
"vimeo": [
18+
"access_token=<replace_this>"
1619
]
1720
}

pnpm-lock.yaml

Lines changed: 13 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)