change classname to PokeTubeDislikesAPIManager

This commit is contained in:
Ashley 2023-10-21 04:51:20 +00:00
parent 85841c595c
commit d63cbc3690

View file

@ -9,7 +9,7 @@
/**
* A class representing a PokeTube API instance for a specific video.
*/
class PokeTubeAPI {
class PokeTubeDislikesAPIManager {
/**
* Creates a new PokeTube API instance for the given video ID.
* @param {string} videoId - The ID of the YouTube video.
@ -40,18 +40,27 @@ class PokeTubeAPI {
* @returns {Promise<object|null>} A Promise that resolves with the engagement data, or null if an error occurs.
* @private
*/
async _getEngagementData() {
var url = [`https://p.poketube.fun/api?v=${this.videoId}&hash=d0550b6e28c8f93533a569c314d5b4e2`, `https://returnyoutubedislikeapi.com/votes?videoId=${this.videoId}`]
const dislikes =
url[Math.floor(Math.random() * url.length)];
async _getEngagementData() {
const apiUrl = `https://p.poketube.fun/api?v=${this.videoId}&hash=d0550b6e28c8f93533a569c314d5b4e2`;
const fallbackUrl = `https://returnyoutubedislikeapi.com/votes?videoId=${this.videoId}`;
const { fetch } = await import("undici");
const { fetch } = await import("undici");
const engagement = await fetch(dislikes).then((res) => res.json());
return engagement;
try {
const engagement = await fetch(apiUrl).then((res) => res.json());
return engagement;
} catch {
try {
const engagement = await fetch(fallbackUrl).then((res) => res.json());
return engagement;
} catch {
return null;
}
}
}
/**
* Retrieves data about the YouTube video and its engagement.
* @returns {Promise<object>} A Promise that resolves with an object containing video and engagement data.
@ -75,7 +84,7 @@ class PokeTubeAPI {
}
/*
Returns basic data about a given YouTube video using PokeTubeAPI.
Returns basic data about a given YouTube video using PokeTubeDislikesAPIManager.
@async
@function
@param {string} videoId - The YouTube video ID to get data for.
@ -83,9 +92,9 @@ Returns basic data about a given YouTube video using PokeTubeAPI.
@throws {Error} If the video ID is invalid or the request fails.
*/
const getBasicPokeTubeData = async (videoId) => {
const pokeTubeAPI = new PokeTubeAPI(videoId);
return await pokeTubeAPI.getData();
const getDislikesData = async (videoId) => {
const pokeTubeAPI = new PokeTubeDislikesAPIManager(videoId);
return await PokeTubeDislikesAPIManager.getData();
};
module.exports = getBasicPokeTubeData;
module.exports = getDislikesData;