2021-07-07 14:35:33 +02: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");
|
|
|
|
|
|
|
|
const renderTemplate = async (res, req, template, data = {}) => {
|
|
|
|
res.render(
|
|
|
|
path.resolve(`${templateDir}${path.sep}${template}`),
|
|
|
|
Object.assign(data)
|
|
|
|
);
|
|
|
|
};
|
2022-01-23 21:50:14 +01:00
|
|
|
|
|
|
|
const ytSearch = require('youtube-search');
|
|
|
|
const fetch = require('node-fetch');
|
2021-07-07 14:35:33 +02:00
|
|
|
|
|
|
|
app.get("/watch", function(req, res) {
|
|
|
|
var url = req.query.v;
|
2021-07-11 18:15:06 +02:00
|
|
|
var uu = `https://www.youtube.com/watch?v=${url}`;
|
2021-07-07 14:35:33 +02:00
|
|
|
var search = require("youtube-search");
|
|
|
|
|
|
|
|
var opts = {
|
|
|
|
maxResults: 1,
|
|
|
|
key: process.env.yt
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetch = require("node-fetch");
|
2021-07-11 18:15:06 +02:00
|
|
|
search(uu, opts, function(err, results) {
|
2021-07-07 14:35:33 +02:00
|
|
|
var i = results[0].id;
|
2022-01-23 21:50:14 +01:00
|
|
|
fetch(`https://yt-proxy-api.herokuapp.com/get_player_info?v=${i}`)
|
2021-07-07 14:35:33 +02:00
|
|
|
.then(res => res.json())
|
|
|
|
.then(json => {
|
|
|
|
var video = results[0];
|
|
|
|
if (!video) return;
|
|
|
|
if (err) console.log(err);
|
2022-01-23 21:50:14 +01:00
|
|
|
const tarih = json.upload_date
|
|
|
|
var h = json.formats[1].url;
|
|
|
|
renderTemplate(res, req, "youtube.ejs", { url: h, title: video,video:json,date:tarih });
|
2021-07-07 14:35:33 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-01-23 21:50:14 +01:00
|
|
|
app.get("/", function(req, res) {
|
|
|
|
var url = req.query.url;
|
|
|
|
var search = require("youtube-search");
|
2021-07-07 14:35:33 +02:00
|
|
|
|
2022-01-23 21:50:14 +01:00
|
|
|
if(url){
|
|
|
|
var opts = {
|
|
|
|
maxResults: 1,
|
|
|
|
key: process.env.yt
|
|
|
|
};
|
2021-07-07 14:35:33 +02:00
|
|
|
|
2022-01-23 21:50:14 +01:00
|
|
|
search(url, opts, function(err, results) {
|
|
|
|
var h = results[0].id;
|
|
|
|
var lmao = results[0];
|
|
|
|
if(err) return
|
|
|
|
res.redirect(`/watch?v=${h}&title=${lmao.title}&channel=${lmao.channelTitle}&searchquery=${url}&data=${mythe2}${mythe}${mythe3}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if(!url){
|
|
|
|
renderTemplate(res, req, "ytmain.ejs")
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/youtube/ara', async (req, res) => {
|
|
|
|
var url = req.query.query;
|
2021-07-07 14:35:33 +02:00
|
|
|
var search = require("youtube-search");
|
|
|
|
|
|
|
|
if (!req.query.query) {
|
2021-07-07 17:05:44 +02:00
|
|
|
return res.redirect(`/`);
|
2021-07-07 14:35:33 +02: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);
|