mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 22:57:54 +01:00
change objects name to fit the whole thingy :3 add uhh use the initerr function ig?
This commit is contained in:
parent
910250047b
commit
4ced593d75
1 changed files with 13 additions and 7 deletions
|
@ -6,7 +6,11 @@ const youtubeUrl = 'https://www.youtube.com/watch?v=';
|
|||
const dislikeApi = 'https://p.poketube.fun/api?v=';
|
||||
const newApiUrl = 'https://inner-api.poketube.fun/api/player';
|
||||
|
||||
const parseXml = async (videoId, headers) => {
|
||||
function initerr(args){
|
||||
console.error("[LIBPT FETCHER ERROR]" + args)
|
||||
}
|
||||
|
||||
const getInnerTubeData = async (videoId, headers) => {
|
||||
try {
|
||||
var { data } = await curly.get(`${newApiUrl}?v=${videoId}`, {
|
||||
httpHeader: Object.entries(headers).map(([k, v]) => `${k}: ${v}`)
|
||||
|
@ -16,7 +20,7 @@ const parseXml = async (videoId, headers) => {
|
|||
return getJson(json);
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Error parsing XML: ${error}`);
|
||||
initerr(`Error parsing XML: ${error}`);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
@ -32,33 +36,35 @@ const getJson = (str) => {
|
|||
|
||||
|
||||
const getEngagementData = async (videoId) => {
|
||||
// return youtube dislike api - https://www.returnyoutubedislike.com/
|
||||
const apiUrl = `${dislikeApi}${videoId}`;
|
||||
const fallbackUrl = `https://p.poketube.fun/${apiUrl}`;
|
||||
|
||||
try {
|
||||
const engagement = await fetch(apiUrl).then((res) => res.json());
|
||||
return engagement.data;
|
||||
// if an error occurs - try the fallback url
|
||||
} catch {
|
||||
try {
|
||||
const engagement = await fetch(fallbackUrl).then((res) => res.json());
|
||||
return engagement;
|
||||
} catch {
|
||||
// if that also doesnt work do nothing lol
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const getPokeTubeData = async (videoId) => {
|
||||
const getBasicPokeTubeData = async (videoId) => {
|
||||
const headers = {};
|
||||
const videoData = await parseXml(videoId, headers);
|
||||
const InnerTubeData = await getInnerTubeData(videoId, headers);
|
||||
const engagement = await getEngagementData(videoId);
|
||||
|
||||
return {
|
||||
video: videoData,
|
||||
video: InnerTubeData,
|
||||
engagement,
|
||||
videoUrlYoutube: `${youtubeUrl}${videoId}`,
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = getPokeTubeData;
|
||||
module.exports = getBasicPokeTubeData;
|
||||
|
|
Loading…
Reference in a new issue