This repository has been archived by the owner on Jan 20, 2018. It is now read-only.
forked from Hiltronix/plugin.video.sickrage
/
default.py
227 lines (192 loc) · 7.36 KB
/
default.py
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import os
import sys
import urllib
import xbmc
import xbmcgui
import xbmcplugin
import xbmcaddon
import resources.lib.common as common
import resources.lib.settings as settings
import resources.lib.sickbeard as sickbeard
my_addon = xbmcaddon.Addon('plugin.video.sickrage')
# Initialize Sickbeard Class
Sickbeard = sickbeard.SB()
# Add the main directory folders.
def mainMenu():
addDirectory('Upcoming Episodes', 2, True, my_addon.getAddonInfo('path')+'/upcoming.png', my_addon.getAddonInfo('path')+'/resources/images/upcoming_thn.png')
addDirectory('History', 3, True, my_addon.getAddonInfo('path')+'/history.png', my_addon.getAddonInfo('path')+'/resources/images/history_thn.png')
if (settings.__servertype__ == "SickRage"):
addDirectory('Backlog', 9, True, my_addon.getAddonInfo('path')+'/backlog.png', my_addon.getAddonInfo('path')+'/resources/images/backlog_thn.png')
addDirectory('Show List', 1, True, my_addon.getAddonInfo('path')+'/manage.png', my_addon.getAddonInfo('path')+'/resources/images/manage_thn.png')
addDirectory('Add New Show', 7, False, my_addon.getAddonInfo('path')+'/add.png', my_addon.getAddonInfo('path')+'/resources/images/add_thn.png')
if (settings.__show_log__ == "true"):
addDirectory('View Log File', 11, False, my_addon.getAddonInfo('path')+'/log.png', my_addon.getAddonInfo('path')+'/resources/images/log_thn.png')
if (settings.__show_clearcache__ == "true"):
addDirectory('Clear Image Cache', 12, False, my_addon.getAddonInfo('path')+'/settings.png', my_addon.getAddonInfo('path')+'/resources/images/settings_thn.png')
# Add directory item.
def addDirectory(menu_item_name, menu_number, folder, icon, thumbnail):
return_url = sys.argv[0]+"?url="+urllib.quote_plus("")+"&mode="+str(menu_number)+"&name="+urllib.quote_plus(menu_item_name)
list_item = xbmcgui.ListItem(menu_item_name, iconImage=thumbnail, thumbnailImage=icon)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=return_url, listitem=list_item, isFolder=folder, totalItems=7)
# Get the parameters from the URL supplied as an arg to this script.
def getParameters():
param=[]
try:
paramstring=sys.argv[2]
if len(paramstring)>=2:
params=sys.argv[2]
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&')
param={}
for i in range(len(pairsofparams)):
splitparams={}
splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2:
param[splitparams[0]]=splitparams[1]
return param
except:
return param
# Initialize URL parameters.
url = None
name = None
menu_number = None
action = None
show_name = None
tvdb_id = None
params = getParameters()
# Parse internal URL.
try:
url = urllib.unquote_plus(params["url"])
print url
except:
pass
try:
name = urllib.unquote_plus(params["name"])
print name
except:
pass
try:
number = urllib.unquote_plus(params["number"])
print number
except:
pass
try:
menu_number = int(params["mode"])
print menu_number
except:
pass
try:
show_name = urllib.unquote_plus(params["title"])
menu_number = 7
print show_name
except:
pass
try:
action = urllib.unquote_plus(params["action"])
menu_number = 8
print action
except:
pass
try:
show_name = urllib.unquote_plus(params["show_name"]).decode('utf-8')
print show_name
except:
pass
try:
tvdb_id = urllib.unquote_plus(params["tvdb_id"])
print tvdb_id
except:
pass
# Open directories based on selection.
if menu_number == None:
mainMenu()
elif menu_number == 1:
import resources.lib.shows as shows
dialog = xbmcgui.Dialog()
ret = dialog.select('Show List', ['All', 'Continuing', 'Ended', 'Paused', 'Exit'])
if (ret == -1) or (ret == 4):
mainMenu()
if ret == 0:
shows.menu()
if ret == 1:
shows.menu('Continuing')
if ret == 2:
shows.menu('Ended')
if ret == 3:
shows.menu('Paused')
elif menu_number == 2:
import resources.lib.upcoming as upcoming
dialog = xbmcgui.Dialog()
ret = dialog.select('Upcoming Episodes', ['1 Week', 'Extended'])
if ret == -1:
mainMenu()
if ret == 0:
upcoming.menu()
if ret == 1:
upcoming.menu(True)
elif menu_number == 3:
import resources.lib.history as history
history.menu()
elif menu_number == 4:
import resources.lib.seasons as seasons
seasons.menu(tvdb_id, show_name)
elif menu_number == 5:
import resources.lib.episodes as episodes
episodes.menu(tvdb_id, show_name, number)
elif menu_number == 6:
xbmc.executebuiltin('XBMC.Action(Info)')
elif menu_number == 7:
import resources.lib.addshow as addshow
addshow.AddShow(show_name)
elif menu_number == 8:
import resources.lib.addshow as addshow
if (action == 'addshow'):
if show_name:
addshow.AddShow(show_name)
elif tvdb_id:
# Convert tvdb_id to show_name so we can do a normal show lookup and user select confirmation.
xbmc.executebuiltin("ActivateWindow(busydialog)")
show_info = []
try:
show_info,total = Sickbeard.GetShowDetails(tvdb_id)
finally:
xbmc.executebuiltin("Dialog.Close(busydialog)")
show_name = show_info['show_name']
addshow.AddShow(show_name)
elif menu_number == 9:
import resources.lib.backlog as backlog
backlog.menu()
# ExtendedInfo Script optional TV Show lookup feature.
elif menu_number == 10:
if xbmc.getCondVisibility('System.HasAddon(script.extendedinfo)'):
xbmc.executebuiltin('XBMC.RunScript(script.extendedinfo,info=extendedtvinfo,tvdb_id=%s)' %(tvdb_id))
else:
settings.messageWindow('Feature Not Available', 'The optional add-on for this feature has not been installed.\nTo Install Goto: System > Add-ons> Install from Repo > Kodi Add-on Repo > Program Add-ons > ExtendedInfo Script')
# View log file.
elif menu_number == 11:
import resources.lib.log as log
log.main()
# Clear the image cache.
elif menu_number == 12:
if common.selectNoYes('Clear Image Cache?', 'No', 'Yes') == 1:
xbmc.executebuiltin("ActivateWindow(busydialog)")
try:
Sickbeard.ClearImageCache()
finally:
xbmc.executebuiltin("Dialog.Close(busydialog)")
common.CreateNotification(header='Image Cache', message='Cleared', icon=xbmcgui.NOTIFICATION_INFO, time=5000, sound=False)
# Update a show's images.
elif menu_number == 13:
xbmc.executebuiltin("ActivateWindow(busydialog)")
try:
# Update Poster image.
Sickbeard.GetShowPoster(tvdb_id, update=True)
# Update Fanart image.
Sickbeard.GetShowFanArt(tvdb_id, update=True)
finally:
xbmc.executebuiltin("Dialog.Close(busydialog)")
common.CreateNotification(header='Updated Cached Images for', message=show_name, icon=xbmcgui.NOTIFICATION_INFO, time=5000, sound=False)
xbmc.executebuiltin('Container.Refresh')
xbmcplugin.endOfDirectory(int(sys.argv[1]))