mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-23 09:28:06 +01:00
Update fetcher.js
This commit is contained in:
parent
444757963b
commit
a068e8aafd
1 changed files with 34 additions and 27 deletions
|
@ -16,28 +16,27 @@
|
||||||
along with this program. If not, see https://www.gnu.org/licenses/.
|
along with this program. If not, see https://www.gnu.org/licenses/.
|
||||||
*/
|
*/
|
||||||
const fetch = require("node-fetch"); //2.5.x
|
const fetch = require("node-fetch"); //2.5.x
|
||||||
const superfetch = require("../src/modules/node-superfetch.js")
|
const xmltojson = require("xml2json")
|
||||||
const lyricsFinder = require("lyrics-finder");
|
const lyricsFinder = require("lyrics-finder");
|
||||||
var youtube_url = `https://www.youtube.com/watch?v=`;
|
var youtube_url = `https://www.youtube.com/watch?v=`;
|
||||||
var dislike_api = `https://returnyoutubedislikeapi.com/votes?videoId=`
|
var dislike_api = `https://returnyoutubedislikeapi.com/votes?videoId=`
|
||||||
var proxy = `https://yt-proxy-api.herokuapp.com/get_player_info?v=`
|
var new_api_url = `https://lighttube.herokuapp.com/api/player`
|
||||||
|
|
||||||
module.exports = async function(video_id){
|
module.exports = async function(video_id){
|
||||||
|
const dislike = await fetch(`${dislike_api}${video_id}`).then((res) => res.json());
|
||||||
const pro = await fetch(`${proxy}${video_id}`).then((res) => res.json());
|
|
||||||
const dislike = await fetch(`${dislike_api}${video_id}`).then((res) => res.json());
|
|
||||||
const dislikes = dislike.dislikes
|
const dislikes = dislike.dislikes
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This is a if else statment to check the lastest
|
functions to fetch xml
|
||||||
format from the fetched url and return it lmao
|
*/
|
||||||
*/
|
async function fetchxml(id){
|
||||||
if(pro.formats[1].url){
|
const player = await fetch(`https://lighttube.herokuapp.com/api/player?v=${id}`)
|
||||||
var url = pro.formats[1].url
|
return player.text()
|
||||||
} else if(!pro.formats[1].url){
|
}
|
||||||
var s = pro.formats
|
|
||||||
const lastItem = s[s.length - 1];
|
async function parsexml(id){
|
||||||
var url = lastItem.url
|
var h = await fetchxml(id)
|
||||||
|
var j = xmltojson.toJson(h);
|
||||||
|
return JSON.parse(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,12 +44,20 @@ module.exports = async function(video_id){
|
||||||
* Returner object
|
* Returner object
|
||||||
*/
|
*/
|
||||||
const returner = {
|
const returner = {
|
||||||
video:pro,
|
video:await parsexml(video_id),
|
||||||
dislikes:dislikes,
|
engagement:dislike,
|
||||||
likes:dislike.likes,
|
video_url_youtube:`${youtube_url}${video_id}`
|
||||||
video_downloaded_url:url,
|
}
|
||||||
video_url_youtube:`${youtube_url}${video_id}`,
|
return returner
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.searcher = async function searcher(query,res){
|
||||||
|
const search = await fetch(`https://lighttube.herokuapp.com/api/search?query=${query}`)
|
||||||
|
const text = await search.text()
|
||||||
|
const j = JSON.parse(xmltojson.toJson(text));
|
||||||
|
for (item of j.Search.Results.Video) {
|
||||||
|
const videoid = item.id;
|
||||||
|
return res.redirect(`/watch?v=${videoid}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return returner
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue