new version!

This commit is contained in:
Ashley 2022-05-17 23:18:32 +03:00 committed by GitHub
parent dbf91956f7
commit 68eee14649
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2021-2022 POKETUBE CONTRUBUTORS (https://github.com/iamashley0/poketube) Copyright (C) 2021-2022 POKETUBE (https://github.com/iamashley0/poketube)
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -17,10 +17,13 @@
const path = require("path"); const path = require("path");
const moment = require("moment"); const moment = require("moment");
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");
var app = express(); var app = express();
app.engine("html", require("ejs").renderFile); app.engine("html", require("ejs").renderFile);
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
var dislike_api = `https://returnyoutubedislikeapi.com/votes?videoId=` var dislike_api = `https://returnyoutubedislikeapi.com/votes?videoId=`
app.set("view engine", "html"); app.set("view engine", "html");
const lyricsFinder = require("./src/lyrics.js"); const lyricsFinder = require("./src/lyrics.js");
const renderTemplate = async (res, req, template, data = {}) => { const renderTemplate = async (res, req, template, data = {}) => {
@ -29,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",
@ -42,6 +46,7 @@ const random_words = [
] ]
const fetch = require("node-fetch"); const fetch = require("node-fetch");
const fetcher = require("./src/fetcher.js"); const fetcher = require("./src/fetcher.js");
app.get("/watch", async function (req, res) { 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;
@ -69,20 +74,24 @@ if (j_.URL != undefined)
lyrics: lyrics.replace(/\n/g, " <br> "), lyrics: lyrics.replace(/\n/g, " <br> "),
}); });
}); });
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, "ytmain.ejs", { renderTemplate(res, req, "ytmain.ejs", {
random:things, random:things,
});}); });});
app.get("/channel", function (req, res) { app.get("/channel", function (req, res) {
renderTemplate(res, req, "channel.ejs"); const ID = req.query.id;
renderTemplate(res, req, "channel.ejs", {
ID:ID,
});});
app.get("/privacy", function (req, res) {
renderTemplate(res, req, "priv.ejs");
}); });
app.get("/domains", function (req, res) { app.get("/domains", function (req, res) {
renderTemplate(res, req, "domains.ejs"); renderTemplate(res, req, "domains.ejs");
}); });
app.get("/privacy", function (req, res) {
renderTemplate(res, req, "priv.ejs");
});
app.get("/api/search", async (req, res) => { app.get("/api/search", async (req, res) => {
const query = req.query.query; const query = req.query.query;
@ -94,15 +103,27 @@ app.get("/api/search", async (req, res) => {
app.get("/css/:id", (req, res) => { app.get("/css/:id", (req, res) => {
res.sendFile(__dirname + `/css/${req.params.id}`); res.sendFile(__dirname + `/css/${req.params.id}`);
}); });
app.get("/js/:id", (req, res) => {
res.sendFile(__dirname + `/js/${req.params.id}`);
});
app.get("/video/upload", (req, res) => { app.get("/video/upload", (req, res) => {
res.redirect("https://youtube.com/upload?from=poketube_utc"); res.redirect("https://youtube.com/upload?from=poketube_utc");
}); });
app.get("/api/video/download", async function (req, res) { app.get("/api/video/download", async function (req, res) {
var v = req.query.v;var fetching = await fetcher(v);const url = fetching.video.Player.Formats.Format[1].URL;res.redirect(url) var v = req.query.v;var fetching = await fetcher(v);const url = fetching.video.Player.Formats.Format[1].URL;res.redirect(url)
}); });
app.get("*", function (req, res) { app.get("/api/video/downloadjson", async function (req, res) {
var v = req.query.v;var fetching = await fetcher(v);const url = fetching.video.Player.Formats.Format[1].URL;res.json(url)
});
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,
});}); });});
const listener = app.listen(3000);
app.listen("3000", () => {
})