[Python-modules-commits] [python-m3u8] 01/05: Import python-m3u8_0.3.4.orig.tar.gz

Ondrej Koblizek kobla-guest at moszumanska.debian.org
Wed Nov 1 07:32:37 UTC 2017


This is an automated email from the git hooks/post-receive script.

kobla-guest pushed a commit to branch master
in repository python-m3u8.

commit 32f22672841ffbcabc55c96ae22b7343d8dfb9bb
Author: Ondřej Kobližek <koblizeko at gmail.com>
Date:   Wed Nov 1 07:56:28 2017 +0100

    Import python-m3u8_0.3.4.orig.tar.gz
---
 m3u8/mixins.py             | 10 +++++++---
 m3u8/model.py              |  9 +++++++--
 m3u8/parser.py             |  2 +-
 setup.py                   |  2 +-
 tests/playlists.py         | 15 +++++++++++++++
 tests/test_model.py        | 15 ++++++++++++++-
 tests/test_parser.py       | 14 ++++++++++++++
 tests/test_variant_m3u8.py |  5 +++--
 8 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/m3u8/mixins.py b/m3u8/mixins.py
index e2576f5..33f228c 100644
--- a/m3u8/mixins.py
+++ b/m3u8/mixins.py
@@ -30,13 +30,17 @@ class BasePathMixin(object):
 
     @property
     def base_path(self):
+        if self.uri is None:
+            return None
         return os.path.dirname(self.uri)
 
     @base_path.setter
     def base_path(self, newbase_path):
-        if not self.base_path:
-            self.uri = "%s/%s" % (newbase_path, self.uri)
-        self.uri = self.uri.replace(self.base_path, newbase_path)
+        if self.uri is not None:
+            if not self.base_path:
+                self.uri = "%s/%s" % (newbase_path, self.uri)
+            else:
+                self.uri = self.uri.replace(self.base_path, newbase_path)
 
 
 class GroupedBasePathMixin(object):
diff --git a/m3u8/model.py b/m3u8/model.py
index 5ca29d5..0ee22bb 100644
--- a/m3u8/model.py
+++ b/m3u8/model.py
@@ -278,7 +278,8 @@ class M3U8(object):
     def _create_sub_directories(self, filename):
         basename = os.path.dirname(filename)
         try:
-            os.makedirs(basename)
+            if basename:
+                os.makedirs(basename)
         except OSError as error:
             if error.errno != errno.EEXIST:
                 raise
