mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-23 03:37:53 +01:00
Update src/libpoketube/init/pages-channel-and-download.js
This commit is contained in:
parent
e01174182c
commit
7767c69ad1
1 changed files with 49 additions and 57 deletions
|
@ -231,7 +231,6 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
: "";
|
: "";
|
||||||
const sort_by = req.query.sort_by || "newest";
|
const sort_by = req.query.sort_by || "newest";
|
||||||
|
|
||||||
|
|
||||||
const getChannelData = async (url) => {
|
const getChannelData = async (url) => {
|
||||||
try {
|
try {
|
||||||
return await fetch(url)
|
return await fetch(url)
|
||||||
|
@ -243,40 +242,35 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const apiUrl = config.invapi + "/channels/";
|
const apiUrl = config.invapi + "/channels/";
|
||||||
|
const channelUrl = `${apiUrl}${atob(
|
||||||
|
ChannelTabs.videos
|
||||||
|
)}/${ID}/?sort_by=${sort_by}${continuation}`;
|
||||||
|
const shortsUrl = `${apiUrl}${ID}/${atob(
|
||||||
|
ChannelTabs.shorts
|
||||||
|
)}?sort_by=${sort_by}${continuations}`;
|
||||||
|
const streamUrl = `${apiUrl}${ID}/${atob(
|
||||||
|
ChannelTabs.streams
|
||||||
|
)}?sort_by=${sort_by}${continuationl}`;
|
||||||
|
const communityUrl = `${apiUrl}${atob(
|
||||||
|
ChannelTabs.community
|
||||||
|
)}/${ID}/?hl=en-US`;
|
||||||
|
const PlaylistUrl = `${apiUrl}${atob(
|
||||||
|
ChannelTabs.playlist
|
||||||
|
)}/${ID}/?hl=en-US`;
|
||||||
|
|
||||||
const channelINVUrl = `${apiUrl}${ID}/`;
|
const channelINVUrl = `${apiUrl}${ID}/`;
|
||||||
const checkPronoun = async (id) => (await (await fetch('https://raw.githubusercontent.com/ashley0143/poke/main/pronounsdb.json')).json())[id] || `no pronouns set`;
|
|
||||||
const pronoun = await checkPronoun(ID);
|
|
||||||
|
|
||||||
const channelINVData = await getChannelData(channelINVUrl);
|
const pronoun = "no pronouns :c"
|
||||||
const cinv = await getChannelData(channelINVUrl);
|
|
||||||
|
|
||||||
if (!channelINVData) {
|
var [tj, shorts, playlist, stream, c, cinv] = await Promise.all([
|
||||||
throw new Error('Failed to fetch channel INV data');
|
getChannelData(channelUrl),
|
||||||
}
|
getChannelData(shortsUrl),
|
||||||
|
getChannelData(PlaylistUrl),
|
||||||
const ChannelTabs = channelINVData.tabs;
|
getChannelData(streamUrl),
|
||||||
|
getChannelData(communityUrl),
|
||||||
const channelUrl = ChannelTabs.videos ? `${apiUrl}${atob(ChannelTabs.videos)}/${ID}/?sort_by=${sort_by}${continuation}` : null;
|
getChannelData(channelINVUrl),
|
||||||
const shortsUrl = ChannelTabs.shorts ? `${apiUrl}${ID}/${atob(ChannelTabs.shorts)}?sort_by=${sort_by}${continuations}` : null;
|
|
||||||
const streamUrl = ChannelTabs.streams ? `${apiUrl}${ID}/${atob(ChannelTabs.streams)}?sort_by=${sort_by}${continuationl}` : null;
|
|
||||||
const communityUrl = ChannelTabs.community ? `${apiUrl}${atob(ChannelTabs.community)}/${ID}/?hl=en-US` : null;
|
|
||||||
const PlaylistUrl = ChannelTabs.playlist ? `${apiUrl}${atob(ChannelTabs.playlist)}/${ID}/?hl=en-US` : null;
|
|
||||||
|
|
||||||
|
|
||||||
const fetchData = async (url) => {
|
|
||||||
return url ? getChannelData(url) : "";
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var [tj, shorts, playlist, stream, c] = await Promise.all([
|
|
||||||
fetchData(channelUrl),
|
|
||||||
fetchData(shortsUrl),
|
|
||||||
fetchData(PlaylistUrl),
|
|
||||||
fetchData(streamUrl),
|
|
||||||
fetchData(communityUrl)
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
function getThumbnailUrl(video) {
|
function getThumbnailUrl(video) {
|
||||||
const maxresDefaultThumbnail = video.videoThumbnails.find(
|
const maxresDefaultThumbnail = video.videoThumbnails.find(
|
||||||
(thumbnail) => thumbnail.quality === "maxresdefault"
|
(thumbnail) => thumbnail.quality === "maxresdefault"
|
||||||
|
@ -317,23 +311,21 @@ var [tj, shorts, playlist, stream, c] = await Promise.all([
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (tj) {
|
|
||||||
if (continuation) {
|
if (continuation) {
|
||||||
const currentAuthorId = String(cinv.authorId).trim();
|
const currentAuthorId = String(cinv.authorId).trim();
|
||||||
const firstVideoAuthorId = String(tj.videos[0].authorId).trim();
|
const firstVideoAuthorId = String(tj.videos[0].authorId).trim();
|
||||||
|
|
||||||
if (currentAuthorId.localeCompare(firstVideoAuthorId) !== 0) {
|
if (currentAuthorId.localeCompare(firstVideoAuthorId) !== 0) {
|
||||||
res.status(400).send("Continuation does not match the channel :c");
|
res.status(400).send("Continuation does not match the channel :c");
|
||||||
return; // Exit the function after sending the response
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var ChannelFirstVideoObject = await fetch(
|
const ChannelFirstVideoObject = await fetch(
|
||||||
`${config.invapi}/videos/${tj.videos[0].videoId}`
|
`${config.invapi}/videos/${tj.videos[0].videoId}`
|
||||||
)
|
)
|
||||||
.then((res) => res.text())
|
.then((res) => res.text())
|
||||||
.then((txt) => getJson(txt));
|
.then((txt) => getJson(txt));
|
||||||
}
|
|
||||||
|
|
||||||
renderTemplate(res, req, "channel.ejs", {
|
renderTemplate(res, req, "channel.ejs", {
|
||||||
ID,
|
ID,
|
||||||
|
|
Loading…
Reference in a new issue