diff --git a/tubearchivist/home/config.json b/tubearchivist/home/config.json index 5bbd38b..aa1580d 100644 --- a/tubearchivist/home/config.json +++ b/tubearchivist/home/config.json @@ -23,7 +23,8 @@ "format": false, "add_metadata": false, "add_thumbnail": false, - "throttledratelimit": false + "throttledratelimit": false, + "integrate_ryd": false }, "application": { "app_root": "/app", diff --git a/tubearchivist/home/forms.py b/tubearchivist/home/forms.py index 8750134..d5a52db 100644 --- a/tubearchivist/home/forms.py +++ b/tubearchivist/home/forms.py @@ -56,11 +56,18 @@ class ApplicationSettingsForm(forms.Form): ("1", "embed thumbnail"), ] + RYD_CHOICES = [ + ("", "-- change ryd integrations"), + ("0", "disable ryd integration"), + ("1", "enable ryd integration"), + ] + subscriptions_channel_size = forms.IntegerField(required=False) downloads_limit_count = forms.IntegerField(required=False) downloads_limit_speed = forms.IntegerField(required=False) downloads_throttledratelimit = forms.IntegerField(required=False) downloads_sleep_interval = forms.IntegerField(required=False) + downloads_autodelete_days = forms.IntegerField(required=False) downloads_format = forms.CharField(required=False) downloads_add_metadata = forms.ChoiceField( widget=forms.Select, choices=METADATA_CHOICES, required=False @@ -68,7 +75,9 @@ class ApplicationSettingsForm(forms.Form): downloads_add_thumbnail = forms.ChoiceField( widget=forms.Select, choices=THUMBNAIL_CHOICES, required=False ) - downloads_autodelete_days = forms.IntegerField(required=False) + downloads_integrate_ryd = forms.ChoiceField( + widget=forms.Select, choices=RYD_CHOICES, required=False + ) class SchedulerSettingsForm(forms.Form): diff --git a/tubearchivist/home/src/index.py b/tubearchivist/home/src/index.py index 40b48b5..3eb8eef 100644 --- a/tubearchivist/home/src/index.py +++ b/tubearchivist/home/src/index.py @@ -14,6 +14,7 @@ from time import sleep import requests import yt_dlp from bs4 import BeautifulSoup +from ryd_client import ryd_client from home.src.config import AppConfig from home.src.helper import DurationConverter, UrlListParser, clean_string from home.src.thumbnails import ThumbManager @@ -282,6 +283,7 @@ class YoutubeVideo: ES_AUTH = CONFIG["application"]["es_auth"] CACHE_DIR = CONFIG["application"]["cache_dir"] VIDEOS = CONFIG["application"]["videos"] + RYD = CONFIG["downloads"]["integrate_ryd"] def __init__(self, youtube_id): self.youtube_id = youtube_id @@ -303,6 +305,8 @@ class YoutubeVideo: break self.vid_dict = vid_dict + if self.RYD: + self.get_ryd_stats() def get_youtubedl_vid_data(self): """parse youtubedl extract info""" @@ -446,6 +450,23 @@ class YoutubeVideo: # delete thumbs from cache ThumbManager().delete_vid_thumb(self.youtube_id) + def get_ryd_stats(self): + """get optional stats from returnyoutubedislikeapi.com""" + try: + print(f"get ryd stats for: {self.youtube_id}") + result = ryd_client.get(self.youtube_id) + except requests.exceptions.ConnectionError: + print(f"failed to query ryd api, skipping {self.youtube_id}") + return False + + dislikes = { + "dislike_count": result["dislikes"], + "average_rating": result["rating"], + } + self.vid_dict["stats"].update(dislikes) + + return True + class YoutubePlaylist: """represent a single playlist on YouTube""" diff --git a/tubearchivist/home/templates/home/settings.html b/tubearchivist/home/templates/home/settings.html index 8c99010..9eb7731 100644 --- a/tubearchivist/home/templates/home/settings.html +++ b/tubearchivist/home/templates/home/settings.html @@ -95,6 +95,14 @@ {{ app_form.downloads_add_thumbnail }} +
Integrate with returnyoutubedislike.com: {{ config.downloads.integrate_ryd }}
+ Get dislikes and average ratings back.