Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Commit

Permalink
extractor arg: preferred_instance
Browse files Browse the repository at this point in the history
  • Loading branch information
grqx committed Oct 6, 2024
1 parent d3ffb06 commit 59cecd3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:<id>` instead of `<id>` 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:<id>` instead of `<id>` 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`.
16 changes: 10 additions & 6 deletions yt_dlp_plugins/extractor/invidious.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand All @@ -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:
Expand Down Expand Up @@ -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}'

Expand Down

0 comments on commit 59cecd3

Please sign in to comment.