Skip to content

Instantly share code, notes, and snippets.

@pukkandan
Last active January 18, 2024 21:56
Show Gist options
  • Save pukkandan/077465b736b861ab1aa6bf8c9bdb322a to your computer and use it in GitHub Desktop.
Save pukkandan/077465b736b861ab1aa6bf8c9bdb322a to your computer and use it in GitHub Desktop.
Moved to https://github.com/pukkandan/yt-dlp-returnyoutubedislike
"""
SPDX-License-Identifier: MIT https://opensource.org/licenses/MIT
Copyright © 2022 pukkandan.ytdlp@gmail.com
yt-dlp plugin postprocessor for https://returnyoutubedislike.com/
Needs yt-dlp v2022.04.08 or above
See https://github.com/yt-dlp/yt-dlp#plugins for how to install and
pass "--use-postprocessor ReturnYoutubeDislikes:when=pre_process"
to activate the PostProcessor
Fields defined in "RYD_FIELDS" are updated using the information from the API.
The original values of those fields and the response from the API are saved
under "RYD" key in the info dict
Note: The API has rate-limiting: https://returnyoutubedislike.com/docs/usage-rights
"""
from yt_dlp.postprocessor.common import PostProcessor
RYD_FIELDS = {
'like_count': 'likes',
'dislike_count': 'dislikes',
'average_rating': 'rating',
'view_count': 'viewCount',
}
SUPPORTED_EXTRACTORS = {
'Youtube',
}
class ReturnYoutubeDislikesPP(PostProcessor):
def run(self, info):
extractor = info['extractor_key']
if extractor not in SUPPORTED_EXTRACTORS:
self.to_screen(f'{self.PP_NAME} is not supported for {extractor}')
return [], info
api_data = self._download_json(
f'https://returnyoutubedislikeapi.com/votes?videoId={info["id"]}') or {}
info['RYD'] = {
'response': api_data,
'original': {k: info.get(k) for k in RYD_FIELDS.keys()}
}
if api_data:
info.update({k: api_data.get(v) for k, v in RYD_FIELDS.items()})
return [], info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment