From 1c0b407f3f119c18be745a65a891db41d96d5031 Mon Sep 17 00:00:00 2001 From: Dominik Sander Date: Sat, 29 Apr 2023 11:32:52 +0200 Subject: [PATCH] Allow to configure yt-dlp `--format-sort` argument (#471) * Allow to configure yt-dlp `--format-sort` argument This exposes the [`--format-sort`][1] yt-dlp option to the user. Implements parts of #316 [1]: https://github.com/yt-dlp/yt-dlp#sorting-formats * Trim split values of format_sort, obey black * Add `format_sort` to default configuration * Add note about codec compatibility to settings page --- tubearchivist/home/config.json | 1 + tubearchivist/home/src/download/yt_dlp_handler.py | 4 ++++ tubearchivist/home/src/frontend/forms.py | 1 + tubearchivist/home/templates/home/settings.html | 13 +++++++++++++ 4 files changed, 19 insertions(+) diff --git a/tubearchivist/home/config.json b/tubearchivist/home/config.json index 08f7645..f2fa66e 100644 --- a/tubearchivist/home/config.json +++ b/tubearchivist/home/config.json @@ -24,6 +24,7 @@ "sleep_interval": 3, "autodelete_days": false, "format": false, + "format_sort": false, "add_metadata": false, "add_thumbnail": false, "subtitle": false, diff --git a/tubearchivist/home/src/download/yt_dlp_handler.py b/tubearchivist/home/src/download/yt_dlp_handler.py index 529526f..2a57d03 100644 --- a/tubearchivist/home/src/download/yt_dlp_handler.py +++ b/tubearchivist/home/src/download/yt_dlp_handler.py @@ -312,6 +312,10 @@ class VideoDownloader: """build user customized options""" if self.config["downloads"]["format"]: self.obs["format"] = self.config["downloads"]["format"] + if self.config["downloads"]["format_sort"]: + format_sort = self.config["downloads"]["format_sort"] + format_sort_list = [i.strip() for i in format_sort.split(",")] + self.obs["format_sort"] = format_sort_list if self.config["downloads"]["limit_speed"]: self.obs["ratelimit"] = ( self.config["downloads"]["limit_speed"] * 1024 diff --git a/tubearchivist/home/src/frontend/forms.py b/tubearchivist/home/src/frontend/forms.py index 85c132a..e06fda8 100644 --- a/tubearchivist/home/src/frontend/forms.py +++ b/tubearchivist/home/src/frontend/forms.py @@ -113,6 +113,7 @@ class ApplicationSettingsForm(forms.Form): downloads_sleep_interval = forms.IntegerField(required=False) downloads_autodelete_days = forms.IntegerField(required=False) downloads_format = forms.CharField(required=False) + downloads_format_sort = forms.CharField(required=False) downloads_add_metadata = forms.ChoiceField( widget=forms.Select, choices=METADATA_CHOICES, required=False ) diff --git a/tubearchivist/home/templates/home/settings.html b/tubearchivist/home/templates/home/settings.html index 51012cc..eaccae7 100644 --- a/tubearchivist/home/templates/home/settings.html +++ b/tubearchivist/home/templates/home/settings.html @@ -95,6 +95,19 @@ {{ app_form.downloads_format }}
+
+

Force sort order to have precedence over all yt-dlp fields.
+ Currently: {{ config.downloads.format_sort }} +

+

Example configurations:

+ + Not all codecs are supported by all browsers. The default value ensures best compatibility. Check out the documentation for valid configurations.
+ {{ app_form.downloads_format_sort }} +
+

Current metadata embed setting: {{ config.downloads.add_metadata }}

Metadata is not embedded into the downloaded files by default.