mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-27 10:10:15 +00:00
api/youtube: use poToken, visitorData, and web client with cookies
and also decipher media whenever needed, but only if cookies are used
This commit is contained in:
parent
9da3ba60a9
commit
c6d0e0bdd5
|
@ -66,12 +66,18 @@ const transformSessionData = (cookie) => {
|
|||
|
||||
const cloneInnertube = async (customFetch) => {
|
||||
const shouldRefreshPlayer = lastRefreshedAt + PLAYER_REFRESH_PERIOD < new Date();
|
||||
const cookie = getCookie('youtube')?.toString();
|
||||
|
||||
const rawCookie = getCookie('youtube');
|
||||
const cookieValues = rawCookie?.values();
|
||||
const cookie = rawCookie?.toString();
|
||||
|
||||
if (!innertube || shouldRefreshPlayer) {
|
||||
innertube = await Innertube.create({
|
||||
fetch: customFetch,
|
||||
retrieve_player: false,
|
||||
cookie
|
||||
retrieve_player: !!cookie,
|
||||
cookie,
|
||||
po_token: cookieValues?.po_token,
|
||||
visitor_data: cookieValues?.visitor_data,
|
||||
});
|
||||
lastRefreshedAt = +new Date();
|
||||
}
|
||||
|
@ -134,6 +140,8 @@ export default async function(o) {
|
|||
} else throw e;
|
||||
}
|
||||
|
||||
const cookie = getCookie('youtube')?.toString();
|
||||
|
||||
let useHLS = o.youtubeHLS;
|
||||
|
||||
// HLS playlists don't contain the av1 video format, at least with the iOS client
|
||||
|
@ -141,9 +149,20 @@ export default async function(o) {
|
|||
useHLS = false;
|
||||
}
|
||||
|
||||
let innertubeClient = "ANDROID";
|
||||
|
||||
if (cookie) {
|
||||
useHLS = false;
|
||||
innertubeClient = "WEB";
|
||||
}
|
||||
|
||||
if (useHLS) {
|
||||
innertubeClient = "IOS";
|
||||
}
|
||||
|
||||
let info;
|
||||
try {
|
||||
info = await yt.getBasicInfo(o.id, useHLS ? 'IOS' : 'ANDROID');
|
||||
info = await yt.getBasicInfo(o.id, innertubeClient);
|
||||
} catch (e) {
|
||||
if (e?.info) {
|
||||
const errorInfo = JSON.parse(e?.info);
|
||||
|
@ -438,6 +457,10 @@ export default async function(o) {
|
|||
urls = audio.uri;
|
||||
}
|
||||
|
||||
if (innertubeClient === "WEB" && innertube) {
|
||||
urls = audio.decipher(innertube.session.player);
|
||||
}
|
||||
|
||||
return {
|
||||
type: "audio",
|
||||
isAudioOnly: true,
|
||||
|
@ -464,11 +487,17 @@ export default async function(o) {
|
|||
width: video.width,
|
||||
height: video.height,
|
||||
});
|
||||
|
||||
filenameAttributes.resolution = `${video.width}x${video.height}`;
|
||||
filenameAttributes.extension = codecList[codec].container;
|
||||
|
||||
video = video.url;
|
||||
audio = audio.url;
|
||||
|
||||
if (innertubeClient === "WEB" && innertube) {
|
||||
video = video.decipher(innertube.session.player);
|
||||
audio = audio.decipher(innertube.session.player);
|
||||
}
|
||||
}
|
||||
|
||||
filenameAttributes.qualityLabel = `${resolution}p`;
|
||||
|
|
Loading…
Reference in a new issue