0
0
Fork 0
mirror of https://github.com/VueTubeApp/VueTube synced 2024-11-22 19:25:16 +00:00

feat(api)! : completely revamped how Innertube recieves video information.

This commit is contained in:
Alex 2022-03-20 19:05:43 +13:00
parent 22f999f9c3
commit 46ffe7a51d
4 changed files with 88 additions and 39 deletions

View file

@ -1,29 +1,27 @@
// Buttons and methods for testing and demonstration purposes only. Uncomment them to see how it works. Remove to actually implement a implementation
<template>
<div>
<!-- Video Loading Animation -->
<center v-if="recommends.length == 0">
<v-skeleton-loader type="card-avatar, article, actions" />
<v-skeleton-loader type="card-avatar, article, actions" />
</center>
<v-list-item v-for="(video, index) in recommends[0]" :key="index">
<v-card class="entry" :to="`/watch?v=${video.id}`">
<v-card-text>
<div style="position: relative">
<v-img :src="video.thumbnail" />
<div v-text="video.metadata.overlay[0]" class="videoRuntimeFloat" style="color: #fff" />
<div
v-text="video.metadata.overlay[0]"
class="videoRuntimeFloat"
style="color: #fff"
/>
</div>
<div v-text="video.title" style="margin-top: 0.5em" />
<div v-text="parseBottom(video)" />
</v-card-text>
</v-card>
</v-list-item>
</div>
</template>

View file

