2021-07-07 08:35:33 -04:00
|
|
|
const path = require("path");
|
|
|
|
const templateDir = path.resolve(`${process.cwd()}${path.sep}html`);
|
|
|
|
var express = require("express");
|
|
|
|
var app = express();
|
|
|
|
app.engine("html", require("ejs").renderFile);
|
|
|
|
app.set("view engine", "html");
|
2022-02-13 06:01:27 -05:00
|
|
|
const lyricsFinder = require("lyrics-finder");
|
|
|
|
const renderTemplate = async (res, req, template, data = {}) => {
|
|
|
|
res.render(path.resolve(`${templateDir}${path.sep}${template}`), Object.assign(data)
|
|
|
|
);
|
2021-07-07 08:35:33 -04:00
|
|
|
};
|
2022-02-13 06:01:27 -05:00
|
|
|
const ytSearch = require('youtube-search');
|
2022-01-23 15:50:14 -05:00
|
|
|
const fetch = require('node-fetch');
|
2022-02-13 06:01:27 -05:00
|
|
|
const search = require("youtube-search");
|
2021-07-07 08:35:33 -04:00
|
|
|
|
|
|
|
app.get("/watch", function(req, res) {
|
|
|
|
var url = req.query.v;
|
2021-07-11 12:15:06 -04:00
|
|
|
var uu = `https://www.youtube.com/watch?v=${url}`;
|
2022-02-13 06:01:27 -05:00
|
|
|
var search = require("youtube-search");
|
2021-07-07 08:35:33 -04:00
|
|
|
|
|
|
|
var opts = {
|
|
|
|
maxResults: 1,
|
|
|
|
key: process.env.yt
|
|
|
|
};
|
2022-02-13 06:01:27 -05:00
|
|
|
|
|
|
|
search(uu, opts, async (err, results) => {
|
|
|
|
if (err != undefined)
|
|
|
|
return console.error(err);
|
|
|
|
if (results.length === 0) return;
|
|
|
|
|
|
|
|
const video = results[0];
|
|
|
|
|
|
|
|
const json = await fetch(`https://yt-proxy-api.herokuapp.com/get_player_info?v=${video.id}`)
|
|
|
|
.then((res) => res.json());
|
|
|
|
|
|
|
|
const lyrics = await lyricsFinder(video.title);
|
|
|
|
|
|
|
|
if (lyrics == undefined) lyrics = "Lyrics not found";
|
|
|
|
renderTemplate(res, req, 'youtube.ejs', {
|
|
|
|
url: json.formats[1].url,
|
|
|
|
title: video,
|
|
|
|
video: json,
|
|
|
|
date: json.upload_date,
|
|
|
|
lyrics:lyrics.replace(/\n/g, ' <br> ')
|
2021-07-07 08:35:33 -04:00
|
|
|
});
|
2022-02-13 06:01:27 -05:00
|
|
|
});
|
2021-07-07 08:35:33 -04:00
|
|
|
});
|
2022-01-23 15:50:14 -05:00
|
|
|
app.get("/", function(req, res) {
|
|
|
|
var url = req.query.url;
|
2021-07-07 08:35:33 -04:00
|
|
|
|
2022-01-23 15:50:14 -05:00
|
|
|
if(url){
|
|
|
|
var opts = {
|
|
|
|
maxResults: 1,
|
|
|
|
key: process.env.yt
|
|
|
|
};
|
2021-07-07 08:35:33 -04:00
|
|
|
|
2022-01-23 15:50:14 -05:00
|
|
|
search(url, opts, function(err, results) {
|
|
|
|
var h = results[0].id;
|
|
|
|
var lmao = results[0];
|
|
|
|
if(err) return
|
2022-01-23 15:55:04 -05:00
|
|
|
res.redirect(`/watch?v=${h}&title=${lmao.title}&channel=${lmao.channelTitle}&searchquery=${url}`);
|
2022-01-23 15:50:14 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if(!url){
|
|
|
|
renderTemplate(res, req, "ytmain.ejs")
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/youtube/ara', async (req, res) => {
|
2022-02-13 06:01:27 -05:00
|
|
|
var url = req.query.query;
|
|
|
|
|
2021-07-07 08:35:33 -04:00
|
|
|
if (!req.query.query) {
|
2021-07-07 11:05:44 -04:00
|
|
|
return res.redirect(`/`);
|
2021-07-07 08:35:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var opts = {
|
|
|
|
maxResults: 1,
|
|
|
|
key: process.env.yt
|
|
|
|
};
|
|
|
|
|
|
|
|
search(req.query.query, opts, function(err, results) {
|
|
|
|
var h = results[0].id;
|
|
|
|
res.redirect(`/watch?v=${h}`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const listener = app.listen(3000);
|