@@ -479,6 +480,7 @@ class Playlist(BasePathMixin):
 
         self.stream_info = StreamInfo(
             bandwidth=stream_info['bandwidth'],
+            closed_captions=stream_info.get('closed_captions'),
             average_bandwidth=stream_info.get('average_bandwidth'),
             program_id=stream_info.get('program_id'),
             resolution=resolution_pair,
@@ -496,6 +498,8 @@ class Playlist(BasePathMixin):
         stream_inf = []
         if self.stream_info.program_id:
             stream_inf.append('PROGRAM-ID=%d' % self.stream_info.program_id)
+        if self.stream_info.closed_captions:
+            stream_inf.append('CLOSED-CAPTIONS=%s' % self.stream_info.closed_captions)
         if self.stream_info.bandwidth:
             stream_inf.append('BANDWIDTH=%d' % self.stream_info.bandwidth)
         if self.stream_info.average_bandwidth:
@@ -547,6 +551,7 @@ class IFramePlaylist(BasePathMixin):
 
         self.iframe_stream_info = StreamInfo(
             bandwidth=iframe_stream_info.get('bandwidth'),
+            closed_captions=iframe_stream_info.get('closed_captions'),
             average_bandwidth=None,
             program_id=iframe_stream_info.get('program_id'),
             resolution=resolution_pair,
@@ -575,7 +580,7 @@ class IFramePlaylist(BasePathMixin):
 
 StreamInfo = namedtuple(
     'StreamInfo',
-    ['bandwidth', 'average_bandwidth', 'program_id', 'resolution', 'codecs']
+    ['bandwidth', 'closed_captions', 'average_bandwidth', 'program_id', 'resolution', 'codecs']
 )
 
 
diff --git a/m3u8/parser.py b/m3u8/parser.py
index f28fd07..a5c8779 100644
--- a/m3u8/parser.py
+++ b/m3u8/parser.py
@@ -174,7 +174,7 @@ def _parse_key(line):
 
 
 def _parse_extinf(line, data, state, lineno, strict):
-    chunks = line.replace(protocol.extinf + ':', '').split(',')
+    chunks = line.replace(protocol.extinf + ':', '').split(',', 1)
     if len(chunks) == 2:
         duration, title = chunks
     elif len(chunks) == 1:
diff --git a/setup.py b/setup.py
index c5fff9c..1dbbdbd 100644
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@ setup(
     name="m3u8",
     author='Globo.com',
     author_email='videos3 at corp.globo.com',
-    version="0.3.3",
+    version="0.3.4",
     license='MIT',
     zip_safe=False,
     include_package_data=True,
diff --git a/tests/playlists.py b/tests/playlists.py
index 8f06a0b..20a4c32 100755
--- a/tests/playlists.py
+++ b/tests/playlists.py
@@ -461,6 +461,14 @@ JUNK
 #EXT-X-ENDLIST
 '''
 
+# The playlist fails if parsed as strict, but otherwise passes
+SIMPLE_PLAYLIST_TITLE_COMMA = '''
+#EXTM3U
+#EXTINF:5220,Title with a comma, end
+http://media.example.com/entire.ts
+#EXT-X-ENDLIST
+'''
+
 # Playlist with EXTINF record not ending with comma
 SIMPLE_PLAYLIST_COMMALESS_EXTINF = '''
 #EXTM3U
@@ -616,6 +624,13 @@ MAP_URI_PLAYLIST_WITH_BYTERANGE = '''#EXTM3U
 #EXT-X-MAP:URI="main.mp4",BYTERANGE="812 at 0"
 '''
 
+MEDIA_WITHOUT_URI_PLAYLIST = '''#EXTM3U
+#EXT-X-VERSION:4
+#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio-aacl-312",NAME="English",LANGUAGE="en",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="2"
+#EXT-X-STREAM-INF:BANDWIDTH=364000,AVERAGE-BANDWIDTH=331000,CODECS="mp4a.40.2",AUDIO="audio-aacl-312",SUBTITLES="textstream"
+ch001-audio_312640_eng=312000.m3u8
+'''
+
 RELATIVE_PLAYLIST_FILENAME = abspath(join(dirname(__file__), 'playlists/relative-playlist.m3u8'))
 
 RELATIVE_PLAYLIST_URI = TEST_HOST + '/path/to/relative-playlist.m3u8'
diff --git a/tests/test_model.py b/tests/test_model.py
index 502144c..4a31009 100755
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -10,7 +10,7 @@ import arrow
 import datetime
 import m3u8
 import playlists
-from m3u8.model import Segment, Key
+from m3u8.model import Segment, Key, Media
 
 
 def test_target_duration_attribute():
@@ -230,10 +230,12 @@ def test_playlists_attribute():
     data = {'playlists': [{'uri': '/url/1.m3u8',
                            'stream_info': {'program_id': 1,
                                            'bandwidth': 320000,
+                                           'closed_captions': None,
                                            'video': 'high'}},
                           {'uri': '/url/2.m3u8',
                            'stream_info': {'program_id': 1,
                                            'bandwidth': 120000,
+                                           'closed_captions': None,
                                            'codecs': 'mp4a.40.5',
                                            'video': 'low'}},
                           ],
@@ -249,6 +251,7 @@ def test_playlists_attribute():
     assert '/url/1.m3u8' == obj.playlists[0].uri
     assert 1 == obj.playlists[0].stream_info.program_id
     assert 320000 == obj.playlists[0].stream_info.bandwidth
+    assert None == obj.playlists[0].stream_info.closed_captions
     assert None == obj.playlists[0].stream_info.codecs
 
     assert None == obj.playlists[0].media[0].uri
@@ -264,6 +267,7 @@ def test_playlists_attribute():
     assert '/url/2.m3u8' == obj.playlists[1].uri
     assert 1 == obj.playlists[1].stream_info.program_id
     assert 120000 == obj.playlists[1].stream_info.bandwidth
+    assert None == obj.playlists[1].stream_info.closed_captions
     assert 'mp4a.40.5' == obj.playlists[1].stream_info.codecs
 
     assert None == obj.playlists[1].media[0].uri
@@ -690,6 +694,15 @@ def test_m3u8_should_propagate_base_uri_to_key():
     assert '/any/key.bin' == obj.keys[0].absolute_uri
 
 
+def test_base_path_with_optional_uri_should_do_nothing():
+    media = Media(type='AUDIO', group_id='audio-group', name='English')
+    assert media.uri is None
+    assert media.base_uri is None
+    media.base_path = "base_path"
+    assert media.absolute_uri is None
+    assert media.base_path is None
+
+
 def test_segment_map_uri_attribute():
     obj = m3u8.M3U8(playlists.MAP_URI_PLAYLIST)
     assert obj.segment_map['uri'] == "fileSequence0.mp4"
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 47676f9..3ac1349 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -20,6 +20,10 @@ def test_should_parse_non_integer_duration_from_playlist_string():
     assert 5220.5 == data['targetduration']
     assert [5220.5] == [c['duration'] for c in data['segments']]
 
+def test_should_parse_comma_in_title():
+    data = m3u8.parse(playlists.SIMPLE_PLAYLIST_TITLE_COMMA)
+    assert ['Title with a comma, end'] == [c['title'] for c in data['segments']]
+
 def test_should_parse_simple_playlist_from_string_with_different_linebreaks():
     data = m3u8.parse(playlists.SIMPLE_PLAYLIST.replace('\n', '\r\n'))
     assert 5220 == data['targetduration']
@@ -261,3 +265,13 @@ def test_should_parse_segment_map_uri():
 def test_should_parse_segment_map_uri_with_byterange():
     data = m3u8.parse(playlists.MAP_URI_PLAYLIST_WITH_BYTERANGE)
     assert data['segment_map']['uri'] == "main.mp4"
+
+
+def test_should_parse_empty_uri_with_base_path():
+    data = m3u8.M3U8(
+            playlists.MEDIA_WITHOUT_URI_PLAYLIST,
+            base_path='base_path', base_uri='base_uri')
+    media = data.media[0]
+    assert media.uri is None
+    assert media.base_path is None
+    assert 'base_uri/' == media.base_uri
diff --git a/tests/test_variant_m3u8.py b/tests/test_variant_m3u8.py
index e1f160e..d05a18c 100644
--- a/tests/test_variant_m3u8.py
+++ b/tests/test_variant_m3u8.py
@@ -12,7 +12,7 @@ def test_create_a_variant_m3u8_with_two_playlists():
                            'English', 'YES', 'YES', 'NO', None)
     variant_m3u8.add_media(subtitles)
 
-    low_playlist = m3u8.Playlist('http://example.com/low.m3u8', stream_info={'bandwidth': 1280000, 'program_id': 1, 'subtitles': 'subs'}, media=[subtitles], base_uri=None)
+    low_playlist = m3u8.Playlist('http://example.com/low.m3u8', stream_info={'bandwidth': 1280000, 'program_id': 1, 'closed_captions': 'NONE', 'subtitles': 'subs'}, media=[subtitles], base_uri=None)
     high_playlist = m3u8.Playlist('http://example.com/high.m3u8', stream_info={'bandwidth': 3000000, 'program_id': 1, 'subtitles': 'subs'}, media=[subtitles], base_uri=None)
 
     variant_m3u8.add_playlist(low_playlist)
@@ -21,7 +21,7 @@ def test_create_a_variant_m3u8_with_two_playlists():
     expected_content = """\
 #EXTM3U
 #EXT-X-MEDIA:URI="english_sub.m3u8",TYPE=SUBTITLES,GROUP-ID="subs",LANGUAGE="en",NAME="English",DEFAULT=YES,AUTOSELECT=YES,FORCED=NO
-#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1280000,SUBTITLES="subs"
+#EXT-X-STREAM-INF:PROGRAM-ID=1,CLOSED-CAPTIONS=NONE,BANDWIDTH=1280000,SUBTITLES="subs"
 http://example.com/low.m3u8
 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=3000000,SUBTITLES="subs"
 http://example.com/high.m3u8
@@ -58,6 +58,7 @@ def test_create_a_variant_m3u8_with_two_playlists_and_two_iframe_playlists():
         uri='video-800k-iframes.m3u8',
         iframe_stream_info={'bandwidth': 151288,
                             'program_id': 1,
+                            'closed_captions': None,
                             'resolution': '624x352',
                             'codecs': 'avc1.4d001f'},
         base_uri='http://example.com/'

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-m3u8.git



More information about the Python-modules-commits mailing list