Update server.js

This commit is contained in:
Ashley 2022-07-13 15:35:18 +03:00 committed by GitHub
parent 3ecd0d9c92
commit cb7c6f78e9

View file

@ -32,6 +32,7 @@ const renderTemplate = async (res, req, template, data = {}) => {
Object.assign(data) Object.assign(data)
); );
}; };
const random_words = [ const random_words = [
"banana pie", "banana pie",
"how to buy an atom bomb", "how to buy an atom bomb",
@ -43,6 +44,7 @@ const random_words = [
"is a panda a panda if pandas???", "is a panda a panda if pandas???",
"Minecraft movie trailer", "Minecraft movie trailer",
]; ];
const image_urls = [ const image_urls = [
"https://cdn.glitch.com/4095e32f-375a-40f2-841e-961cee4c2a95/sheng-l-q2dUSl9S4Xg-unsplash.jpg?v=1655990895950", "https://cdn.glitch.com/4095e32f-375a-40f2-841e-961cee4c2a95/sheng-l-q2dUSl9S4Xg-unsplash.jpg?v=1655990895950",
"https://cdn.glitch.com/4095e32f-375a-40f2-841e-961cee4c2a95/willian-justen-de-vasconcellos-T_Qe4QlMIvQ-unsplash(1).jpg?v=1655991004992", "https://cdn.glitch.com/4095e32f-375a-40f2-841e-961cee4c2a95/willian-justen-de-vasconcellos-T_Qe4QlMIvQ-unsplash(1).jpg?v=1655991004992",
@ -71,6 +73,7 @@ app.get("/watch", async function (req, res) {
var v = req.query.v; var v = req.query.v;
var e = req.query.e; var e = req.query.e;
var r = req.query.r; var r = req.query.r;
var f = req.query.f;
var t = req.query.t; var t = req.query.t;
const video = await fetch(config.tubeApi + `video?v=${v}`); const video = await fetch(config.tubeApi + `video?v=${v}`);
const h = await video.text(); const h = await video.text();
@ -83,6 +86,11 @@ app.get("/watch", async function (req, res) {
if (j_.URL != undefined) url = j_.URL; if (j_.URL != undefined) url = j_.URL;
const json = fetching.video.Player; const json = fetching.video.Player;
const engagement = fetching.engagement; const engagement = fetching.engagement;
const channel = await fetch(
config.tubeApi + `channel?id=${json.Channel.id}&tab=videos`
);
const c = await channel.text();
const tj = JSON.parse(toJson(c));
const lyrics = await lyricsFinder(json.Title); const lyrics = await lyricsFinder(json.Title);
if (lyrics == undefined) lyrics = "Lyrics not found"; if (lyrics == undefined) lyrics = "Lyrics not found";
renderTemplate(res, req, "poketube.ejs", { renderTemplate(res, req, "poketube.ejs", {
@ -95,14 +103,15 @@ app.get("/watch", async function (req, res) {
date: moment(k.Video.uploadDate).format("LL"), date: moment(k.Video.uploadDate).format("LL"),
e: e, e: e,
k: k, k: k,
tj: tj,
r: r, r: r,
f: f,
t: config.t_url, t: config.t_url,
optout: t, optout: t,
lyrics: lyrics.replace(/\n/g, " <br> "), lyrics: lyrics.replace(/\n/g, " <br> "),
}); });
}); });
app.get("/download", async function (req, res) { app.get("/download", async function (req, res) {
var v = req.query.v; var v = req.query.v;
@ -117,7 +126,7 @@ app.get("/download", async function (req, res) {
if (j_.URL != undefined) url = j_.URL; if (j_.URL != undefined) url = j_.URL;
const json = fetching.video.Player; const json = fetching.video.Player;
const engagement = fetching.engagement; const engagement = fetching.engagement;
renderTemplate(res, req, "download.ejs", { renderTemplate(res, req, "download.ejs", {
url: url, url: url,
engagement: engagement, engagement: engagement,
@ -165,8 +174,6 @@ app.get("/music", async function (req, res) {
}); });
}); });
app.get("/old/watch", async function (req, res) { app.get("/old/watch", async function (req, res) {
var v = req.query.v; var v = req.query.v;
var e = req.query.e; var e = req.query.e;
@ -277,7 +284,7 @@ app.get("/api/video/downloadjson", async function (req, res) {
const url = fetching.video.Player.Formats.Format[1].URL; const url = fetching.video.Player.Formats.Format[1].URL;
res.json(url); res.json(url);
}); });
app.get("*", function (req, res) { app.get("*", function (req, res) {
const things = random_words[Math.floor(Math.random() * random_words.length)]; const things = random_words[Math.floor(Math.random() * random_words.length)];
renderTemplate(res, req, "404.ejs", { renderTemplate(res, req, "404.ejs", {
@ -285,7 +292,6 @@ app.get("*", function (req, res) {
}); });
}); });
//
//
app.listen("3000", () => {}); app.listen("3000", () => {});