Skip to content

stream.hls: also compare parsed language selection #6469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 15, 2025

Conversation

bastimeyer
Copy link
Member

See #6467 (comment)

This allows selecting HLS audio streams without having to know the exact value of the LANGUAGE attribute of the respective EXT-X-MEDIA tag. Previously, this was even case-sensitive, which language codes definitely are not.

Instead of only comparing plain values, parse the user's input (test all language attributes: alpha_2, alpha_3, name and bibliographic) and also parse the language data of the media playlists in the HLS multivariant playlist (test all language attributes as well), and then do the comparisons on the resulting Language objects when selecting audio streams. Keep plain value language code comparision, to support selecting audio streams with invalid language codes or languages with reserved codes (qaa-qtz).

The last two commits are simple performance improvements.


So for example, --hls-audio-select=ger now allows users to select audio streams which are annotated with the alpha_3 code deu (regardless of case), as ger is the bilbiographic attribute of German/Deutsch. Likewise, --hls-audio-select=German would also work, as the language's name attribute is also taken into consideration. pycountry does not have any data for localized language names, --hls-audio-select=Deutsch won't work.


Since the implementation of the external audio stream selection is still pretty bad (#4902), we should at least improve the logging of the available substreams, as there's no indication of what is available unless low logging levels are set. This is for a future PR though...

Parse the language of `EXT-X-MEDIA` tags and parse the languages
of the user's `hls-audio-select` values.

Compare both plain language codes and the parsed languages when
selecting the audio streams, so users are able to select audio streams
1. without having to know the specific ISO 639-2 language codes:
   Languages are looked up by the `alpha_2`, `alpha_3`, `name`
   and `bibliographic` attributes on the HLS playlist and user input.
   This means that for example `--hls-audio-select=German` will match
   German audio streams with `LANGUAGE="deu"`.
2. with language codes that are invalid or reserved for private use:
   Valid language codes are not guaranteed, so plain string comparisons
   are still needed, just like before. `pycountry` also rejects codes
   reserved for private use, so we need to handle this case as well.
Use the cached value of the parsed language of the media playlist
when comparing it with the user's locale configuration.
@bastimeyer bastimeyer force-pushed the stream/hls/select-audio branch from 92713e2 to d32af02 Compare March 12, 2025 23:57
@bastimeyer bastimeyer merged commit 1b8036b into streamlink:master Mar 15, 2025
16 checks passed
@bastimeyer bastimeyer deleted the stream/hls/select-audio branch March 15, 2025 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants