From 971bfced6d2062a95203f1cfecf82881fc70a91b Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 25 Mar 2022 19:42:11 +0300 Subject: [PATCH] Create video.js --- sdk/src/video.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 sdk/src/video.js diff --git a/sdk/src/video.js b/sdk/src/video.js new file mode 100644 index 00000000..fea50eb3 --- /dev/null +++ b/sdk/src/video.js @@ -0,0 +1,39 @@ + +const fetch = require("node-fetch"); +const xmltojson = require("xml2json") +const url = require("../config.json") + +class videoFetchManager{ + static async getVideoJsonByID(ID){ + const player = await fetch(url.poketube_api + `/player?v=${ID}`) + var text = await player.text();var json = xmltojson.toJson(text);let parser = JSON.parse(json); + return parser +} + static async getEngagementByID(ID){ + const engagement = await fetch(url.dislike_api + `${ID}`) + const returner = { + likes:engagement.likes.toLocaleString(), + dislikes:engagement.dislikes.toLocaleString(), + viewCount:engagement.viewCount.toLocaleString() + } + return returner + } + static async downloadVideo(ID){ + const player = await fetch(url.poketube_api + `/player?v=${ID}`) + var text = await player.text(); + var json = xmltojson.toJson(text); + let parser = JSON.parse(json); + const fetching = parser + var j = fetching.Player.Formats.Format + if(j[1].URL){ + var url = j[1].URL + } else if(j[1].URL){ + var s = j.formats + const lastItem = s[s.length - 1]; + var url = lastItem.URL + } + return url + } +} + +module.exports = videoFetchManager