Skip to content

Commit

Permalink
Merge pull request globocom#84 from bertothunder/master
Browse files Browse the repository at this point in the history
Fixed ugly broken lines from autopep8
  • Loading branch information
leandromoreira committed Oct 4, 2016
2 parents a21bfd9 + 7bc4bf2 commit bbc2dd3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 33 deletions.
28 changes: 9 additions & 19 deletions m3u8/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ def format_date_time(value):
return value.isoformat()


def get_empty_key():
return {'method': None, 'uri': None, 'iv': None, 'keyformat': None, 'keyformatversions': None, }


class ParseError(Exception):

Expand All @@ -38,6 +35,7 @@ def __str__(self):
return 'Syntax error in manifest on line %d: %s' % (self.lineno, self.line)



def parse(content, strict=False):
'''
Given a M3U8 playlist content returns a dictionary with all data found
Expand Down Expand Up @@ -78,8 +76,7 @@ def parse(content, strict=False):
_parse_simple_parameter(line, data, int)

elif line.startswith(protocol.ext_x_program_date_time):
_, program_date_time = _parse_simple_parameter_raw_value(
line, cast_date_time)
_, program_date_time = _parse_simple_parameter_raw_value(line, cast_date_time)
if not data.get('program_date_time'):
data['program_date_time'] = program_date_time
state['current_program_date_time'] = program_date_time
Expand All @@ -93,8 +90,7 @@ def parse(content, strict=False):
state['cue_start'] = True

elif line.startswith(protocol.ext_x_cue_out_start):
_parse_cueout_start(
line, state, string_to_lines(content)[lineno - 2])
_parse_cueout_start(line, state, string_to_lines(content)[lineno - 2])
state['cue_out'] = True
state['cue_start'] = True

Expand Down Expand Up @@ -159,8 +155,7 @@ def parse(content, strict=False):


def _parse_key(line):
params = ATTRIBUTELISTPATTERN.split(
line.replace(protocol.ext_x_key + ':', ''))[1::2]
params = ATTRIBUTELISTPATTERN.split(line.replace(protocol.ext_x_key + ':', ''))[1::2]
key = {}
for param in params:
name, value = param.split('=', 1)
Expand Down Expand Up @@ -223,30 +218,26 @@ def _parse_attribute_list(prefix, line, atribute_parser):
def _parse_stream_inf(line, data, state):
data['is_variant'] = True
data['media_sequence'] = None
atribute_parser = remove_quotes_parser(
'codecs', 'audio', 'video', 'subtitles')
atribute_parser = remove_quotes_parser('codecs', 'audio', 'video', 'subtitles')
atribute_parser["program_id"] = int
atribute_parser["bandwidth"] = int
atribute_parser["average_bandwidth"] = int
state['stream_info'] = _parse_attribute_list(
protocol.ext_x_stream_inf, line, atribute_parser)
state['stream_info'] = _parse_attribute_list(protocol.ext_x_stream_inf, line, atribute_parser)


def _parse_i_frame_stream_inf(line, data):
atribute_parser = remove_quotes_parser('codecs', 'uri')
atribute_parser["program_id"] = int
atribute_parser["bandwidth"] = int
iframe_stream_info = _parse_attribute_list(
protocol.ext_x_i_frame_stream_inf, line, atribute_parser)
iframe_stream_info = _parse_attribute_list(protocol.ext_x_i_frame_stream_inf, line, atribute_parser)
iframe_playlist = {'uri': iframe_stream_info.pop('uri'),
'iframe_stream_info': iframe_stream_info}

data['iframe_playlists'].append(iframe_playlist)


def _parse_media(line, data, state):
quoted = remove_quotes_parser(
'uri', 'group_id', 'language', 'name', 'characteristics')
quoted = remove_quotes_parser('uri', 'group_id', 'language', 'name', 'characteristics')
media = _parse_attribute_list(protocol.ext_x_media, line, quoted)
data['media'].append(media)

Expand All @@ -261,8 +252,7 @@ def _parse_variant_playlist(line, data, state):
def _parse_byterange(line, state):
if 'segment' not in state:
state['segment'] = {}
state['segment']['byterange'] = line.replace(
protocol.ext_x_byterange + ':', '')
state['segment']['byterange'] = line.replace(protocol.ext_x_byterange + ':', '')


def _parse_simple_parameter_raw_value(line, cast_to=str, normalize=False):
Expand Down
6 changes: 2 additions & 4 deletions tests/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,11 @@
448/chunklist_w370587926_b688000_vo_slen_t64TWFpbg==.m3u8
'''

