Skip to content

Commit 4f87ee7

Browse files
authored
Merge pull request #5 from anxdpanic/dev-v5
m3u8 return list of quality, url tuples instead of dict
2 parents 03a734d + 378f375 commit 4f87ee7

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

resources/lib/twitch/parser.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
def m3u8(f):
1515
def m3u8_wrapper(*args, **kwargs):
16-
return m3u8_to_dict(f(*args, **kwargs))
16+
return m3u8_to_list(f(*args, **kwargs))
1717
return m3u8_wrapper
1818

1919

@@ -28,3 +28,19 @@ def m3u8_to_dict(string):
2828

2929
log.debug('m3u8_to_dict result:\n{}'.format(d))
3030
return d
31+
32+
33+
def m3u8_to_list(string):
34+
log.debug('m3u8_to_list called for:\n{}'.format(string))
35+
l = list()
36+
matches = re.finditer(_m3u_pattern, string)
37+
chunked = None
38+
for m in matches:
39+
l.append((m.group('group_name'), m.group('url')))
40+
if m.group('group_id') == 'chunked':
41+
chunked = m.group('url')
42+
if (chunked) and (not any(re.match('[Ss]ource', name) for name, url in l)):
43+
l.insert(0, ('Source', chunked))
44+
45+
log.debug('m3u8_to_list result:\n{}'.format(l))
46+
return l

0 commit comments

Comments
 (0)