Repository: globocom/m3u8

Issue:
handle audio channels
Ref https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-07#page-38

Discussion:

Patch:
diff --git a/m3u8/model.py b/m3u8/model.py
index 01d9428..ed5d90f 100644
--- a/m3u8/model.py
+++ b/m3u8/model.py
@@ -936,6 +936,7 @@ class Media(BasePathMixin):
     `forced`
     `instream_id`
     `characteristics`
+    `channels`
       attributes in the EXT-MEDIA tag
 
     `base_uri`
@@ -944,7 +945,7 @@ class Media(BasePathMixin):
 
     def __init__(self, uri=None, type=None, group_id=None, language=None,
                  name=None, default=None, autoselect=None, forced=None,
-                 characteristics=None, assoc_language=None,
+                 characteristics=None, channels=None, assoc_language=None,
                  instream_id=None, base_uri=None, **extras):
         self.base_uri = base_uri
         self.uri = uri
@@ -958,6 +959,7 @@ class Media(BasePathMixin):
         self.assoc_language = assoc_language
         self.instream_id = instream_id
         self.characteristics = characteristics
+        self.channels = channels
         self.extras = extras
 
     def dumps(self):
@@ -985,6 +987,8 @@ class Media(BasePathMixin):
             media_out.append('INSTREAM-ID=' + quoted(self.instream_id))
         if self.characteristics:
             media_out.append('CHARACTERISTICS=' + quoted(self.characteristics))
+        if self.channels:
+            media_out.append('CHANNELS=' + quoted(self.channels))
 
         return ('#EXT-X-MEDIA:' + ','.join(media_out))
 
diff --git a/m3u8/parser.py b/m3u8/parser.py
index e7b1fe7..606c403 100644
--- a/m3u8/parser.py
+++ b/m3u8/parser.py
@@ -309,7 +309,7 @@ def _parse_i_frame_stream_inf(line, data):
 
 
 def _parse_media(line, data, state):
-    quoted = remove_quotes_parser('uri', 'group_id', 'language', 'assoc_language', 'name', 'instream_id', 'characteristics')
+    quoted = remove_quotes_parser('uri', 'group_id', 'language', 'assoc_language', 'name', 'instream_id', 'characteristics', 'channels')
     media = _parse_attribute_list(protocol.ext_x_media, line, quoted)
     data['media'].append(media)
 


Test patch:
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 7ac425c..7a1daa5 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -336,6 +336,14 @@ def test_should_parse_empty_uri_with_base_path():
     assert 'base_uri/' == media.base_uri
 
 
+def test_should_parse_audio_channels():
+    data = m3u8.M3U8(
+            playlists.MEDIA_WITHOUT_URI_PLAYLIST,
+            base_path='base_path', base_uri='base_uri')
+    media = data.media[0]
+    assert media.channels == "2"
+
+
 def test_should_parse_start_with_negative_time_offset():
     data = m3u8.parse(playlists.SIMPLE_PLAYLIST_WITH_START_NEGATIVE_OFFSET)
     assert data['start']['time_offset'] == -2.0