mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 18:38:18 +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 dislikeApi = 'https://p.poketube.fun/api?v=';
|
||||||
const newApiUrl = 'https://inner-api.poketube.fun/api/player';
|
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 {
|
try {
|
||||||
var { data } = await curly.get(`${newApiUrl}?v=${videoId}`, {
|
var { data } = await curly.get(`${newApiUrl}?v=${videoId}`, {
|
||||||
httpHeader: Object.entries(headers).map(([k, v]) => `${k}: ${v}`)
|
httpHeader: Object.entries(headers).map(([k, v]) => `${k}: ${v}`)
|
||||||
|
@ -16,7 +20,7 @@ const parseXml = async (videoId, headers) => {
|
||||||
return getJson(json);
|
return getJson(json);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error parsing XML: ${error}`);
|
initerr(`Error parsing XML: ${error}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -32,33 +36,35 @@ const getJson = (str) => {
|
||||||
|
|
||||||
|
|
||||||
const getEngagementData = async (videoId) => {
|
const getEngagementData = async (videoId) => {
|
||||||
|
// return youtube dislike api - https://www.returnyoutubedislike.com/
|
||||||
const apiUrl = `${dislikeApi}${videoId}`;
|
const apiUrl = `${dislikeApi}${videoId}`;
|
||||||
const fallbackUrl = `https://p.poketube.fun/${apiUrl}`;
|
const fallbackUrl = `https://p.poketube.fun/${apiUrl}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const engagement = await fetch(apiUrl).then((res) => res.json());
|
const engagement = await fetch(apiUrl).then((res) => res.json());
|
||||||
return engagement.data;
|
return engagement.data;
|
||||||
|
// if an error occurs - try the fallback url
|
||||||
} catch {
|
} catch {
|
||||||
try {
|
try {
|
||||||
const engagement = await fetch(fallbackUrl).then((res) => res.json());
|
const engagement = await fetch(fallbackUrl).then((res) => res.json());
|
||||||
return engagement;
|
return engagement;
|
||||||
} catch {
|
} catch {
|
||||||
|
// if that also doesnt work do nothing lol
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getBasicPokeTubeData = async (videoId) => {
|
||||||
const getPokeTubeData = async (videoId) => {
|
|
||||||
const headers = {};
|
const headers = {};
|
||||||
const videoData = await parseXml(videoId, headers);
|
const InnerTubeData = await getInnerTubeData(videoId, headers);
|
||||||
const engagement = await getEngagementData(videoId);
|
const engagement = await getEngagementData(videoId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
video: videoData,
|
video: InnerTubeData,
|
||||||
engagement,
|
engagement,
|
||||||
videoUrlYoutube: `${youtubeUrl}${videoId}`,
|
videoUrlYoutube: `${youtubeUrl}${videoId}`,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = getPokeTubeData;
|
module.exports = getBasicPokeTubeData;
|
||||||
|
|
Loading…
Reference in a new issue