youtube: use "Return YouTube Dislike" api for the dislike count

This commit is contained in:
jkhsjdhjs 2021-12-14 20:45:08 +00:00
parent 9ba23e9a29
commit 9c8203d433

View File

@ -16,6 +16,7 @@ class YouTube(Plugin):
URL = 'https://www.googleapis.com/youtube/v3' URL = 'https://www.googleapis.com/youtube/v3'
API = '{}/videos?part=snippet,statistics,contentDetails'.format(URL) API = '{}/videos?part=snippet,statistics,contentDetails'.format(URL)
SEARCH = '{}/search?part=id'.format(URL) SEARCH = '{}/search?part=id'.format(URL)
RETURN_YOUTUBE_DISLIKE_API = 'https://returnyoutubedislikeapi.com/votes'
def get_video_data(self, video_id: str): def get_video_data(self, video_id: str):
"""Requests the infos for a video id and formats them.""" """Requests the infos for a video id and formats them."""
@ -24,13 +25,15 @@ class YouTube(Plugin):
if not data.get('items'): if not data.get('items'):
return return
return_youtube_dislike_response = requests.get(self.RETURN_YOUTUBE_DISLIKE_API, params={'videoId': video_id}).json()
item = data['items'][0] item = data['items'][0]
date = date_from_iso(item['snippet']['publishedAt']) date = date_from_iso(item['snippet']['publishedAt'])
length = re.findall('(\d+[DHMS])', item['contentDetails']['duration']) length = re.findall('(\d+[DHMS])', item['contentDetails']['duration'])
views = int(item['statistics'].get('viewCount', 0)) views = int(item['statistics'].get('viewCount', 0))
likes = int(item['statistics'].get('likeCount', 0)) likes = int(item['statistics'].get('likeCount', 0))
dislikes = int(item['statistics'].get('dislikeCount', 0)) dislikes = int(return_youtube_dislike_response.get('dislikes', 0))
try: try:
score = 100 * float(likes) / (likes + dislikes) score = 100 * float(likes) / (likes + dislikes)