mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 12:17:52 +01:00
Refactor code :3
This commit is contained in:
parent
948114cebd
commit
0cc9bd398b
1 changed files with 14 additions and 17 deletions
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
const { curly } = require("node-libcurl");
|
const { curly } = require("node-libcurl");
|
||||||
const { toJson } = require("xml2json");
|
const { toJson } = require("xml2json");
|
||||||
|
|
||||||
const YOUTUBE_URL = "https://www.youtube.com/watch?v=";
|
const YOUTUBE_URL = "https://www.youtube.com/watch?v=";
|
||||||
const DISLIKE_API = "https://p.poketube.fun/api?v=";
|
const DISLIKE_API = "https://p.poketube.fun/api?v=";
|
||||||
const NEW_API_URL = "https://inner-api.poketube.fun/api/player";
|
const NEW_API_URL = "https://inner-api.poketube.fun/api/player";
|
||||||
|
@ -28,7 +28,6 @@ class PokeTubeAPI {
|
||||||
this.headers = {};
|
this.headers = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a JSON string and returns the resulting object.
|
* Parses a JSON string and returns the resulting object.
|
||||||
* @param {string} str - The JSON string to parse.
|
* @param {string} str - The JSON string to parse.
|
||||||
|
@ -42,29 +41,27 @@ class PokeTubeAPI {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves engagement data for the YouTube video.
|
* Retrieves engagement data for the YouTube video.
|
||||||
* @returns {Promise<object|null>} A Promise that resolves with the engagement data, or null if an error occurs.
|
* @returns {Promise<object|null>} A Promise that resolves with the engagement data, or null if an error occurs.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async _getEngagementData() {
|
async _getEngagementData(videoId) {
|
||||||
const apiUrl = `${DISLIKE_API}${this.videoId}&hash=d0550b6e28c8f93533a569c314d5b4e2`;
|
const apiUrl = `https://returnyoutubedislikeapi.com/votes?videoId=${videoId}`;
|
||||||
const fallbackUrl = `https://returnyoutubedislikeapi.com/votes?videoId=${this.videoId}`;
|
|
||||||
|
|
||||||
const { fetch } = await import("undici");
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const engagement = await fetch(apiUrl).then((res) => res.json());
|
const response = await fetch(apiUrl);
|
||||||
return engagement.data;
|
|
||||||
} catch {
|
if (!response.ok) {
|
||||||
try {
|
throw new Error(`Failed to fetch data from ${apiUrl}`);
|
||||||
const engagement = await fetch(fallbackUrl).then((res) => res.json());
|
|
||||||
return engagement;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const engagement = await response.json();
|
||||||
|
return engagement;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error); // You might want to handle the error more gracefully
|
||||||
|
return null; // Return null or another appropriate value in case of an error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue