use return youtube dislike API instead

This commit is contained in:
Evert Prants 2021-12-14 18:03:29 +02:00
parent 4bb425429d
commit e24a87d3e1
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 26 additions and 5 deletions

View File

@ -39,7 +39,7 @@
},
{
"name": "urlreply",
"version": "1.0.3"
"version": "1.0.5"
},
{
"name": "utility",

View File

@ -2,7 +2,7 @@
"main": "plugin.js",
"name": "urlreply",
"description": "Fetch titles from web pages, specifically made for IRC",
"version": "1.0.4",
"version": "1.0.5",
"tags": ["irc"],
"dependencies": [],
"npmDependencies": ["cheerio@^1.0.0-rc.10"]

View File

@ -142,6 +142,14 @@ async function getYoutubeFromVideo(
return false;
}
const dislikeAPI = `https://returnyoutubedislikeapi.com/votes?videoId=${id}`;
let dislikeData = await httpGET(dislikeAPI);
try {
dislikeData = JSON.parse(dislikeData);
} catch (e) {
dislikeData = null;
}
const vid = data.items[0];
const time = full.searchParams.get('t');
let live = false;
@ -176,12 +184,25 @@ async function getYoutubeFromVideo(
keys.push(['field', ytDuration(vid.contentDetails.duration.toString()), { label: 'Duration' }]);
}
let likeCount: number | null = null;
let dislikeCount: number | null = null;
if (vid.statistics && vid.statistics.likeCount != null) {
const likeCount = vid.statistics.likeCount.toString();
// const dislikeCount = vid.statistics.dislikeCount.toString();
likeCount = vid.statistics.likeCount;
}
if (dislikeData) {
dislikeCount = dislikeData.dislikes;
if (likeCount === null) {
likeCount = dislikeData.likes;
}
}
if (likeCount !== null) {
keys.push(['field', likeCount, { color: 'limegreen', label: ['▲', 'Likes'], type: 'metric' }]);
// keys.push(['field', dislikeCount, { color: 'red', label: ['▼', 'Dislikes'], type: 'metric' }]);
}
if (dislikeCount !== null) {
keys.push(['field', dislikeCount, { color: 'red', label: ['▼', 'Dislikes'], type: 'metric' }]);
}
keys.push(['field', vid.snippet.channelTitle, { label: ['By'] }]);