-
Notifications
You must be signed in to change notification settings - Fork 2
/
default.py
293 lines (236 loc) · 8.96 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import sys, urllib, time, re, os
import xbmc, xbmcaddon, xbmcgui, xbmcplugin
import context
from utils import settings
# Plugin constants
__plugin__ = 'Streamcub Library'
__author__ = 'Streamcub Team'
__url__ = 'http://www.streamcub.com'
__version__ = '1.3.4'
print "[PLUGIN] '%s: version %s' initialized!" % (__plugin__, __version__)
if settings.getSetting('tv_show_custom_directory') == "true":
TV_SHOWS_PATH = settings.getSetting('tv_show_directory')
else:
TV_SHOWS_PATH = os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.video.streamcub/tvshows'), '')
if settings.getSetting('movie_custom_directory') == "true":
MOVIES_PATH = settings.getSetting('movie_directory')
else:
MOVIES_PATH = os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.video.streamcub/movies'), '')
CACHE_PATH= os.path.join(xbmc.translatePath('special://profile/addon_data/plugin.video.streamcub/traktcache'), '')
try:
MYCONTEXT = context.context().getContext()
except:
MYCONTEXT = 'video'
from utils import searcher
from utils import common
from sites import trakt,traktlib
from sites import furklib
print sys.modules[ "__main__" ]
def parse_qs(u):
params = '?' in u and dict(p.split('=') for p in u[u.index('?') + 1:].split('&')) or {}
return params;
def AddonMenu(): #homescreen
print 'Streamcub menu'
url = sys.argv[0]+'?action='
#common.createListItem(params['content_type'],True,url + 'myFiles')
#params['action'] = 'trakt_Menu'
#trakt.traktAction(params)
common.createListItem('Movies', True, url +'MovieMenu')
common.createListItem('TV Shows', True, url +'ShowMenu')
if settings.getSetting('adult_menu') == 'true':
common.createListItem('Adult', True, url +'trakt_ShowAdultLists')
common.createListItem('My Files',True,url + 'myFiles')
#common.createListItem('Live TV',True,url + 'LiveTVMenu')
common.createListItem('Search all torrents', True, url+'search')
common.createListItem('Setup',False,url +'setup')
common.createListItem('Account usage', True, url+'accountUsage')
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def ShowMenu(): #homescreen
print 'Streamcub TV show menu'
url = sys.argv[0]+'?action='
common.createListItem('Search TV Show', True, url+'trakt_SearchShows')
common.createListItem('Genres', True, url +'trakt_ShowGenres')
common.createListItem('Featured', True, url +'trakt_Shows&name=featured')
common.createListItem('Most Popular', True, url +'trakt_Shows&name=trending')
common.createListItem('Highly Rated', True, url +'trakt_Shows&name=top_rated')
common.createListItem('Airing This Week', True, url +'trakt_Shows&name=on_the_air')
common.createListItem('Airing Today', True, url +'trakt_Shows&name=airing_today')
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def MovieMenu(): #homescreen
print 'Streamcub Movie menu'
url = sys.argv[0]+'?action='
common.createListItem('Search Movie', True, url+'trakt_SearchMovies')
common.createListItem('Genres', True, url +'trakt_MovieGenres')
common.createListItem('Most Popular', True, url +'trakt_Movies&name=trending')
#common.createListItem('Playing in theaters', True, url +'trakt_Movies&name=now_playing')
common.createListItem('Highly rated', True, url +'trakt_Movies&name=top_rated')
common.createListItem('Featured', True, url +'trakt_Movies&name=featured')
common.createListItem('Revenue', True, url +'trakt_Movies&name=revenue')
#common.createListItem('Upcoming', True, url +'trakt_Movies&name=upcoming')
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def LiveTVMenu(cat): #homescreen
print 'Streamcub Live TV menu'
dialog = xbmcgui.Dialog()
dialog.ok("Upgrade", "Your Cloudberry software is out of date",
"Visit www.cloudberrybox.com/upgrade to upgrade your box.",
"The update includes over 1000 new Live TV channels.")
def check_sources_xml(path):
try:
source_path = os.path.join(xbmc.translatePath('special://profile/'), 'sources.xml')
f = open(source_path, 'a+')
f.seek(0)
content = f.read()
f.close()
path = str(path).replace('\\', '\\\\')
if re.search(path, content):
return True
except:
xbmc.log("Could not find sources.xml!")
return False
def startup():
if len(settings.getSetting('username')) < 1:
dialog = xbmcgui.Dialog()
dialog.ok("Login", "Please login to your Streamcub account.",
"Get a free account at www.streamcub.com")
settings.openSettings()
if len(settings.getSetting('username')) > 0:
dialog = xbmcgui.Dialog()
login_ok = furklib.login(settings.getSetting('username'),settings.getSetting('password'));
if not login_ok and dialog.yesno("Login failed", "Do you want to view your settings?"):
settings.openSettings()
return login_ok
else:
return False
xbmc.log('params_str=%s' % sys.argv[2])
params = parse_qs(sys.argv[2])
if not params:
params['action'] = 'dirs'
try:
action = params['action']
except:
params['action'] = 'dirs'
xbmc.log('_params=%s' % params)
if(params['action'] == 'search'):
# Search
keyboard = xbmc.Keyboard(settings.getSetting('last_cache_search'), 'Search')
keyboard.doModal()
if keyboard.isConfirmed():
query = keyboard.getText()
settings.setSetting('last_cache_search', query)
searcher.SearchFromMenu(query)
elif(params['action'] == 'myFiles'):
searcher.getMyFiles()
elif(params['action'] == 'accountUsage'):
searcher.showAccountPicture()
elif(params['action'] == 'listFiles'):
id = params['id']
searcher.ListFiles(id)
elif(params['action'] == 'scrapeMovie'):
title = params['title']
year = params['year']
common.createMovieStrm(title,year,MOVIES_PATH)
common.Notification ('Added to library:',title)
xbmc.executebuiltin('UpdateLibrary(video)')
elif(params['action'] == 'ShowMenu'):
ShowMenu()
elif(params['action'] == 'MovieMenu'):
MovieMenu()
elif(params['action'] == 'LiveTVMenu'):
try:
LiveTVMenu(params['category'])
except:
LiveTVMenu(None)
elif(params['action'] == 'Trailers'):
xbmc.executebuiltin("XBMC.RunScript(special://home/addons/plugin.video.streamcub/trailers.py)")
elif(params['action'] == 'SearchMe'):
# Search
type = params['type']
year= 0
season = 0
episode = 0
movie = None
episodedata = None
if type=='Show':
type = params['type']
season = params['season']
episode = params['episode']
title = params['title']
try:
tvdbid = params['tvdbid']
except:
tvdbid = None
if tvdbid:
episodedata = traktlib.getEpisodeInfo(tvdbid,season,episode)
else:
episodedata = None
elif type=='Movie':
imdbid = params['imdbid']
movie = common.getMovieInfobyImdbid(imdbid)
if movie:
title = movie['title']
year = movie['year']
else:
title = params['title']
year = params['year']
else:
type = 'Movie'
title = params['query']
go = False
try:
go = params['go']
if go:
go=True
except:
go = False
print go
myname,myurl = searcher.SearchDialog(type,title,year,season,episode,go)
if myurl:
#common.Notification("Found"," and playing!")
time.sleep(1)
listitem = xbmcgui.ListItem(myname, path=myurl)
listitem.setLabel(myname)
listitem.setProperty("IsPlayable", "true")
if movie:
common.addMovieInfotoPlayListitem(listitem,movie)
#common.Notification("Found"," Movie!")
elif episodedata:
common.addEpisodeInfotoListitem(listitem,episodedata)
xbmcplugin.setResolvedUrl(int(sys.argv[ 1 ]),True,listitem)
if go:
xbmc.Player().play(myurl, listitem)
else:
xbmcplugin.setResolvedUrl(int(sys.argv[ 1 ]),False,xbmcgui.ListItem())
elif(params['action'].startswith('imdb_')):
imdb.imdbAction(params)
elif(params['action'].startswith('trakt_')):
trakt.traktAction(params)
elif(params['action'] == 'traktlib'):
try:
fg = params['fg']
except:
fg = 'True'
totalAdded = trakt.addToXbmcLib(fg)
if totalAdded>0:
common.Notification('Trakt', '{0} were added'.format(totalAdded))
xbmc.executebuiltin('UpdateLibrary(video)')
# if fg=='False':
# settings.startTimer()
elif(params['action'] == 'download'):
id = params['id']
furklib.addDownload(id)
Notification('File added')
elif(params['action'] == 'delete'):
id = params['id']
furklib.deleteDownload(id)
elif(params['action'] == 'setup'):
settings.openSettings()
if len(settings.getSetting('username')) > 0:
furklib.login(settings.getSetting('username'),settings.getSetting('password'))
else:
xbmc.log('argv=%s' % sys.argv)
if (MYCONTEXT == 'video'):
common.createCachePath()
if startup() :
AddonMenu()
print 'Closing Streamcub'
#sys.modules.clear()