diff --git a/tubearchivist/home/config.json b/tubearchivist/home/config.json index 1b6000e..edb6356 100644 --- a/tubearchivist/home/config.json +++ b/tubearchivist/home/config.json @@ -27,7 +27,8 @@ "subtitle_source": false, "subtitle_index": false, "throttledratelimit": false, - "integrate_ryd": false + "integrate_ryd": false, + "integrate_sponsorblock": false }, "application": { "app_root": "/app", diff --git a/tubearchivist/home/src/frontend/forms.py b/tubearchivist/home/src/frontend/forms.py index c4ac817..53ef284 100644 --- a/tubearchivist/home/src/frontend/forms.py +++ b/tubearchivist/home/src/frontend/forms.py @@ -62,6 +62,12 @@ class ApplicationSettingsForm(forms.Form): ("1", "enable ryd integration"), ] + SP_CHOICES = [ + ("", "-- change sponsorblock integrations"), + ("0", "disable sponsorblock integration"), + ("1", "enable sponsorblock integration"), + ] + CAST_CHOICES = [ ("", "-- change Cast integration --"), ("0", "disable Cast"), @@ -103,6 +109,9 @@ class ApplicationSettingsForm(forms.Form): downloads_integrate_ryd = forms.ChoiceField( widget=forms.Select, choices=RYD_CHOICES, required=False ) + downloads_integrate_sponsorblock = forms.ChoiceField( + widget=forms.Select, choices=SP_CHOICES, required=False + ) application_enable_cast = forms.ChoiceField( widget=forms.Select, choices=CAST_CHOICES, required=False ) diff --git a/tubearchivist/home/src/index/video.py b/tubearchivist/home/src/index/video.py index 1dafb7b..bac9e30 100644 --- a/tubearchivist/home/src/index/video.py +++ b/tubearchivist/home/src/index/video.py @@ -306,6 +306,9 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle): if self.config["downloads"]["integrate_ryd"]: self._get_ryd_stats() + if self.config["downloads"]["integrate_sponsorblock"]: + self._get_sponsorblock() + return def _process_youtube_meta(self): @@ -447,6 +450,18 @@ class YoutubeVideo(YouTubeItem, YoutubeSubtitle): return True + def _get_sponsorblock(self): + """get optional sponsorblock timestamps from sponsor.ajay.app""" + api = "https://sponsor.ajay.app/api" + url = f"{api}/skipSegments?videoID={self.youtube_id}" + print(f"{self.youtube_id}: get sponsorblock timestamps") + response = requests.get(url) + if not response.ok: + print(f"{self.youtube_id}: failed to get sponsorblock data") + return + + self.json_data["sponsorblock"] = response.json() + def check_subtitles(self): """optionally add subtitles""" handler = YoutubeSubtitle(self) diff --git a/tubearchivist/home/templates/home/settings.html b/tubearchivist/home/templates/home/settings.html index 740ca40..e4d9534 100644 --- a/tubearchivist/home/templates/home/settings.html +++ b/tubearchivist/home/templates/home/settings.html @@ -128,6 +128,11 @@ Before activating that, make sure you have a scraping sleep interval of at least 3 secs set to avoid ratelimiting issues.
{{ app_form.downloads_integrate_ryd }} +
+

Integrate with SponsorBlock to get sponsored timestamps: {{ config.downloads.integrate_sponsorblock }}

+ Before activating that, make sure you have a scraping sleep interval of at least 3 secs set to avoid ratelimiting issues.
+ {{ app_form.downloads_integrate_sponsorblock }} +

Current Cast integration: {{ config.application.enable_cast }}

Enabling Cast will load an additional JS library from Google. HTTPS and a supported browser are required for this integration.