Whole file

globocom/m3u8

The author described this change as Fix #2: parsing chunk title. It counts as a record because the check below fails on the code as it stood at b4ce785d7 and passes on 36437d369, with nothing else changed between the two runs.

Fix saved2012-05-02
Sharing licenceMIT · LICENSE
Change size+11 7

What the code was meant to do, written into the code itself as a save note

Fix #2: parsing chunk title

The change

1616 '''
1717 data = {'chunks': []}
1818 next_chuck_duration = None
19+ next_chunk_title = None
1920
2021 for line in string_to_lines(content):
2122
2223 if next_chuck_duration:
23- _parse_ts_chuck(line, data, next_chuck_duration)
24+ _parse_ts_chuck(line, data, next_chuck_duration, next_chunk_title)
2425 next_chuck_duration = None
26+ next_chunk_title = None
2527
2628 elif line.startswith(ext_x_targetduration):
2729 _parse_targetduration(line, data)
3335 _parse_key(line, data)
3436
3537 elif line.startswith(extinf):
36- next_chuck_duration = _parse_duration(line)
38+ next_chuck_duration, next_chunk_title = _parse_duration_and_title(line)
3739
3840 return data
3941
5355 name, value = param.split('=', 1)
5456 data['key'][name.lower()] = remove_quotes(value)
5557
56-def _parse_duration(line):
57- return int(line.replace(extinf + ':', '').split(',')[0])
58+def _parse_duration_and_title(line):
59+ duration, title = line.replace(extinf + ':', '').split(',')
60+ return int(duration), remove_quotes(title)
5861
59-def _parse_ts_chuck(line, data, duration=None):
62+def _parse_ts_chuck(line, data, duration=None, title=None):
6063 data['chunks'].append({'duration': duration,
61- 'uri': line})
64+ 'uri': line,
65+ 'title': title})
6266
6367 def string_to_lines(string):
6468 return string.strip().split('\n')
7478
7579 '''
7680 quotes = ('"', "'")
77- if string[0] in quotes and string[-1] in quotes:
81+ if string and string[0] in quotes and string[-1] in quotes:
7882 return string[1:-1]
7983 return string
8084

The check that tells the two apart

failpass·tests/test_parser.py::test_should_parse_title_from_playlist

Check file tests/test_parser.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itb4ce785d7fad1b96ebcf32a4b7fa6ddded9f1049
Broken version dated2012-05-02
Modulem3u8.parser
Units changed_parse_ts_chuck, parse, remove_quotes
Fingerprint857f697b61112175
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.