@ -28,6 +28,7 @@ class Innertube {
this.key = data.INNERTUBE_API_KEY;
this.context = data.INNERTUBE_CONTEXT;
this.context.client = constants.INNERTUBE_CLIENT(this.context.client)
this.header = constants.INNERTUBE_HEADER(this.context.client)
}
} catch (err) {
@ -89,13 +90,32 @@ class Innertube {
}
}
async getVidInfoAsync(id) {
let data = { context: this.context, videoId: id }
async getVidAsync(id) {
const response = await Http.post({
url: `${constants.URLS.YT_BASE_API}/player?key=${this.key}`,
data: data,
headers: constants.INNERTUBE_HEADER(this.context)
// const url = `${constants.URLS.YT_MOBILE}/watch?v=${id}&t=8s&pbj=1`
// console.log(url)
// const response = await Http.get({
// url: url,
// params: {},
// headers: Object.assign({"referer": url}, this.header)
// }).catch((error) => error)
const response = await Http.get({
url: `https://m.youtube.com/watch?v=${id}&t=8s&pbj=1`,
params: {},
headers: {
accept: '*/*',
'user-agent': 'Mozilla/5.0 (Linux; Android 10; WP7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.101 Mobile Safari/537.36',
'content-type': 'application/json',
'accept-language': 'en-US,en;q=0.9',
'x-goog-authuser': 0,
'x-goog-visitor-id': 'CgtsaVdQdGhfbVNOMCiC0taRBg%3D%3D',
'x-youtube-client-name': 2,
'x-youtube-client-version': '2.20220318.00.00',
'x-youtube-chrome-connected': 'source=Chrome,mode=0,enable_account_consistency=true,supervised=false,consistency_enabled_by_default=false',
'x-origin': 'https://m.youtube.com',
origin: 'https://m.youtube.com',
referer: `https://m.youtube.com/watch?v=${id}`
}
}).catch((error) => error);
if (response instanceof Error) return { success: false, status_code: response.response.status, message: response.message };
@ -114,6 +134,52 @@ class Innertube {
return rec;
}
async VidInfoAsync(id) {
let response = await this.getVidAsync(id)
response = response.data
if (response[2].playerResponse?.playabilityStatus?.status == ("ERROR" || undefined))
throw new Error(`Could not get information for video: ${response[2].playerResponse?.playabilityStatus?.status} - ${response[2].playerResponse?.playabilityStatus?.reason}`)
const details = response[2].playerResponse?.videoDetails
const microformat = response[2].playerResponse?.microformat?.playerMicroformatRenderer
const renderedPanels = response[3].response?.engagementPanels
const columnUI = response[3].response?.contents.singleColumnWatchNextResults?.results?.results
console.log((columnUI.contents).length)
return {
id: details.videoId,
title: details.title || microformat.title?.runs[0].text,
isLive: details.isLiveContent || microformat.liveBroadcastDetails?.isLiveNow || false,
channelName: details.author || microformat.ownerChannelName,
channelUrl: microformat.ownerProfileUrl,
availableResolutions: response[2].playerResponse?.streamingData?.formats,
availableResolutionsAdaptive: response[2].playerResponse?.streamingData?.adaptiveFormats,
metadata: {
description: microformat.description?.runs[0].text,
descriptionShort: details.shortDescription,
thumbnails: details.thumbnails?.thumbnails || microformat.thumbnails?.thumbnails,
isFamilySafe: microformat.isFamilySafe,
availableCountries: microformat.availableCountries,
liveBroadcastDetails: microformat.liveBroadcastDetails,
uploadDate: microformat.uploadDate,
publishDate: microformat.publishDate,
isPrivate: details.isPrivate,
viewCount: details.viewCount || microformat.viewCount,
lengthSeconds: details.lengthSeconds || microformat.lengthSeconds,
likes: parseInt(columnUI?.contents[1]
.slimVideoMetadataSectionRenderer?.contents[1].slimVideoActionBarRenderer?.buttons[0]
.slimMetadataToggleButtonRenderer?.button?.toggleButtonRenderer?.defaultText?.accessibility?.accessibilityData?.label?.replace(/\D/g, '')) // Yes. I know.
},
rendered_data: {
description: renderedPanels[0].engagementPanelSectionListRenderer?.content.structuredDescriptionContentRenderer?.items[1].expandableVideoDescriptionBodyRenderer?.descriptionBodyText.runs,
recommendations: columnUI?.contents[(columnUI.contents).length -1].itemSectionRenderer?.contents,
recommendContinuation: columnUI?.continuations[0].reloadContinuationData?.continuation
}
}
}
}

View file

@ -185,27 +185,7 @@ const recommendationModule = {
async getVid(id) {
// temporary test
const html = await Http.get({
url: "https://m.youtube.com/watch?v=U-9M-BjFYMc&t=8s&pbj=1",
params: {},
headers: {
accept: '*/*',
'user-agent': 'Mozilla/5.0 (Linux; Android 10; WP7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.101 Mobile Safari/537.36',
'content-type': 'application/json',
'accept-language': 'en-US,en;q=0.9',
'x-goog-authuser': 0,
'x-goog-visitor-id': 'CgtsaVdQdGhfbVNOMCiC0taRBg%3D%3D',
'x-youtube-client-name': 2,
'x-youtube-client-version': '2.20220318.00.00',
'x-youtube-chrome-connected': 'source=Chrome,mode=0,enable_account_consistency=true,supervised=false,consistency_enabled_by_default=false',
'x-origin': 'https://m.youtube.com',
origin: 'https://m.youtube.com',
referer: 'https://m.youtube.com/watch?v=U-9M-BjFYMc'
}
}).catch((error) => error);
console.log(html.data)
return InnertubeAPI.getVidInfoAsync(id);
console.log(await InnertubeAPI.VidInfoAsync(id))
},
// It just works™

View file

@ -2,6 +2,7 @@
const url = {
YT_URL: 'https://www.youtube.com',
YT_MOBILE: "https://m.youtube.com",
YT_MUSIC_URL: 'https://music.youtube.com',
YT_BASE_API: 'https://www.youtube.com/youtubei/v1',
YT_SUGGESTIONS: "https://suggestqueries.google.com/complete",
@ -27,13 +28,17 @@ module.exports = {
INNERTUBE_HEADER: (info) => {
let headers = {
'accept': '*/*',
'user-agent': info.client.userAgent,
accept: '*/*',
'user-agent': info.userAgent,
'content-type': 'application/json',
'accept-language': `${info.hl}-${info.gl},${info.hl};q=0.9`,
'x-goog-authuser': 0,
'x-youtube-client-name': 2,
'x-youtube-client-version': info.client.clientVersion,
'x-youtube-chrome-connected': 'source=Chrome,mode=0,enable_account_consistency=true,supervised=false,consistency_enabled_by_default=false',
'x-goog-visitor-id': info.visitorData,
'x-youtube-client-name': ytApiVal.CLIENTNAME,
'x-youtube-client-version': ytApiVal.VERSION,
'x-origin': info.originalUrl,
origin: info.originalUrl,
// referer: 'https://m.youtube.com/watch?v=U-9M-BjFYMc'
};
return headers
},