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.
Projectglobocom/m3u8
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
| 16 | 16 | ''' | |
| 17 | 17 | data = {'chunks': []} | |
| 18 | 18 | next_chuck_duration = None | |
| 19 | + | next_chunk_title = None | |
| 19 | 20 | ||
| 20 | 21 | for line in string_to_lines(content): | |
| 21 | 22 | ||
| 22 | 23 | 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) | |
| 24 | 25 | next_chuck_duration = None | |
| 26 | + | next_chunk_title = None | |
| 25 | 27 | ||
| 26 | 28 | elif line.startswith(ext_x_targetduration): | |
| 27 | 29 | _parse_targetduration(line, data) | |
| ⋯ | |||
| 33 | 35 | _parse_key(line, data) | |
| 34 | 36 | ||
| 35 | 37 | elif line.startswith(extinf): | |
| 36 | - | next_chuck_duration = _parse_duration(line) | |
| 38 | + | next_chuck_duration, next_chunk_title = _parse_duration_and_title(line) | |
| 37 | 39 | ||
| 38 | 40 | return data | |
| 39 | 41 | ||
| ⋯ | |||
| 53 | 55 | name, value = param.split('=', 1) | |
| 54 | 56 | data['key'][name.lower()] = remove_quotes(value) | |
| 55 | 57 | ||
| 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) | |
| 58 | 61 | ||
| 59 | - | def _parse_ts_chuck(line, data, duration=None): | |
| 62 | + | def _parse_ts_chuck(line, data, duration=None, title=None): | |
| 60 | 63 | data['chunks'].append({'duration': duration, | |
| 61 | - | 'uri': line}) | |
| 64 | + | 'uri': line, | |
| 65 | + | 'title': title}) | |
| 62 | 66 | ||
| 63 | 67 | def string_to_lines(string): | |
| 64 | 68 | return string.strip().split('\n') | |
| ⋯ | |||
| 74 | 78 | ||
| 75 | 79 | ''' | |
| 76 | 80 | 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: | |
| 78 | 82 | return string[1:-1] | |
| 79 | 83 | return string | |
| 80 | 84 | ||
The check that tells the two apart
fail→pass·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.