diff --git a/README.md b/README.md
index ccd221bb44..a27aee34c8 100644
--- a/README.md
+++ b/README.md
@@ -1559,6 +1559,10 @@ #### funimation
* `language`: Languages to extract. Eg: `funimation:language=english,japanese`
* `version`: The video version to extract - `uncut` or `simulcast`
+#### crunchyroll
+* `language`: Languages to extract. Eg: `crunchyroll:language=jaJp`
+* `hardsub`: Which hard-sub versions to extract. Eg: `crunchyroll:hardsub=None,enUS`
+
#### vikichannel
* `video_types`: Types of videos to download - one or more of `episodes`, `movies`, `clips`, `trailers`
diff --git a/yt_dlp/extractor/crunchyroll.py b/yt_dlp/extractor/crunchyroll.py
index 511ac1b2ce..cd35728e58 100644
--- a/yt_dlp/extractor/crunchyroll.py
+++ b/yt_dlp/extractor/crunchyroll.py
@@ -27,6 +27,7 @@
int_or_none,
lowercase_escape,
merge_dicts,
+ qualities,
remove_end,
sanitized_Request,
try_get,
@@ -478,19 +479,24 @@ def _real_extract(self, url):
[r']+href="/publisher/[^"]+"[^>]*>([^<]+)', r'
\s*Publisher:\s*\s*(.+?)\s*\s*
'],
webpage, 'video_uploader', default=False)
+ requested_languages = self._configuration_arg('language')
+ requested_hardsubs = [('' if val == 'none' else val) for val in self._configuration_arg('hardsub')]
+ language_preference = qualities((requested_languages or [language or ''])[::-1])
+ hardsub_preference = qualities((requested_hardsubs or ['', language or ''])[::-1])
+
formats = []
for stream in media.get('streams', []):
- audio_lang = stream.get('audio_lang')
- hardsub_lang = stream.get('hardsub_lang')
+ audio_lang = stream.get('audio_lang') or ''
+ hardsub_lang = stream.get('hardsub_lang') or ''
+ if (requested_languages and audio_lang.lower() not in requested_languages
+ or requested_hardsubs and hardsub_lang.lower() not in requested_hardsubs):
+ continue
vrv_formats = self._extract_vrv_formats(
stream.get('url'), video_id, stream.get('format'),
audio_lang, hardsub_lang)
for f in vrv_formats:
- f['language_preference'] = 1 if audio_lang == language else 0
- f['quality'] = (
- 1 if not hardsub_lang
- else 0 if hardsub_lang == language
- else -1)
+ f['language_preference'] = language_preference(audio_lang)
+ f['quality'] = hardsub_preference(hardsub_lang)
formats.extend(vrv_formats)
if not formats:
available_fmts = []