Skip to content

Commit a99ca1c

Browse files
authored
Merge pull request #18 from anxdpanic/dev
return uniform dicts from parser, add icon
2 parents 0c89f65 + c2282c6 commit a99ca1c

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

addon.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="script.module.python.twitch" name="python-twitch for Kodi" version="1.0.0~beta1" provider-name="A Talented Community">
2+
<addon id="script.module.python.twitch" name="python-twitch for Kodi" version="1.0.0~beta2" provider-name="A Talented Community">
33
<requires>
44
<import addon="xbmc.python" version="2.1.0"/>
55
<import addon="script.module.six" version="1.9.0"/>
@@ -13,7 +13,6 @@
1313
</news>
1414
<assets>
1515
<icon>icon.png</icon>
16-
<fanart>fanart.jpg</fanart>
1716
</assets>
1817
<platform>all</platform>
1918
<summary lang="en">Module for interaction with the Twitch.tv API</summary>

icon.png

19.1 KB
Loading

resources/lib/twitch/parser.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,20 @@ def m3u8_to_dict(string):
4343
d = dict()
4444
matches = re.finditer(_m3u_pattern, string)
4545
for m in matches:
46-
d[m.group('group_name')] = m.group('url')
4746
if m.group('group_id') == 'chunked':
48-
d.update({'Source': m.group('url')}) # ensure Source stream identified for consistency
49-
47+
d[m.group('group_id')] = {
48+
'id': m.group('group_id'),
49+
'name': 'Source',
50+
'url': m.group('url'),
51+
'bandwidth': int(m.group('bandwidth'))
52+
}
53+
else:
54+
d[m.group('group_id')] = {
55+
'id': m.group('group_id'),
56+
'name': m.group('group_name'),
57+
'url': m.group('url'),
58+
'bandwidth': int(m.group('bandwidth'))
59+
}
5060
log.debug('m3u8_to_dict result:\n{}'.format(d))
5161
return d
5262

@@ -55,13 +65,21 @@ def m3u8_to_list(string):
5565
log.debug('m3u8_to_list called for:\n{}'.format(string))
5666
l = list()
5767
matches = re.finditer(_m3u_pattern, string)
58-
chunked = None
5968
for m in matches:
60-
l.append((m.group('group_name'), m.group('url'), m.group('bandwidth')))
6169
if m.group('group_id') == 'chunked':
62-
chunked = ('Source', m.group('url'), int(m.group('bandwidth')))
63-
if (chunked) and (not any(re.match('[Ss]ource', name) for name, url, bandwidth in l)):
64-
l.insert(0, chunked)
70+
l.insert(0, {
71+
'id': m.group('group_id'),
72+
'name': 'Source',
73+
'url': m.group('url'),
74+
'bandwidth': int(m.group('bandwidth'))
75+
})
76+
else:
77+
l.append({
78+
'id': m.group('group_id'),
79+
'name': m.group('group_name'),
80+
'url': m.group('url'),
81+
'bandwidth': int(m.group('bandwidth'))
82+
})
6583

6684
log.debug('m3u8_to_list result:\n{}'.format(l))
6785
return l
@@ -73,8 +91,19 @@ def clip_embed_to_list(string):
7391
l = list()
7492
if match:
7593
match = eval(match.group('qualities'))
76-
l = [(item['quality'], item['source'], -1) for item in match]
77-
l.insert(0, ('Source', l[0][1], -1))
94+
l = [{
95+
'id': item['quality'],
96+
'name': item['quality'],
97+
'url': item['source'],
98+
'bandwidth': -1
99+
} for item in match]
100+
if l:
101+
l.insert(0, {
102+
'id': 'Source',
103+
'name': 'Source',
104+
'url': l[0]['url'],
105+
'bandwidth': -1
106+
})
78107

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

0 commit comments

Comments
 (0)