Skip to content

Commit

Permalink
Fix base path when query string has slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioabreu committed Aug 6, 2020
1 parent b28f143 commit 3bb55c6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
6 changes: 5 additions & 1 deletion m3u8/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def absolute_uri(self):
def base_path(self):
if self.uri is None:
return None
return os.path.dirname(self.uri)
return os.path.dirname(self.get_path_from_uri())

def get_path_from_uri(self):
"""Some URIs have a slash in the query string."""
return self.uri.split("?")[0]

@base_path.setter
def base_path(self, newbase_path):
Expand Down
15 changes: 15 additions & 0 deletions tests/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,4 +1045,19 @@
#EXT-X-PART:DURATION=1,URI="filePart271.c.ts"
'''

PLAYLIST_WITH_SLASH_IN_QUERY_STRING = '''
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:5
#EXT-X-MEDIA-SEQUENCE:10599
#EXT-X-PROGRAM-DATE-TIME:2020-08-05T13:51:49.000+00:00
#EXTINF:5.0000,
testvideo-1596635509-4769390994-a0e3087c.ts?hdntl=exp=1596678764~acl=/*~data=hdntl~hmac=12345&
#EXTINF:5.0000,
testvideo-1596635514-4769840994-a0e00878.ts?hdntl=exp=1596678764~acl=/*~data=hdntl~hmac=12345&
#EXTINF:5.0000,
testvideo-1596635519-4770290994-a0e5087d.ts?hdntl=exp=1596678764~acl=/*~data=hdntl~hmac=12345&
#EXTINF:5.0000,
'''

del abspath, dirname, join
7 changes: 7 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def dst(self, dt):
utc = UTC()


def test_base_path_playlist_with_slash_in_query_string():
playlist = m3u8.M3U8(
playlists.PLAYLIST_WITH_SLASH_IN_QUERY_STRING,
base_path='http://testvideo.com/foo'
)
assert playlist.segments[0].uri == 'http://testvideo.com/foo/testvideo-1596635509-4769390994-a0e3087c.ts?hdntl=exp=1596678764~acl=/*~data=hdntl~hmac=12345&'

def test_target_duration_attribute():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST)
mock_parser_data(obj, {'targetduration': '1234567'})
Expand Down
2 changes: 0 additions & 2 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,6 @@ def test_gap():
def test_gap_in_parts():
data = m3u8.parse(playlists.GAP_IN_PARTS_PLAYLIST)

print(data['segments'][0]['parts'])

assert data['segments'][0]['parts'][0]['gap_tag'] is None
assert data['segments'][0]['parts'][0].get('gap', None) is None
assert data['segments'][0]['parts'][1]['gap_tag'] is None
Expand Down

0 comments on commit 3bb55c6

Please sign in to comment.