/
default.py
528 lines (504 loc) · 33 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
### ############################################################################################################
### #
### # Project: # TheFunctStation.com - by The Highway 2013.
### # Author: # The Highway
### # Version: # v0.3.4
### # Description: # http://www.thefunkstation.com/ | http://listento.thefunkstation.com:8000/
### #
### ############################################################################################################
### ############################################################################################################
##### Imports #####
import xbmc,xbmcplugin,xbmcgui,xbmcaddon,xbmcvfs
#import requests ### (Removed in v0.2.1b to fix scripterror on load on Mac OS.) ###
try: import requests ### <import addon="script.module.requests" version="1.1.0"/> ###
except: t='' ### See https://github.com/kennethreitz/requests ###
import urllib,urllib2,re,os,sys,htmllib,string,StringIO,logging,random,array,time,datetime
try: import urlresolver
except: t=''
import copy
###
#import cookielib
#import base64
#import threading
###
#import unicodedata ### I don't want to use unless I absolutely have to. ###
#import zipfile ### Removed because it caused videos to not play. ###
import HTMLParser, htmlentitydefs
try: import StorageServer
except: import storageserverdummy as StorageServer
try: from t0mm0.common.addon import Addon
except: from t0mm0_common_addon import Addon
try: from t0mm0.common.net import Net
except: from t0mm0_common_net import Net
#try: from sqlite3 import dbapi2 as sqlite; print "Loading sqlite3 as DB engine"
#except: from pysqlite2 import dbapi2 as sqlite; print "Loading pysqlite2 as DB engine"
#try: from script.module.metahandler import metahandlers
#except: from metahandler import metahandlers
###
from teh_tools import *
from config import *
##### /\ ##### Imports #####
### ############################################################################################################
### ############################################################################################################
### ############################################################################################################
__plugin__=ps('__plugin__'); __authors__=ps('__authors__'); __credits__=ps('__credits__'); _addon_id=ps('_addon_id'); _domain_url=ps('_domain_url'); _database_name=ps('_database_name'); _plugin_id=ps('_addon_id')
_database_file=os.path.join(xbmc.translatePath("special://database"),ps('_database_name')+'.db');
###
_addon=Addon(ps('_addon_id'), sys.argv); addon=_addon; _plugin=xbmcaddon.Addon(id=ps('_addon_id')); cache=StorageServer.StorageServer(ps('_addon_id'))
### ############################################################################################################
### ############################################################################################################
### ############################################################################################################
##### Paths #####
### # ps('')
_addonPath =xbmc.translatePath(_plugin.getAddonInfo('path'))
_artPath =xbmc.translatePath(os.path.join(_addonPath,ps('_addon_path_art')))
_datapath =xbmc.translatePath(_addon.get_profile()); _artIcon =_addon.get_icon();
#try: _artFanart =ps('_fanart_url')
#except: _artFanart =_addon.get_fanart()
_artFanart =_addon.get_fanart()
##### /\ ##### Paths #####
##### Important Functions with some dependencies #####
def art(f,fe=ps('default_art_ext')): return xbmc.translatePath(os.path.join(_artPath,f+fe)) ### for Making path+filename+ext data for Art Images. ###
##### /\ ##### Important Functions with some dependencies #####
##### Settings #####
_setting={}; _setting['enableMeta'] = _enableMeta =tfalse(addst("enableMeta"))
_setting['debug-enable']= _debugging =tfalse(addst("debug-enable")); _setting['debug-show'] = _shoDebugging =tfalse(addst("debug-show"))
#_setting['meta.tv.page']=ps('meta.tv.page'); _setting['meta.tv.fanart.url']=ps('meta.tv.fanart.url'); _setting['meta.tv.fanart.url2']=ps('meta.tv.fanart.url2');
_setting['label-empty-favorites']=tfalse(addst('label-empty-favorites'))
CurrentPercent=0; CancelDownload=False
##### /\ ##### Settings #####
##### Variables #####
_art404=art('notfound','.gif')
_art150=art('notfound','.gif')
_artDead=ps('art_dead'); _artSun=ps('art_sun');
COUNTRIES=ps('COUNTRIES'); GENRES=ps('GENRES'); _default_section_=ps('default_section'); net=Net(); DB=_database_file; BASE_URL=_domain_url;
#_artFanart=xbmc.translatePath(os.path.join(_addonPath,'fanart5.jpg'))
##### /\ ##### Variables #####
deb('Addon Path',_addonPath); deb('Art Path',_artPath); deb('Addon Icon Path',_artIcon); deb('Addon Fanart Path',_artFanart)
### ############################################################################################################
def eod(): _addon.end_of_directory()
def deadNote(header='',msg='',delay=5000,image=_artDead): _addon.show_small_popup(title=header,msg=msg,delay=delay,image=image)
def sunNote( header='',msg='',delay=5000,image=_artSun):
header=cFL(header,ps('cFL_color')); msg=cFL(msg,ps('cFL_color2'))
_addon.show_small_popup(title=header,msg=msg,delay=delay,image=image)
def messupText(t,_html=False,_ende=False,_a=False,Slashes=False):
if (_html==True): t=ParseDescription(HTMLParser.HTMLParser().unescape(t))
if (_ende==True): t=t.encode('ascii', 'ignore'); t=t.decode('iso-8859-1')
if (_a==True): t=_addon.decode(t); t=_addon.unescape(t)
if (Slashes==True): t=t.replace( '_',' ')
return t
def name2path(name): return (((name.lower()).replace('.','-')).replace(' ','-')).replace('--','-')
def name2pathU(name): return (((name.replace(' and ','-')).replace('.','-')).replace(' ','-')).replace('--','-')
### ############################################################################################################
### ############################################################################################################
##### Queries #####
_param={}
_param['mode']=addpr('mode',''); _param['url']=addpr('url',''); _param['pagesource'],_param['pageurl'],_param['pageno'],_param['pagecount']=addpr('pagesource',''),addpr('pageurl',''),addpr('pageno',0),addpr('pagecount',1)
_param['img']=addpr('img',''); _param['fanart']=addpr('fanart',''); _param['thumbnail'],_param['thumbnail'],_param['thumbnail']=addpr('thumbnail',''),addpr('thumbnailshow',''),addpr('thumbnailepisode','')
_param['section']=addpr('section','movies'); _param['title']=addpr('title',''); _param['year']=addpr('year',''); _param['genre']=addpr('genre','')
_param['by']=addpr('by',''); _param['letter']=addpr('letter',''); _param['showtitle']=addpr('showtitle',''); _param['showyear']=addpr('showyear',''); _param['listitem']=addpr('listitem',''); _param['infoLabels']=addpr('infoLabels',''); _param['season']=addpr('season',''); _param['episode']=addpr('episode','')
_param['pars']=addpr('pars',''); _param['labs']=addpr('labs',''); _param['name']=addpr('name',''); _param['thetvdbid']=addpr('thetvdbid','')
_param['plot']=addpr('plot',''); _param['tomode']=addpr('tomode',''); _param['country']=addpr('country','')
_param['thetvdb_series_id']=addpr('thetvdb_series_id',''); _param['dbid']=addpr('dbid',''); _param['user']=addpr('user','')
_param['subfav']=addpr('subfav',''); _param['episodetitle']=addpr('episodetitle',''); _param['special']=addpr('special',''); _param['studio']=addpr('studio','')
#_param['']=_addon.queries.get('','')
#_param['']=_addon.queries.get('','')
##_param['pagestart']=addpr('pagestart',0)
##### /\
### ############################################################################################################
### ############################################################################################################
### ############################################################################################################
### ############################################################################################################
### ############################################################################################################
##### Player Functions #####
def PlayURL(url):
#play=xbmc.Player(xbmc.PLAYER_CORE_AUTO) ### xbmc.PLAYER_CORE_AUTO | xbmc.PLAYER_CORE_DVDPLAYER | xbmc.PLAYER_CORE_MPLAYER | xbmc.PLAYER_CORE_PAPLAYER
### AUTO|DVDPLAYER|MPLAYER|PAPLAYER
PlayerMethod=addst("core-player")
if (PlayerMethod=='DVDPLAYER'): PlayerMeth=xbmc.PLAYER_CORE_DVDPLAYER
elif (PlayerMethod=='MPLAYER'): PlayerMeth=xbmc.PLAYER_CORE_MPLAYER
elif (PlayerMethod=='PAPLAYER'): PlayerMeth=xbmc.PLAYER_CORE_PAPLAYER
else: PlayerMeth=xbmc.PLAYER_CORE_AUTO
play=xbmc.Player(PlayerMeth) ### xbmc.PLAYER_CORE_AUTO | xbmc.PLAYER_CORE_DVDPLAYER | xbmc.PLAYER_CORE_MPLAYER | xbmc.PLAYER_CORE_PAPLAYER
try: _addon.resolve_url(url)
except: t=''
try: play.play(url)
except: t=''
def PlayURLAuto(url):
play=xbmc.Player(xbmc.PLAYER_CORE_AUTO) ### xbmc.PLAYER_CORE_AUTO | xbmc.PLAYER_CORE_DVDPLAYER | xbmc.PLAYER_CORE_MPLAYER | xbmc.PLAYER_CORE_PAPLAYER
try: _addon.resolve_url(url)
except: t=''
try: play.play(url)
except: t=''
def PlayURLPAPlayer(url):
play=xbmc.Player(xbmc.PLAYER_CORE_PAPLAYER) ### xbmc.PLAYER_CORE_AUTO | xbmc.PLAYER_CORE_DVDPLAYER | xbmc.PLAYER_CORE_MPLAYER | xbmc.PLAYER_CORE_PAPLAYER
try: _addon.resolve_url(url)
except: t=''
try: play.play(url)
except: t=''
def PlayPlayList(url):
thumbnail=ps('_playlist_img') #_artIcon
name='The Funk Station'
liz=xbmcgui.ListItem(name,iconImage=thumbnail,thumbnailImage=thumbnail)
liz.setInfo('music',{'Title':name}) # ,"Duration" : duration
liz.setProperty('mimetype', 'audio/mpeg')
liz.setProperty('IsPlayable', 'true') #play=xbmc.Player(xbmc.PLAYER_CORE_AUTO) ### xbmc.PLAYER_CORE_AUTO | xbmc.PLAYER_CORE_DVDPLAYER | xbmc.PLAYER_CORE_MPLAYER | xbmc.PLAYER_CORE_PAPLAYER
pl = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
pl.clear()
pl.add(url, liz)
#xbmc.Player(xbmc.PLAYER_CORE_MPLAYER).play(pl)
#play=xbmc.Player(xbmc.PLAYER_CORE_AUTO) ### xbmc.PLAYER_CORE_AUTO | xbmc.PLAYER_CORE_DVDPLAYER | xbmc.PLAYER_CORE_MPLAYER | xbmc.PLAYER_CORE_PAPLAYER
play=xbmc.Player(xbmc.PLAYER_CORE_MPLAYER)
try: _addon.resolve_url(url)
except: t=''
try: play.play(pl) # url
except: t=''
#try: _addon.resolve_url(pl)
#except: t=''
def DownloadStatus(numblocks, blocksize, filesize, dlg, download_method, start_time, section, url, img, LabelName, ext, LabelFile):
if (CancelDownload==True):
try:
if (download_method=='Progress'): ## For Frodo and earlier.
dlg.close()
elif (download_method=='ProgressBG'): ## Only works on daily build of XBMC.
dlg.close()
elif (download_method=='Test'): t=''
elif (download_method=='Hidden'): t=''
except: t=''
try:
percent = min(numblocks * blocksize * 100 / filesize, 100)
currently_downloaded = float(numblocks) * blocksize / (1024 * 1024)
kbps_speed = numblocks * blocksize / (time.time() - start_time)
if kbps_speed > 0: eta = (filesize - numblocks * blocksize) / kbps_speed
else: eta = 0
kbps_speed /= 1024
total = float(filesize) / (1024 * 1024)
#if (download_method=='Progress'): ## For Frodo and earlier.
# line1 = '%.02f MB of %.02f MB' % (currently_downloaded, total)
# line1 +=' '+percent+'%'
# line2 = 'Speed: %.02f Kb/s ' % kbps_speed
# line3 = 'ETA: %02d:%02d' % divmod(eta, 60)
# dlg.update(percent, line1, line2, line3)
#elif (download_method=='ProgressBG'): ## Only works on daily build of XBMC.
# line1 ='%.02f MB of %.02f MB' % (currently_downloaded, total)
# line1 +=' '+percent+'%'
# line2 ='Speed: %.02f Kb/s ' % kbps_speed
# line2 +='ETA: %02d:%02d' % divmod(eta, 60)
# dlg.update(percent, line1, line2)
#elif (download_method=='Test'):
# mbs = '%.02f MB of %.02f MB' % (currently_downloaded, total)
# spd = 'Speed: %.02f Kb/s ' % kbps_speed
# est = 'ETA: %02d:%02d' % divmod(eta, 60)
# Header= ext+' '+mbs+' '+percent+'%'
# Message= est+' '+spd
#elif (download_method=='Hidden'): t=''
#if (time.time()==start_time) or (int(str(time.time())[-5:1]) == 0): # and (int(str(time.time())[-5:2]) < 10):
#if (int(time.strptime(time.time(),fmt='%S')) == 0):
#if (str(percent) in ['0','1','5','10','15','20','25','30','35','40','45','50','55','60','65','70','75','80','85','90','91','92','93','94','95','96','97','98','99','100']):
#if (str(percent) == '0' or '1' or '5' or '10' or '15' or '20' or '25' or '30' or '35' or '40' or '45' or '50' or '55' or '60' or '65' or '70' or '75' or '80' or '85' or '90' or '91' or '92' or '93' or '94' or '95' or '96' or '97' or '98' or '99' or '100'):
#if ('.' in str(percent)): pCheck=int(str(percent).split('.')[0])
#else: pCheck=percent
#pCheck=int(str(percent)[1:])
#if (CurrentPercent is not pCheck):
# global CurrentPercent
# CurrentPercent=pCheck
# myNote(header=Header,msg=Message,delay=100,image=img)
##myNote(header=Header,msg=Message,delay=1,image=img)
except:
percent=100
if (download_method=='Progress'): ## For Frodo and earlier.
t=''
dlg.update(percent)
elif (download_method=='ProgressBG'): ## Only works on daily build of XBMC.
t=''
dlg.update(percent)
elif (download_method=='Test'): t=''
#myNote(header='100%',msg='Download Completed',delay=15000,image=img)
elif (download_method=='Hidden'): t=''
if (download_method=='Progress'): ## For Frodo and earlier.
line1 = '%.02f MB of %.02f MB' % (currently_downloaded, total)
line1 +=' '+str(percent)+'%'
line2 = 'Speed: %.02f Kb/s ' % kbps_speed
line3 = 'ETA: %02d:%02d' % divmod(eta, 60)
dlg.update(percent, line1, line2, line3)
elif (download_method=='ProgressBG'): ## Only works on daily build of XBMC.
line1 ='%.02f MB of %.02f MB' % (currently_downloaded, total)
line1 +=' '+str(percent)+'%'
line2 ='Speed: %.02f Kb/s ' % kbps_speed
line2 +='ETA: %02d:%02d' % divmod(eta, 60)
dlg.update(percent, line1, line2)
elif (download_method=='Test'):
mbs = '%.02f MB of %.02f MB' % (currently_downloaded, total)
spd = 'Speed: %.02f Kb/s ' % kbps_speed
est = 'ETA: %02d:%02d' % divmod(eta, 60)
Header= ext+' '+mbs+' '+str(percent)+'%'
Message= est+' '+spd
elif (download_method=='Hidden'): t=''
if (download_method=='Progress'): ## For Frodo and earlier.
try:
if dlg.iscanceled(): ## used for xbmcgui.DialogProgress() but causes an error with xbmcgui.DialogProgressBG()
dlg.close()
#deb('Download Error','Download canceled.'); myNote('Download Error','Download canceled.')
#raise StopDownloading('Stopped Downloading')
except: t=''
elif (download_method=='ProgressBG'): ## Only works on daily build of XBMC.
try:
if (dlg.isFinished()):
dlg.close()
except: t=''
def DownloadRequest(section, url,img,LabelName):
if (LabelName=='') and (_param['title'] is not ''): LabelName==_param['title']
if (LabelName=='') and (_param['showtitle'] is not ''): LabelName==_param['showtitle']
LabelFile=clean_filename(LabelName)
deb('LabelName',LabelName)
if (LabelName==''): deb('Download Error','Missing Filename String.'); myNote('Download Error','Missing Filename String.'); return
if (section==ps('section.wallpaper')): FolderDest=xbmc.translatePath(addst("download_folder_wallpapers"))
elif (section==ps('section.tv')): FolderDest=xbmc.translatePath(addst("download_folder_tv"))
elif (section==ps('section.movie')): FolderDest=xbmc.translatePath(addst("download_folder_movies"))
else: FolderDest=xbmc.translatePath(addst("download_folder_movies"))
if os.path.exists(FolderDest)==False: os.mkdir(FolderDest)
if os.path.exists(FolderDest):
if (section==ps('section.tv')) or (section==ps('section.movie')):
### param >> url: /link/show/1466546/
match=re.search( '/.+?/.+?/(.+?)/', url) ## Example: http://www.solarmovie.so/link/show/1052387/ ##
videoId=match.group(1); deb('Solar ID',videoId); url=BASE_URL + '/link/play/' + videoId + '/' ## Example: http://www.solarmovie.so/link/play/1052387/ ##
html=net.http_GET(url).content; match=re.search( '<iframe.+?src="(.+?)"', html, re.IGNORECASE | re.MULTILINE | re.DOTALL); link=match.group(1); link=link.replace('/embed/', '/file/'); deb('hoster link',link)
try: stream_url = urlresolver.HostedMediaFile(link).resolve()
except: stream_url=''
ext=Download_PrepExt(stream_url,'.flv')
else:
stream_url=url
ext=Download_PrepExt(stream_url,'.jpg')
t=1; c=1
if os.path.isfile(xbmc.translatePath(os.path.join(FolderDest,LabelFile+ext))):
t=LabelFile
while t==LabelFile:
if os.path.isfile(xbmc.translatePath(os.path.join(FolderDest,LabelFile+'['+str(c)+']'+ext)))==False:
LabelFile=LabelFile+'['+str(c)+']'
c=c+1
start_time = time.time()
deb('start_time',str(start_time))
download_method=addst('download_method') ### 'Progress|ProgressBG|Hidden'
urllib.urlcleanup()
if (download_method=='Progress'):
dp=xbmcgui.DialogProgress(); dialogType=12 ## For Frodo and earlier.
dp.create('Downloading', LabelFile+ext)
urllib.urlretrieve(stream_url, xbmc.translatePath(os.path.join(FolderDest,LabelFile+ext)), lambda nb, bs, fs: DownloadStatus(nb, bs, fs, dp, download_method, start_time, section, url, img, LabelName, ext, LabelFile)) #urllib.urlretrieve(url, localfilewithpath)
myNote('Download Complete',LabelFile+ext,15000)
elif (download_method=='ProgressBG'):
dp=xbmcgui.DialogProgressBG(); dialogType=13 ## Only works on daily build of XBMC.
dp.create('Downloading', LabelFile+ext)
urllib.urlretrieve(stream_url, xbmc.translatePath(os.path.join(FolderDest,LabelFile+ext)), lambda nb, bs, fs: DownloadStatus(nb, bs, fs, dp, download_method, start_time, section, url, img, LabelName, ext, LabelFile)) #urllib.urlretrieve(url, localfilewithpath)
myNote('Download Complete',LabelFile+ext,15000)
elif (download_method=='Test'):
dp=xbmcgui.DialogProgress()
myNote('Download Started',LabelFile+ext,15000)
urllib.urlretrieve(stream_url, xbmc.translatePath(os.path.join(FolderDest,LabelFile+ext)), lambda nb, bs, fs: DownloadStatus(nb, bs, fs, dp, download_method, start_time, section, url, img, LabelName, ext, LabelFile)) #urllib.urlretrieve(url, localfilewithpath)
myNote('Download Complete',LabelFile+ext,15000)
elif (download_method=='Hidden'):
dp=xbmcgui.DialogProgress()
myNote('Download Started',LabelFile+ext,15000)
urllib.urlretrieve(stream_url, xbmc.translatePath(os.path.join(FolderDest,LabelFile+ext)), lambda nb, bs, fs: DownloadStatus(nb, bs, fs, dp, download_method, start_time, section, url, img, LabelName, ext, LabelFile)) #urllib.urlretrieve(url, localfilewithpath)
myNote('Download Complete',LabelFile+ext,15000)
elif (download_method=='jDownloader (StreamURL)'):
myNote('Download','sending to jDownloader plugin',15000)
xbmc.executebuiltin("XBMC.RunPlugin(plugin://plugin.program.jdownloader/?action=addlink&url=%s)" % stream_url)
#return
elif (download_method=='jDownloader (Link)'):
myNote('Download','sending to jDownloader plugin',15000)
xbmc.executebuiltin("XBMC.RunPlugin(plugin://plugin.program.jdownloader/?action=addlink&url=%s)" % link)
#return
else: deb('Download Error','Incorrect download method.'); myNote('Download Error','Incorrect download method.'); return
##
##urllib.urlretrieve(stream_url, xbmc.translatePath(os.path.join(FolderDest,LabelFile+ext)), lambda nb, bs, fs: DownloadStatus(nb, bs, fs, dp, download_method, start_time, section, url, img, LabelName, ext, LabelFile)) #urllib.urlretrieve(url, localfilewithpath)
##
#myNote('Download Complete',LabelFile+ext,15000)
##
#### xbmc.translatePath(os.path.join(FolderDest,localfilewithpath+ext))
_addon.resolve_url(url)
_addon.resolve_url(stream_url)
#
#
else: deb('Download Error','Unable to create destination path.'); myNote('Download Error','Unable to create destination path.'); return
#def StartLastFM(): path='plugin://'+ps('_plugin_id')+'/slideshow.py'; xbmc.executebuiltin('XBMC.RunScript(%s)' % path)
# ##path = os.path.join(xbmc.translatePath('special://home/addons'), 'script.image.lastfm.slideshow', 'default.py')
# #path = os.path.join(_addonPath, 'slideshow.py')
# #xbmc.executebuiltin('XBMC.RunScript(%s)' % path)
# path='plugin://'+ps('_plugin_id')+'/slideshow.py'; xbmc.executebuiltin('XBMC.RunScript(%s)' % path)
##### /\ ##### Player Functions #####
### ############################################################################################################
### ############################################################################################################
### ############################################################################################################
##### Weird, Stupid, or Plain up Annoying Functions. #####
def netURL(url): ### Doesn't seem to work.
return net.http_GET(url).content
def remove_accents(input_str): ### Not even sure rather this one works or not.
#nkfd_form = unicodedata.normalize('NFKD', unicode(input_str))
#return u"".join([c for c in nkfd_form if not unicodedata.combining(c)])
return input_str
##### /\ ##### Weird, Stupid, or Plain up Annoying Functions. #####
### ############################################################################################################
### ############################################################################################################
### ############################################################################################################
def mGetItemPage(url):
deb('Fetching html from Url',url)
try: html=net.http_GET(url).content
except: html=''
if (html=='') or (html=='none') or (html==None) or (html==False): return ''
else:
html=HTMLParser.HTMLParser().unescape(html); html=_addon.decode(html); html=_addon.unescape(html); html=ParseDescription(html); html=html.encode('ascii', 'ignore'); html=html.decode('iso-8859-1'); deb('Length of HTML fetched',str(len(html)))
return html
def mGetDataGroup2String(html,parseTag='',ifTag='',startTag='',endTag='',Topic=''):
if (ifTag in html):
html=(((html.split(startTag)[1])).split(endTag)[0]).strip()
try: results=re.compile(parseTag, re.MULTILINE | re.IGNORECASE | re.DOTALL).findall(html)
except: return ''
i=0; r=''
for result in results:
if (i==0): r=result.strip()
else: r=r+', '+result.strip()
i=i+1
deb(Topic,r); return r
else: return ''
def mdGetSplitFindGroup(html,ifTag='', parseTag='',startTag='',endTag=''):
if (ifTag=='') or (parseTag=='') or (startTag=='') or (endTag==''): return ''
if (ifTag in html):
html=(((html.split(startTag)[1])).split(endTag)[0]).strip()
try: return re.compile(parseTag, re.MULTILINE | re.IGNORECASE | re.DOTALL).findall(html)
except: return ''
else: return ''
### ############################################################################################################
### ############################################################################################################
### ############################################################################################################
##### Menus #####
def Menu_MainMenu(): #The Main Menu
WhereAmI('@ the Main Menu')
_addon.add_directory({'mode': 'PlayURL','url':'http://listento.thefunkstation.com:8000/'}, {'title': cFL_('Listen (on Gotham)',ps('cFL_color'))} ,is_folder=False ,fanart=_artFanart,img=art('Listen')) #img=ps('_button_url'))
_addon.add_directory({'mode': 'PlayURLPAPlayer','url':'http://listento.thefunkstation.com:8000/'}, {'title': cFL_('Listen (on Frodo)',ps('cFL_color'))} ,is_folder=False ,fanart=_artFanart, img=art('Listen2')) #ps('_button_url'))
#
_addon.add_directory({'mode': 'SongHistory','url':'http://listento.thefunkstation.com:8000/played.html'}, {'title': cFL_('Song History',ps('cFL_color3'))} ,is_folder=True ,fanart=_artFanart, img=art('SongHistory')) #ps('_tfs_mini_img'))
_addon.add_directory({'mode': 'Status','url':'http://listento.thefunkstation.com:8000/index.html'}, {'title': cFL_('Status',ps('cFL_color3'))} ,is_folder=True ,fanart=_artFanart, img=art('Status')) #ps('_tfs_mini_img'))
_addon.add_directory({'mode': 'SlideShowStart'},{'title': cFL_('Start SlideShow (LastFM Packaged)',ps('cFL_color5'))} ,is_folder=True ,fanart=_artFanart, img=art('SlideShow')) #ps('_button2_url'))
#
_addon.add_directory({'mode': 'Settings'}, {'title': cFL_('Plugin Settings',ps('cFL_color2'))} ,is_folder=True ,fanart=_artFanart, img=art('Settings')) #ps('_settings_url'))
##_addon.add_directory({'mode': 'DownloadStop'}, {'title': cFL('S',ps('cFL_color'))+'top Current Download'},is_folder=False ,img=_artDead ,fanart=_artFanart)
#_addon.add_directory({'mode': 'TextBoxFile', 'title': "[COLOR cornflowerblue]Local Change Log:[/COLOR] %s" % (__plugin__), 'url': ps('changelog.local')}, {'title': cFL('L',ps('cFL_color'))+'ocal Change Log'}, img=art('thechangelog','.jpg'), is_folder=False ,fanart=_artFanart)
#_addon.add_directory({'mode': 'TextBoxUrl', 'title': "[COLOR cornflowerblue]Latest Change Log:[/COLOR] %s" % (__plugin__), 'url': ps('changelog.url')}, {'title': cFL('L',ps('cFL_color'))+'atest Online Change Log'}, img=art('thechangelog','.jpg'), is_folder=False ,fanart=_artFanart)
#_addon.add_directory({'mode': 'TextBoxUrl', 'title': "[COLOR cornflowerblue]Latest News:[/COLOR] %s" % (__plugin__), 'url': ps('news.url')}, {'title': cFL('L',ps('cFL_color'))+'atest Online News'}, img=_art404 , is_folder=False ,fanart=_artFanart)
### ############
set_view('list',addst('default-view')); eod()
### ############
### _addon.show_countdown(9000,'Testing','Working...') ### Time seems to be in seconds.
##### /\ ##### Menus #####
def SongHistory(url):
if (url==''): deadNote('URL Error', 'No URL was Found.'); return
html=''; WhereAmI('@ Song History -- url: %s' % url)
try: html=net.http_GET(url).content
except:
try: html=getURL(url)
except:
try: html=getURLr(url,_domain_url)
except: html=''
if (html=='') or (html=='none') or (html==None): deb('Error','Problem with page'); deadNote('Results: '+section,'No results were found.'); return
deb('Length of HTML',str(len(html)))
html2=(html.split('<tr><td>Played @</td><td><b>Song Title</b></td></tr>')[1]).split('</table>')[0]
html2=html2.replace('<b>','[B]').replace('<B>','[B]').replace('</b>','[/B]').replace('</B>','[/B]')
html2=html2.replace('<i>','[I]').replace('<I>','[I]').replace('</i>','[/I]').replace('</I>','[/I]')
html2=html2.replace('<tr>','').replace('<TR>','').replace('</tr>','[CR]').replace('</TR>','[CR]')
html2=html2.replace('</td><td>',' ').replace('</TD><TD>',' ')
html2=html2.replace('<td>','').replace('<TD>','').replace('</td>','').replace('</TD>','')
html2=html2.replace('[B]Current Song[/B]','[B][COLOR grey] << Current Song[/COLOR][/B]')
#html2=html2.replace('','')
#try: _addon.resolve_url(url)
#except: t=''
TextBox2().load_string( html2 , cFL('Song History',ps('cFL_color2')) )
#eod()
def Status(url):
if (url==''): deadNote('URL Error', 'No URL was Found.'); return
html=''; WhereAmI('@ Status -- url: %s' % url)
try: html=net.http_GET(url).content
except:
try: html=getURL(url)
except:
try: html=getURLr(url,_domain_url)
except: html=''
if (html=='') or (html=='none') or (html==None): deb('Error','Problem with page'); deadNote('Results: '+section,'No results were found.'); return
deb('Length of HTML',str(len(html)))
html2=(html.split('<table cellpadding=5 cellspacing=0 border=0 width=100%><tr><td bgcolor=#000025 colspan=2 align=center><font class=ST>Current Stream Information</font></td></tr></table><table cellpadding=2 cellspacing=0 border=0 align=center>')[1]).split('</table>')[0]
html2=html2.replace('<b>','[B]').replace('<B>','[B]').replace('</b>','[/B]').replace('</B>','[/B]').replace('<i>','[I]').replace('<I>','[I]').replace('</i>','[/I]').replace('</I>','[/I]').replace('<tr>','').replace('<TR>','').replace('</tr>','[CR]').replace('</TR>','[CR]').replace('</td><td>',' ').replace('</TD><TD>',' ').replace('<td>','').replace('<TD>','').replace('</td>','').replace('</TD>','')
html2=html2.replace('<td width=100 nowrap>','').replace('<font class=default>','').replace('</font>','')
html2=html2.replace('<br>','[CR]').replace('<BR>','[CR]').replace(' ',' ').replace('[/B][/B]','[/B]')
html2=html2.replace('</a>','[/COLOR]').replace('<a href="','[COLOR maroon]').replace('">','[/COLOR] [COLOR red]')
#html2=html2.replace('','')
#try: _addon.resolve_url(url)
#except: t=''
TextBox2().load_string( html2 , cFL('Song History',ps('cFL_color2')) )
#eod()
### ############################################################################################################
### ############################################################################################################
### ############################################################################################################
##### Modes #####
def check_mode(mode=''):
deb('Mode',mode)
if (mode=='') or (mode=='main') or (mode=='MainMenu'): Menu_MainMenu()
#elif (mode=='PlayVideo'): PlayVideo(_param['url'], _param['infoLabels'], _param['listitem'])
#elif (mode=='PlaySong'): PlaySong(_param['url'], _param['title'], _param['img'])
elif (mode=='PlayURL'): PlayURL(_param['url'])
elif (mode=='PlayURLAuto'): PlayURLAuto(_param['url'])
elif (mode=='PlayURLPAPlayer'): PlayURLPAPlayer(_param['url'])
elif (mode=='PlayPlayList'): PlayPlayList(_param['url'])
elif (mode=='Settings'): _addon.addon.openSettings() #_plugin.openSettings()
#elif (mode=='ResolverSettings'): urlresolver.display_settings()
#elif (mode=='LoadCategories'): Menu_LoadCategories(_param['section'])
#elif (mode=='GetTitles'): listItems(_param['section'], _param['url'], _param['pageno'], _param['pagecount'], _param['genre'], _param['year'], _param['title'])
elif (mode=='TextBoxFile'): TextBox2().load_file(_param['url'],_param['title']); eod()
elif (mode=='TextBoxUrl'): TextBox2().load_url( _param['url'],_param['title']); eod()
elif (mode=='Search'): doSearchNormal(_param['section'],_param['title'])
elif (mode=='sunNote'): sunNote( header=_param['title'],msg=_param['plot'])
elif (mode=='deadNote'): deadNote(header=_param['title'],msg=_param['plot'])
#elif (mode=='Download'): print _param; DownloadRequest(_param['section'], _param['url'],_param['img'],_param['studio']); eod()
#elif (mode=='DownloadStop'): DownloadStop(); eod()
#elif (mode=='ChangeFanartList'): ChangeFanartList(_param['section'],_param['subfav'],_param['url'],_param['fanart'],_param['img'],_param['studio'])
#elif (mode=='ChangeFanartUpdate'): ChangeFanartUpdate(_param['section'],_param['subfav'],_param['url'],_param['title'])
elif (mode=='SongHistory'): SongHistory(_param['url'])
elif (mode=='Status'): Status(_param['url'])
elif (mode=='SlideShowStart'): path = os.path.join(_addonPath, 'slideshow.py'); xbmc.executebuiltin('XBMC.RunScript(%s)' % path)
else: deadNote(header='Mode: "'+mode+'"',msg='[ mode ] not found.'); initDatabase(); Menu_MainMenu()
# {'showyear': '', 'infoLabels': "
# {'Plot': '', 'Episode': '11', 'Title': u'Transformers Prime', 'IMDbID': '2961014', 'host': 'filenuke.com',
# 'IMDbURL': 'http://anonym.to/?http%3A%2F%2Fwww.imdb.com%2Ftitle%2Ftt2961014%2F',
# 'ShowTitle': u'Transformers Prime', 'quality': 'HDTV', 'Season': '3', 'age': '25 days',
# 'Studio': u'Transformers Prime (2010): 3x11 - Persuasion', 'Year': '2010', 'IMDb': '2961014',
# 'EpisodeTitle': u'Persuasion'}", 'thetvdbid': '', 'year': '', 'special': '', 'plot': '',
# 'img': 'http://static.solarmovie.so/images/movies/1659175_150x220.jpg', 'title': '', 'fanart': '', 'dbid': '', 'section': 'tv', 'pagesource': '', 'listitem': '<xbmcgui.ListItem object at 0x14C799B0>', 'episodetitle': '', 'thumbnail': '', 'thetvdb_series_id': '', 'season': '', 'labs': '', 'pageurl': '', 'pars': '', 'user': '', 'letter': '', 'genre': '', 'by': '', 'showtitle': '', 'episode': '', 'name': '', 'pageno': 0, 'pagecount': 1, 'url': '/link/show/1466546/', 'country': '', 'subfav': '', 'mode': 'Download', 'tomode': ''}
##### /\ ##### Modes #####
### ############################################################################################################
deb('param >> studio',_param['studio'])
deb('param >> season',_param['season'])
deb('param >> section',_param['section'])
deb('param >> img',_param['img'])
deb('param >> showyear',_param['showyear'])
deb('param >> showtitle',_param['showtitle'])
deb('param >> title',_param['title'])
deb('param >> url',_param['url']) ### Simply Logging the current query-passed / param -- URL
check_mode(_param['mode']) ### Runs the function that checks the mode and decides what the plugin should do. This should be at or near the end of the file.
### ############################################################################################################
### ############################################################################################################
### ############################################################################################################
###
### ** Currently Used: **
###
### Menu_MainMenu
### Menu_BrowseByCountry
### Menu_BrowseByYear
### Menu_BrowseByScore
### Menu_BrowseByRating
### listItems
### PlayVideo
###
###
###
###
### ############################################################################################################
### ############################################################################################################
### ############################################################################################################