forked from micahg/plugin.video.snnow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.py
More file actions
161 lines (126 loc) · 5.19 KB
/
default.py
File metadata and controls
161 lines (126 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import snnow
import xbmc, xbmcplugin, xbmcgui, xbmcaddon, os, urllib, urlparse
__settings__ = xbmcaddon.Addon(id='plugin.video.snnow')
__language__ = __settings__.getLocalizedString
def getAuthCredentials():
username = __settings__.getSetting("username")
if len(username) == 0:
dialog = xbmcgui.Dialog()
dialog.ok(__language__(30000), __language__(30001))
xbmcplugin.endOfDirectory(handle = int(sys.argv[1]),
succeeded=False)
return None
# get the password
password = __settings__.getSetting("password")
if len(password) == 0:
dialog = xbmcgui.Dialog()
dialog.ok(__language__(30002), __language__(30003))
xbmcplugin.endOfDirectory(handle = int(sys.argv[1]),
succeeded=False)
return None
mso = __settings__.getSetting("mso")
return { 'u' : username, 'p' : password, 'm' : mso }
def createMainMenu():
"""
Create the main menu
"""
sn = snnow.SportsnetNow()
creds = getAuthCredentials()
if creds == None:
xbmcplugin.endOfDirectory(int(sys.argv[1]))
return
sn.checkMSOs()
if not sn.authorize(creds['u'], creds['p'], creds['m']):
dialog = xbmcgui.Dialog()
dialog.ok(__language__(30004), __language__(30004))
xbmcplugin.endOfDirectory(handle = int(sys.argv[1]),
succeeded=False)
channels = sn.getChannels()
guide = sn.getGuideData()
for channel in channels:
chanId = str(channel['id'])
values = { 'menu' : 'channel', 'name' : channel['name'],
'id' : channel['id'], 'abbr' : channel['abbr'] }
title = values['name']
showTitle = channel['name']
if chanId in guide.keys():
prog = guide[chanId]
for key in prog.keys():
values[key] = prog[key].encode('utf-8')
if prog['tvshowtitle']:
title += ' ([B]' + prog['tvshowtitle'] + '[/B]'
if prog['title']:
title += ' - [I]' + prog['title'] + '[/I]'
title += ')'
showTitle = prog['tvshowtitle']
live = xbmcgui.ListItem(title)
labels = {"TVShowTitle" : showTitle,
"Studio" : channel['name']}
if 'title' in values:
labels['Title'] = prog['title']
if 'plot' in values:
labels["Plot"] = prog['plot']
live.setInfo(type="Video", infoLabels=labels)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
url=sys.argv[0] + "?" + urllib.urlencode(values),
listitem=live,
isFolder=True)
# signal the end of the directory
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def createLiveMenu(values):
pid = values['provider'][0]
pf = providerfactory.ProviderFactory()
provider = pf.getProviders()[pid]
channels = provider.getChannels()
for channel in channels:
values = { 'menu' : 'channel', 'provider' : pid,
'name' : channel['name'], 'id' : channel['id'],
'abbr' : channel['abbr'] }
live = xbmcgui.ListItem(values['name'])
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
url=sys.argv[0] + "?" + urllib.urlencode(values),
listitem=live,
isFolder=False)
# signal the end of the directory
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def playChannel(values):
mso = __settings__.getSetting("mso")
stream = getChannelStream(values['id'][0], values['abbr'][0], mso)
if not stream:
dialog = xbmcgui.Dialog()
dialog.ok(__language__(30004), __language__(30005))
else:
name = values['name'][0]
li = xbmcgui.ListItem(name)
labels = {"TVShowTitle" : values['tvshowtitle'][0],
"Studio" : values['name'][0]}
if 'title' in values:
labels['Title'] = values['title'][0]
if 'plotoutline' in values:
labels["Plot"] = values['plot'][0]
li.setInfo(type="Video", infoLabels=labels)
p = xbmc.Player()
p.play(stream, li)
def getChannelStream(channelId, channelName, msoName):
sn = snnow.SportsnetNow()
stream = sn.getChannel(channelId, channelName, msoName)
if not stream:
# auth token may have expired - attempt re-auth first
print('Auth token may have expired. Attempting re-auth.')
creds = getAuthCredentials()
if sn.authorize(creds['u'], creds['p'], creds['m']):
return sn.getChannel(channelId, channelName, msoName)
return stream
if len(sys.argv[2]) == 0:
# create the data folder if it doesn't exist
data_path = xbmc.translatePath(xbmcaddon.Addon().getAddonInfo('profile'))
if not os.path.exists(data_path):
os.makedirs(data_path)
# show the main menu
createMainMenu()
else:
values = urlparse.parse_qs(sys.argv[2][1:])
if values['menu'][0] == 'live':
createLiveMenu(values)
elif values['menu'][0] == 'channel':
playChannel(values)