Repository: streamlink/streamlink

Issue:
Question about multi audio streams (hls live streams)
### Checklist

- [ ] This is a bug report.
- [ ] This is a plugin request.
- [x] This is a feature request.
- [x] I used the search function to find already opened/closed issues or pull requests.

### Description

When i try to play a live stream with more than one audio stream, i can't.

This issue is exactly what i need #485 

In my case, the english audio stream is named "qaa" and the french one "fra"

However i can play separately the "qaa" and "qad" audio streams.

Thanks

### Expected / Actual behavior

Playing any audio stream when it is possible.

### Reproduction steps / Stream URLs to test

```
#EXTM3U
#EXT-X-VERSION:4
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",LANGUAGE="fra",NAME="fra",AUTOSELECT=YES,DEFAULT=YES
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",LANGUAGE="qaa",NAME="qaa",AUTOSELECT=NO,DEFAULT=NO,URI="http://ncdn-sr.adam.sfr.fr/iphone/tf1_audio_qaa/tf1.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",LANGUAGE="qad",NAME="qad",AUTOSELECT=NO,DEFAULT=NO,URI="http://ncdn-sr.adam.sfr.fr/iphone/tf1_audio_qad/tf1.m3u8"
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=364050,RESOLUTION=320x180,CODECS="mp4a.40.5,avc1.42c01e",AUDIO="audio"
http://ncdn-sr.adam.sfr.fr/iphone/tf1_299968/tf1.m3u8
```

### Environment details (operating system, python version, etc.)

Python 2.7 on Debian 8

### Comments, logs, screenshots, etc.


Discussion:

Resolving patch:
diff --git a/src/streamlink/stream/hls.py b/src/streamlink/stream/hls.py
--- a/src/streamlink/stream/hls.py
+++ b/src/streamlink/stream/hls.py
@@ -289,6 +289,7 @@ def parse_variant_playlist(cls, session_, url, name_key="name",
         # Backwards compatibility with "namekey" and "nameprefix" params.
         name_key = request_params.pop("namekey", name_key)
         name_prefix = request_params.pop("nameprefix", name_prefix)
+        audio_select = session_.options.get("hls-audio-select")
 
         res = session_.http.get(url, exception=IOError, **request_params)
 
@@ -321,8 +322,10 @@ def parse_variant_playlist(cls, session_, url, name_key="name",
                     default_audio = media
 
                 # select the first audio stream that matches the users explict language selection
-                if (not preferred_audio or media.default) and locale.explicit and locale.equivalent(
-                        language=media.language):
+                if ((media.language == audio_select or media.name == audio_select) or
+                    ((not preferred_audio or media.default) and
+                        locale.explicit and
+                        locale.equivalent(language=media.language))):
                     preferred_audio = media
 
             # final fallback on the first audio stream listed
diff --git a/src/streamlink_cli/argparser.py b/src/streamlink_cli/argparser.py
--- a/src/streamlink_cli/argparser.py
+++ b/src/streamlink_cli/argparser.py
@@ -652,6 +652,15 @@ def boolean(value):
 
     Default is 60.0.
     """)
+transport.add_argument(
+    "--hls-audio-select",
+    type=str,
+    metavar="CODE",
+    help="""
+    Selects a specific audio source, by language code, when multiple audio sources are available.
+
+    Note: This is only useful in special circumstances where the regular locale option fails.
+    """)
 transport.add_argument(
     "--http-stream-timeout",
     type=num(float, min=0),
diff --git a/src/streamlink_cli/main.py b/src/streamlink_cli/main.py
--- a/src/streamlink_cli/main.py
+++ b/src/streamlink_cli/main.py
@@ -718,6 +718,9 @@ def setup_options():
     if args.hls_timeout:
         streamlink.set_option("hls-timeout", args.hls_timeout)
 
+    if args.hls_audio_select:
+        streamlink.set_option("hls-audio-select", args.hls_audio_select)
+
     if args.hds_live_edge:
         streamlink.set_option("hds-live-edge", args.hds_live_edge)
 


Test patch: