diff --git a/README.md b/README.md index 5316bfe..471ff29 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # yt-dlp-invidious This repository contains a plugin for [yt-dlp](https://github.com/yt-dlp/yt-dlp#readme). See [yt-dlp plugins](https://github.com/yt-dlp/yt-dlp#plugins) for more details. The plugin adds native support for Invidious and allows youtube downloads to fallback to Invidious on the error 'Sign in to confirm you’re not a bot. This helps protect our community. Learn more'. -The code is based on https://github.com/ytdl-org/youtube-dl/pull/31426. +The code is based on [ytdl-org/youtube-dl#31426](https://github.com/ytdl-org/youtube-dl/pull/31426). ## Installation @@ -48,13 +48,20 @@ Just use yt-dlp as normal, the plugin will automatically fall back to invidious ### Force override mode -Pass `--ies "Invidious,InvidiousPlaylist,default,-youtube,-youtubeplaylist"` to yt-dlp. The plugin automatically matches the video id/playlist id so you can just pass a YouTube link or even just a video id/playlist id. For a single video id, use `invidious:` instead of `` to force yt-dlp to use Invidious. +Pass `--ies "Invidious,InvidiousPlaylist"` to yt-dlp. The plugin automatically matches the video id/playlist id so you can just pass a video id/playlist id. For a single video id, use `invidious:` instead of `` to force yt-dlp to use Invidious. ### Extractor arguments -See [EXTRACTOR ARGUMENTS](https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#extractor-arguments). -- `InvidiousIE`: - - `max_retries`: maxium retry times. (default: 5) - e.g. `--extractor-args "Invidious:max_retries=infinite"` (unrecommended), - `--extractor-args "Invidious:max_retries=3"`. - - `retry_interval`: interval between retries (in seconds). (default: 5) - e.g. `--extractor-args "Invidious:retry_interval=3.45"` +Use something like `--extractor-args "invidious:max_retries=3;retry_interval=3.45" --extractor-args "invidiousplaylist:preferred_instance=inv.nadeko.net"` to pass multiple extractor arguments in a single run. +See [EXTRACTOR ARGUMENTS](https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#extractor-arguments) for more details. + +#### **invidious** +- `max_retries`: maxium retry times. (default: 5) + e.g. `infinite` (unrecommended), `3`. +- `retry_interval`: interval between retries (in seconds). (default: 5) + e.g. `3.45`. +- `preferred_instance`: netloc of preferred instance (default: `INSTANCES[0]`) + e.g. `inv.nadeko.net`. + +#### **invidiousplaylist** +- `preferred_instance`: netloc of preferred instance (default: `INSTANCES[0]`) + e.g. `inv.nadeko.net`. diff --git a/yt_dlp_plugins/extractor/invidious.py b/yt_dlp_plugins/extractor/invidious.py index 5f7faae..e9f4c96 100644 --- a/yt_dlp_plugins/extractor/invidious.py +++ b/yt_dlp_plugins/extractor/invidious.py @@ -137,18 +137,22 @@ def _get_thumbnails(self, api_response): def _real_extract(self, url): video_id = (self._match_valid_url(url) or YoutubeIE._match_valid_url(url)).group('id') + preferred_instance = self._configuration_arg('preferred_instance', [INSTANCES[0]])[0] # host_url will contain `http[s]://example.com` where `example.com` is the used invidious instance. url_parsed = urllib.parse.urlparse(url) url = urllib.parse.urlunparse(( url_parsed.scheme or 'http', - INSTANCES[0] if url_parsed.netloc not in INSTANCES else url_parsed.netloc, + ( + preferred_instance + if url_parsed.netloc not in [preferred_instance, *INSTANCES] + else url_parsed.netloc + ), url_parsed.path, url_parsed.params, url_parsed.query, url_parsed.fragment, )) - # TODO: extractor arg: preferred_instance url_parsed = urllib.parse.urlparse(url) self.url_netloc = url_parsed.netloc host_url = f'{url_parsed.scheme}://{self.url_netloc}' @@ -160,8 +164,7 @@ def _real_extract(self, url): max_retries = int(max_retries) retry_interval = traverse_obj( - self._configuration_arg('retry_interval', ['5']), - (0, {float_or_none}), 5) + self._configuration_arg('retry_interval', ['5']), (0, {float_or_none})) retries = 0 while retries <= max_retries: @@ -297,13 +300,14 @@ def _get_entries(self, api_response): def _real_extract(self, url): playlist_id = (self._match_valid_url(url) or YoutubePlaylistIE._match_valid_url(url)).group('id') + preferred_instance = self._configuration_arg('preferred_instance', [INSTANCES[0]])[0] # host_url will contain `http[s]://example.com` where `example.com` is the used invidious instance. url_parsed = urllib.parse.urlparse(url) - if url_parsed.netloc in INSTANCES: + if url_parsed.netloc in [preferred_instance, *INSTANCES]: netloc = url_parsed.netloc else: - netloc = INSTANCES[0] + netloc = preferred_instance self.host_url = f'{url_parsed.scheme or "http"}://{netloc}'