Skip to content

Commit

Permalink
Fix bug in attribute parsing. accept float EXTINF
Browse files Browse the repository at this point in the history
CODEC may contain comma in quoted string like below
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=271610,CODECS="mp4a.40.2,avc1.42801e"

EXTINF duration could be integer or fixed point float.
ref: http://tools.ietf.org/html/draft-pantos-http-live-streaming-08#section-3.3.2
  • Loading branch information
feuvan committed Sep 2, 2012
1 parent 4a870ba commit 05e3471
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions m3u8/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
ext_x_allow_cache = '#EXT-X-ALLOW-CACHE'
extinf = '#EXTINF'

'''
http://tools.ietf.org/html/draft-pantos-http-live-streaming-08#section-3.2
http://stackoverflow.com/questions/2785755/how-to-split-but-ignore-separators-in-quoted-strings-in-python
'''
ATTRIBUTELISTPATTERN = re.compile(r'''((?:[^,"']|"[^"]*"|'[^']*')+)''')

def parse(content):
'''
Expand Down Expand Up @@ -63,23 +68,23 @@ def parse(content):
return data

def _parse_key(line, data):
params = line.replace(ext_x_key + ':', '').split(',')
params = ATTRIBUTELISTPATTERN.split(line.replace(ext_x_key + ':', ''))[1::2]
data['key'] = {}
for param in params:
name, value = param.split('=', 1)
data['key'][normalize_attribute(name)] = remove_quotes(value)

def _parse_extinf(line, data, state):
duration, title = line.replace(extinf + ':', '').split(',')
state['segment'] = {'duration': int(duration), 'title': remove_quotes(title)}
state['segment'] = {'duration': float(duration), 'title': remove_quotes(title)}

def _parse_ts_chunk(line, data, state):
segment = state.pop('segment')
segment['uri'] = line
data['segments'].append(segment)

def _parse_stream_inf(line, data, state):
params = line.replace(ext_x_stream_inf + ':', '').split(',')
params = ATTRIBUTELISTPATTERN.split(line.replace(ext_x_stream_inf + ':', ''))[1::2]

stream_info = {}
for param in params:
Expand Down

0 comments on commit 05e3471

Please sign in to comment.