mirror of
https://github.com/VueTubeApp/VueTube
synced 2025-01-05 15:11:13 +00:00
feat: channel wrapper
This commit is contained in:
parent
c9147c93f6
commit
aff6cb6847
3 changed files with 56 additions and 5 deletions
|
@ -33,6 +33,7 @@ module.exports = {
|
|||
recommendations: "Recommendations",
|
||||
init: "Initialize",
|
||||
innertube: "Innertube",
|
||||
channel: "Channel",
|
||||
},
|
||||
|
||||
INNERTUBE_HEADER: (info) => {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue