Skip to content

Commit 0c30397

Browse files
authored
Merge pull request #15 from anxdpanic/dev
add bandwidth to m3u8 regex and return values
2 parents 093c187 + cfdf228 commit 0c30397

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

resources/lib/twitch/parser.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
r'#EXT-X-MEDIA:TYPE=VIDEO.*'
77
r'GROUP-ID="(?P<group_id>[^"]*)",'
88
r'NAME="(?P<group_name>[^"]*)"[,=\w]*\n'
9-
r'#EXT-X-STREAM-INF:.*\n('
9+
r'#EXT-X-STREAM-INF:.*'
10+
r'BANDWIDTH=(?P<bandwidth>[0-9]+).*\n('
1011
r'?P<url>http.*)')
1112

1213
_clip_embed_pattern = re.compile(r'quality_options:\s*(?P<qualities>\[[^\]]+?\])')
@@ -45,11 +46,11 @@ def m3u8_to_list(string):
4546
matches = re.finditer(_m3u_pattern, string)
4647
chunked = None
4748
for m in matches:
48-
l.append((m.group('group_name'), m.group('url')))
49+
l.append((m.group('group_name'), m.group('url'), m.group('bandwidth')))
4950
if m.group('group_id') == 'chunked':
50-
chunked = m.group('url')
51-
if (chunked) and (not any(re.match('[Ss]ource', name) for name, url in l)):
52-
l.insert(0, ('Source', chunked))
51+
chunked = ('Source', m.group('url'), int(m.group('bandwidth')))
52+
if (chunked) and (not any(re.match('[Ss]ource', name) for name, url, bandwidth in l)):
53+
l.insert(0, chunked)
5354

5455
log.debug('m3u8_to_list result:\n{}'.format(l))
5556
return l
@@ -61,8 +62,8 @@ def clip_embed_to_list(string):
6162
l = list()
6263
if match:
6364
match = eval(match.group('qualities'))
64-
l = [(item['quality'], item['source']) for item in match]
65-
l.insert(0, ('Source', l[0][1]))
65+
l = [(item['quality'], item['source'], -1) for item in match]
66+
l.insert(0, ('Source', l[0][1], -1))
6667

6768
log.debug('clip_embed_to_list result:\n{}'.format(l))
6869
return l

0 commit comments

Comments
 (0)