diff --git a/squeebot.repo.json b/squeebot.repo.json index 1b07b9c..66e3577 100644 --- a/squeebot.repo.json +++ b/squeebot.repo.json @@ -39,7 +39,7 @@ }, { "name": "urlreply", - "version": "1.0.3" + "version": "1.0.5" }, { "name": "utility", diff --git a/urlreply/plugin.json b/urlreply/plugin.json index 457e023..4f76cd0 100644 --- a/urlreply/plugin.json +++ b/urlreply/plugin.json @@ -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"] diff --git a/urlreply/plugin.ts b/urlreply/plugin.ts index 9cff9fa..7db2b14 100644 --- a/urlreply/plugin.ts +++ b/urlreply/plugin.ts @@ -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'] }]);