diff --git a/NUXT/plugins/constants.js b/NUXT/plugins/constants.js index 74c188f..3ad81f0 100644 --- a/NUXT/plugins/constants.js +++ b/NUXT/plugins/constants.js @@ -33,6 +33,7 @@ module.exports = { recommendations: "Recommendations", init: "Initialize", innertube: "Innertube", + channel: "Channel", }, INNERTUBE_HEADER: (info) => { diff --git a/NUXT/plugins/innertube.js b/NUXT/plugins/innertube.js index 723e9cf..94aa176 100644 --- a/NUXT/plugins/innertube.js +++ b/NUXT/plugins/innertube.js @@ -76,18 +76,23 @@ class Innertube { //--- API Calls ---// - async browseAsync(action_type) { + async browseAsync(action_type, args) { let data = { context: this.context }; switch (action_type) { case "recommendations": - data.browseId = "FEwhat_to_watch"; + args.browseId = "FEwhat_to_watch"; break; case "playlist": - data.browseId = args.browse_id; - break; + case "channel": + if (args && args.browseId) { + break; + } else { + throw new ReferenceError("No browseId provided"); + } default: } + data.browseId = { ...data, args }; console.log(data); @@ -217,6 +222,28 @@ class Innertube { }; } + async getEndPoint(url) { + let data = { context: this.context, url: url }; + const response = await Http.post({ + url: `${constants.URLS.YT_BASE_API}/navigation/resolve_url?key=${this.key}`, + data: data, + headers: { "Content-Type": "application/json" }, + }).catch((error) => error); + + if (response instanceof Error) + return { + success: false, + status_code: response.status, + message: response.message, + }; + + return { + success: true, + status_code: response.status, + data: response.data, + }; + } + // WARNING: This is tracking the user's activity, but is required for recommendations to properly work async apiStats(params, url) { console.log(params); @@ -252,10 +279,24 @@ class Innertube { // Simple Wrappers async getRecommendationsAsync() { const rec = await this.browseAsync("recommendations"); - console.log(rec.data); return rec; } + async getChannelAsync(url) { + const channelEndpoint = await this.getEndPoint(url); + if ( + channelEndpoint.success && + channelEndpoint.data.endpoint?.browseEndpoint + ) { + return await this.browseAsync( + "channel", + channelEndpoint.data.endpoint?.browseEndpoint + ); + } else { + throw new ReferenceError("Cannot find channel"); + } + } + async VidInfoAsync(id) { let response = await this.getVidAsync(id); diff --git a/NUXT/plugins/youtube.js b/NUXT/plugins/youtube.js index 0b784e2..87e1b3f 100644 --- a/NUXT/plugins/youtube.js +++ b/NUXT/plugins/youtube.js @@ -109,6 +109,15 @@ const innertubeModule = { else return `https://img.youtube.com/vi/${id}/mqdefault.jpg`; }, + async getChannel(url) { + try { + const response = await InnertubeAPI.getChannelAsync(url); + return response.data; + } catch (error) { + logger(constants.LOGGER_NAMES.channel, error, true); + } + }, + // It just works™ // Front page recommendation async recommend() {