RELATIVE_PLAYLIST_FILENAME = abspath(
join(dirname(__file__), 'playlists/relative-playlist.m3u8'))
RELATIVE_PLAYLIST_FILENAME = abspath(join(dirname(__file__), 'playlists/relative-playlist.m3u8'))

RELATIVE_PLAYLIST_URI = TEST_HOST + '/path/to/relative-playlist.m3u8'

CUE_OUT_PLAYLIST_FILENAME = abspath(
join(dirname(__file__), 'playlists/cue_out.m3u8'))
CUE_OUT_PLAYLIST_FILENAME = abspath(join(dirname(__file__), 'playlists/cue_out.m3u8'))

CUE_OUT_PLAYLIST_URI = TEST_HOST + '/path/to/cue_out.m3u8'

Expand Down
9 changes: 3 additions & 6 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def test_load_should_create_object_from_file_with_relative_segments():
expected_ts1_path = '/entire1.ts'
expected_ts2_abspath = '%s/entire2.ts' % os.path.dirname(base_uri)
expected_ts2_path = '../entire2.ts'
expected_ts3_abspath = '%s/entire3.ts' % os.path.dirname(
os.path.dirname(base_uri))
expected_ts3_abspath = '%s/entire3.ts' % os.path.dirname(os.path.dirname(base_uri))
expected_ts3_path = '../../entire3.ts'
expected_ts4_abspath = '%s/entire4.ts' % base_uri
expected_ts4_path = 'entire4.ts'
Expand All @@ -77,11 +76,9 @@ def test_load_should_create_object_from_uri_with_relative_segments():
expected_key_path = '../key.bin'
expected_ts1_abspath = '%s/entire1.ts' % (prefix)
expected_ts1_path = '/entire1.ts'
expected_ts2_abspath = '%s%sentire2.ts' % (
prefix, os.path.normpath(base_uri + '/..') + '/')
expected_ts2_abspath = '%s%sentire2.ts' % (prefix, os.path.normpath(base_uri + '/..') + '/')
expected_ts2_path = '../entire2.ts'
expected_ts3_abspath = '%s%sentire3.ts' % (
prefix, os.path.normpath(base_uri + '/../..'))
expected_ts3_abspath = '%s%sentire3.ts' % (prefix, os.path.normpath(base_uri + '/../..'))
expected_ts3_path = '../../entire3.ts'
expected_ts4_abspath = '%s%sentire4.ts' % (prefix, base_uri + '/')
expected_ts4_path = 'entire4.ts'
Expand Down
6 changes: 2 additions & 4 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def test_media_sequence_attribute():
def test_program_date_time_attribute():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST_WITH_PROGRAM_DATE_TIME)

assert arrow.get(
'2014-08-13T13:36:33+00:00').datetime == obj.program_date_time
assert arrow.get('2014-08-13T13:36:33+00:00').datetime == obj.program_date_time


def test_program_date_time_attribute_for_each_segment():
Expand Down Expand Up @@ -182,8 +181,7 @@ def test_segments_attribute_with_byterange():


def test_segment_attribute_with_multiple_keys():
obj = m3u8.M3U8(
playlists.PLAYLIST_WITH_ENCRIPTED_SEGMENTS_AND_IV_WITH_MULTIPLE_KEYS)
obj = m3u8.M3U8(playlists.PLAYLIST_WITH_ENCRIPTED_SEGMENTS_AND_IV_WITH_MULTIPLE_KEYS)

segments = obj.segments
assert segments[0].key.uri == '/hls-key/key.bin'
Expand Down

0 comments on commit bbc2dd3

Please sign in to comment.