add music (very beta)

This commit is contained in:
Ashley 2022-07-11 00:41:52 +03:00 committed by GitHub
parent 3e4787921f
commit 575618c8a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -102,6 +102,46 @@ app.get("/watch", async function (req, res) {
}); });
}); });
app.get("/music", async function (req, res) {
var v = req.query.v;
const getColors = require("get-image-colors");
var e = req.query.e;
var r = req.query.r;
var t = req.query.t;
const { toJson } = require("xml2json");
const video = await fetch(config.tubeApi + `video?v=${v}`);
const h = await video.text();
const k = JSON.parse(toJson(h));
if (!v) res.redirect("/");
var fetching = await fetcher(v);
const j = fetching.video.Player.Formats.Format,
j_ = Array.isArray(j) ? j[j.length - 1] : j;
let url;
if (j_.URL != undefined) url = j_.URL;
const json = fetching.video.Player;
const engagement = fetching.engagement;
const lyrics = await lyricsFinder(json.Title);
if (lyrics == undefined) lyrics = "Lyrics not found";
renderTemplate(res, req, "poketube-music.ejs", {
url: url,
color: await getColors(
`https://i.ytimg.com/vi/${v}/maxresdefault.jpg`
).then((colors) => colors[0].hex()),
engagement: engagement,
video: json,
date: moment(k.Video.uploadDate).format("LL"),
e: e,
k: k,
r: r,
t: config.t_url,
optout: t,
lyrics: lyrics.replace(/\n/g, " <br> "),
});
});
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;
const getColors = require("get-image-colors"); const getColors = require("get-image-colors");
@ -213,11 +253,15 @@ 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", {
random: things, random: things,
}); });
}); });
//
app.listen("3000", () => {}); app.listen("3000", () => {});