1
0
Fork 0
mirror of https://codeberg.org/ashley/poke.git synced 2024-11-17 04:14:39 -05:00

NEW BACK-END!!!

This commit is contained in:
Ashley 2022-10-09 12:34:39 +02:00
parent 678624509a
commit 344d2ae1ef

131
server.js
View file

@ -28,7 +28,10 @@ const lyricsFinder = require("./src/lyrics.js");
const fetch = require("node-fetch"); const fetch = require("node-fetch");
const { toJson } = require("xml2json"); const { toJson } = require("xml2json");
const fetcher = require("./src/fetcher.js"); const fetcher = require("./src/fetcher.js");
const api = require("./src/pt-api.js");
const templateDir = path.resolve(`${process.cwd()}${path.sep}html`); const templateDir = path.resolve(`${process.cwd()}${path.sep}html`);
var express = require("express"); var express = require("express");
@ -168,68 +171,36 @@ app.get("/watch", async function (req, res) {
var t = req.query.t; var t = req.query.t;
var q = req.query.quality; var q = req.query.quality;
const video = await fetch(config.tubeApi + `video?v=${v}`);
const info = await fetch("http://ip-api.com/json/"); const info = await fetch("http://ip-api.com/json/");
const jj = await info.text(); const jj = await info.text();
const ip = JSON.parse(jj); const ip = JSON.parse(jj);
var badges = ""; api.video(v).then((data) => {
// try few times, thanks kuylar
for (let i = 0; i < 3; i++) { const k = data.video
try { const json = data.json
const nightly = await fetch( const engagement = data.engagement
`https://lighttube-nightly.kuylar.dev/api/video?v=${v}`
); if(api.video(v).b) {
var n = await nightly.text(); var nnn = data.beta
if (n == undefined) { var badges = nnn.channel.badges[0];
for (let i = 0; i < 6; i++) { var comments = nnn.commentCount;
try {
const nightly = await fetch(
`https://lighttube-nightly.kuylar.dev/api/video?v=${v}`
);
var n = await nightly.text();
} catch (err) {
if (err.status === 500) {
await new Promise((resolve) => setTimeout(resolve, 1000));
} else {
return (n = "");
}
}
}
}
} catch (err) {
if (err.status === 500) {
// retry after a bit
await new Promise((resolve) => setTimeout(resolve, 1000));
} else {
return (n = "");
}
}
} }
var nn = ""; if(!api.video(v).b) {
var nnn = ""; var nnn = ""
var comments = ""; var badges = ""
var comments = ""
if (n == "") {
badges, nnn, (comments = "");
} }
if (IsJsonString(n)) {
if (n != "") {
nnn = JSON.parse(n);
badges = nnn.channel.badges[0];
comments = nnn.commentCount;
}
}
var fetching = await fetcher(v);
const json = fetching.video.Player;
const h = await video.text();
const k = JSON.parse(toJson(h));
if (!v) res.redirect("/"); if (!v) res.redirect("/");
//video //video
@ -247,22 +218,7 @@ app.get("/watch", async function (req, res) {
"Piwik" + "Piwik" +
sha384(config.t_url); sha384(config.t_url);
// channel info const desc = data.desc;
const engagement = fetching.engagement;
const channel = await fetch(
config.tubeApi + `channel?id=${k.Video.Channel.id}&tab=videos`
);
const c = await channel.text();
const tj = JSON.parse(toJson(c));
// about
const abtchnl = await fetch(
config.tubeApi + `channel?id=${k.Video.Channel.id}&tab=about`
);
const ab = await abtchnl.text();
const a = JSON.parse(toJson(ab));
const desc = a.Channel.Contents.ItemSection.About.Description;
var d = desc.toString().replace(/\n/g, " <br> "); var d = desc.toString().replace(/\n/g, " <br> ");
@ -270,46 +226,11 @@ app.get("/watch", async function (req, res) {
var d = false; var d = false;
} }
const summary = await wiki.summary(k.Video.Channel.Name);
var w = "";
if (summary.title === "Not found.") {
w = "none";
}
if (summary.title !== "Not found.") {
w = summary;
}
/***********
* URL = Video URl
* color= embed color
* engagement = engagement data
* video = video json info
* date = upload date
* e = embed
* k = player
* process = process information
* sha384 = encryption
* isMobile = to check if its mobile or not
* tj = channel videos page
* r = recommended videos
* qua = quality obv
* ip = ip info
* convert = formats a number
* wiki = wikipedia info
* f = recent videos from this channel
* t = default piwik url
* optout = piwik optout
* badges = channel badges
* desc = channel description
* comments = comment size
* nnn = nigthly stuff
*/
renderTemplate(res, req, "poketube.ejs", { renderTemplate(res, req, "poketube.ejs", {
url: url_e, url: url_e,
color: await getColors( color: data.color,
`https://i.ytimg.com/vi/${v}/maxresdefault.jpg`
).then((colors) => colors[0].hex()),
engagement: engagement, engagement: engagement,
video: json, video: json,
date: moment(k.Video.uploadDate).format("LL"), date: moment(k.Video.uploadDate).format("LL"),
@ -318,12 +239,12 @@ app.get("/watch", async function (req, res) {
process: process, process: process,
sha384: sha384, sha384: sha384,
isMobile: req.useragent.isMobile, isMobile: req.useragent.isMobile,
tj: tj, tj: data.channel,
r: r, r: r,
qua: q, qua: q,
ip: ip, ip: ip,
convert: convert, convert: convert,
wiki: w, wiki: data.wiki,
f: f, f: f,
t: config.t_url, t: config.t_url,
optout: t, optout: t,
@ -335,6 +256,8 @@ app.get("/watch", async function (req, res) {
}); });
}); });
});
app.get("/music", async function (req, res) { app.get("/music", async function (req, res) {
/* /*
* QUERYS * QUERYS