-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathteh_tools.py
1823 lines (1706 loc) · 99.6 KB
/
teh_tools.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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### ############################################################################################################
### #
### # Project: # teh_tools - by The Highway 2013.
### # Author: # The Highway
### # Version: # (ever changing)
### # Description: # My collection of common tools.
### #
### ############################################################################################################
### ############################################################################################################
from config import *
__plugin__ = ps('__plugin__')
__authors__ = ps('__authors__')
plugin_id = ps('_plugin_id')
#__plugin__ = "[COLOR grey][COLOR goldenrod]S[/COLOR]olar[COLOR yellow]M[/COLOR]ovie.so[/COLOR]"
#__authors__ = "The Highway"
#plugin_id = "plugin.video.solarmovie.so"
### ############################################################################################################
### ############################################################################################################
import xbmc,xbmcplugin,xbmcgui,xbmcaddon,xbmcvfs
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: print "Failed to import urlresolver."; pass
import copy
try: import json
except ImportError: import simplejson as json
#try: import StorageServer
#except: import storageserverdummy as StorageServer
#cache = StorageServer.StorageServer(plugin_id)
try:
try: import StorageServer as StorageServer
except:
try: import z_StorageServer as StorageServer
except:
try: import storageserverdummy as StorageServer
except:
try: import z_storageserverdummy as StorageServer
except: pass
cache=StorageServer.StorageServer(plugin_id)
except: pass
## ### ##
#from t0mm0.common.net import Net as net
#from t0mm0.common.net import Net
#from t0mm0.common.addon import Addon
#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 t0mm0.common.net import Net as net
#except: from t0mm0_common_net import Net as net
try: from addon.common.addon import Addon
except:
try: from t0mm0.common.addon import Addon
except: from t0mm0_common_addon import Addon
try: from addon.common.net import Net
except:
try: from t0mm0.common.net import Net
except: from t0mm0_common_net import Net
try: from addon.common.net import Net as net
except:
try: from t0mm0.common.net import Net as net
except: from t0mm0_common_net import Net as net
net_=Net();
#from config import *
### ############################################################################################################
### ############################################################################################################
### ### Common Imports ###
### ######################
### import shutil, md5, base64, unicodedata, threading, string
### import resources.lib.common as common
### import xbmc, xbmcplugin, xbmcgui, xbmcaddon, xbmcvfs, common
### import os.path, sys, urllib, urllib2, cookielib, string, httplib, socket, random
### import os, re, math, binascii, datetime, HTMLParser
### from BeautifulSoup import BeautifulStoneSoup
### from BeautifulSoup import BeautifulSoup , Tag, NavigableString
### try: from xml.etree import ElementTree
### except: from elementtree import ElementTree
### from xbmcgui import Dialog
### import copy
### requests, httplib, urlparse
### from operator import itemgetter
### from metahandler import metahandlers
### from metahandler import metacontainers
###
###
###
###
###
###
###
###
###
### ############################################################################################################
### ############################################################################################################
def get_params():
param=[]
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
### ############################################################################################################
### ############################################################################################################
cache = StorageServer.StorageServer(plugin_id)
addon = Addon(plugin_id, sys.argv)
local = xbmcaddon.Addon(id=plugin_id)
__settings__ = xbmcaddon.Addon(id=plugin_id)
__home__ = __settings__.getAddonInfo('path')
addonPath = __settings__.getAddonInfo('path')
artPath = addonPath+'/art/' #special://home/addons/plugin.video.theanimehighway/art
if __settings__.getSetting("debug-enable") == "true":debugging=True #if (debugging==True):
else: debugging=False
if __settings__.getSetting("debug-show") == "true": shoDebugging=True #if (showDebugging==True):
else: shoDebugging=False
_debugging=debugging; _shoDebugging=shoDebugging
params=get_params()
ICON = os.path.join(__home__, 'icon.png')
fanart = os.path.join(__home__, 'fanart.jpg')
_addon=Addon(ps('_addon_id'), sys.argv);
def addst(r,s=''): return _addon.get_setting(r) ## Get Settings
def addpr(r,s=''): return _addon.queries.get(r,s) ## Get Params
def cFL(t,c=ps('default_cFL_color')): ### For Coloring Text ###
return '[COLOR '+c+']'+t+'[/COLOR]'
def cFL_(t,c=ps('default_cFL_color')): ### For Coloring Text ###
return '[COLOR '+c+']'+t[0:1]+'[/COLOR]'+t[1:]
### ############################################################################################################
### ############################################################################################################
url=None; urlbac=None; name=None; name2=None; type2=None; favcmd=None; mode=None; scr=None; imgfan=None; show=None; category=None
try: category=urllib.unquote_plus(params["cat"])
except: pass
if category==None: category='Base'
try:
url=urllib.unquote_plus(params["url"])
urlbac=url
except: pass
try: scr=urllib.unquote_plus(params["scr"])
except: pass
try: imgfan=urllib.unquote_plus(params["fan"])
except: pass
try: favcmd=urllib.unquote_plus(params["fav"])
except: pass
try: name=urllib.unquote_plus(params["name"])
except: pass
try: name2=urllib.unquote_plus(params["nm"])
except: pass
try: show=urllib.unquote_plus(params["show"])
except: pass
try: type2=int(params["tp"])
except: pass
try: mode=int(params["mode"])
except: pass
### ############################################################################################################
### ############################################################################################################
ICON8 = os.path.join(artPath, 'icon_watchdub.png');ICON7 = os.path.join(artPath, 'icon_dubhappy.png');ICON6 = os.path.join(artPath, 'iconDAOn2.png');ICON5 = os.path.join(artPath, 'iconA44couk.png');ICON4 = os.path.join(artPath, 'icongd.png');ICON3 = os.path.join(artPath, 'iconAPlus.png');ICON2 = os.path.join(artPath, 'iconA44.png');ICON1 = os.path.join(artPath, 'iconAG.png');ICON0 = os.path.join(__home__, 'icon.png')
fanart8 = os.path.join(artPath, 'fanart_watchdub.jpg');fanart7 = os.path.join(artPath, 'fanart_dubhappy.jpg');fanart6 = os.path.join(artPath, 'fanartDAOn2.jpg');fanart5 = os.path.join(artPath, 'fanartA44couk.jpg');fanart4 = os.path.join(artPath, 'fanartgd.jpg');fanart3 = os.path.join(artPath, 'fanartAPlus.jpg');fanart2 = os.path.join(artPath, 'fanartA44.jpg');fanart1 = os.path.join(artPath, 'fanartAG.jpg');fanart0 = os.path.join(__home__, 'fanart.jpg')
if type2==8: #site 8
fanart = os.path.join(artPath, 'fanart_watchdub.jpg');ICON = os.path.join(artPath, 'icon_watchdub.png');mainSite='http://www.watchdub.com/'
elif type2==7: #site 7
fanart = os.path.join(artPath, 'fanart_dubhappy.jpg');ICON = os.path.join(artPath, 'icon_dubhappy.png');mainSite='http://www.dubhappy.eu/'
elif type2==6: #site 6
fanart = os.path.join(artPath, 'fanartDAOn2.jpg');ICON = os.path.join(artPath, 'iconDAOn2.png');mainSite='http://dubbedanimeon.com/'
elif type2==5: #site 5
fanart = os.path.join(artPath, 'fanartA44couk.jpg');ICON = os.path.join(artPath, 'iconA44couk.png');mainSite='http://www.anime44.co.uk/'
if ('-anime' in url) and ('http://' not in url): url = mainSite + 'subanime/' + url
if ('-anime' in url) and ('http://' not in scr) and (artPath not in scr): scr = mainSite + 'subanime/' + scr
if ('-anime' in url) and ('http://' not in imgfan) and (artPath not in imgfan): imgfan = mainSite + 'subanime/' + imgfan
#if ('-anime' not in url) and ('http://' not in url): url = mainSite + 'english-dubbed/' + url
#if ('-anime' not in url) and ('http://' not in scr) and (artPath not in scr): scr = mainSite + 'english-dubbed/' + scr
#if ('-anime' not in url) and ('http://' not in imgfan) and (artPath not in imgfan): imgfan = mainSite + 'english-dubbed/' + imgfan
#if ('alpha-anime' in url): url.replace('alpha-anime','subanime')
#if ('alpha-movies' in url): url.replace('alpha-movies','subanime')
#if ('alpha-anime' in show): show.replace('alpha-anime','subanime')
#if ('alpha-movies' in show): show.replace('alpha-movies','subanime')
elif type2==4: #site 4
fanart = os.path.join(artPath, 'fanartgd.jpg');ICON = os.path.join(artPath, 'icongd.png');mainSite='http://www.gooddrama.net/'
elif type2==3: #site 3
fanart = os.path.join(artPath, 'fanartplus.jpg');ICON = os.path.join(artPath, 'iconplus.png');mainSite='http://www.animeplus.tv/'
elif type2==2: #site 2
fanart = os.path.join(artPath, 'fanartA44.jpg');ICON = os.path.join(artPath, 'iconA44.png');mainSite='http://www.anime44.com/'
else: #site 1
fanart = os.path.join(artPath, 'fanartAG.jpg');ICON = os.path.join(artPath, 'iconAG.png');mainSite='http://www.animeget.com/'
### ############################################################################################################
### ############################################################################################################
SiteBits=['nosite','animeget.com','anime44.com','animeplus.tv','gooddrama.net','anime44.co.uk','dubbedanimeon.com','dubhappy.eu','watchdub.com']
SiteNames=['nosite','[COLOR blue][COLOR white]Anime[/COLOR]Get[/COLOR]','[COLOR red][COLOR white]Anime[/COLOR]44[/COLOR]','[COLOR darkblue][COLOR white]Anime[/COLOR]Plus[/COLOR]','[COLOR grey]Good[COLOR white]Drama[/COLOR][/COLOR]','[COLOR maroon][COLOR white]Anime[/COLOR]Zone[/COLOR]','[COLOR teal]Dubbed[COLOR white]Anime[/COLOR]On [/COLOR]','[COLOR cornflowerblue][COLOR white]dub[/COLOR]happy[/COLOR]','[COLOR cornflowerblue]Watch[/COLOR][COLOR white]Dub[/COLOR]','','']
SitePrefixes=['nosite','','','','','subanime/','','','','','','','','','','','','']
SiteSufixes= ['nosite','','','','','.html','','','','','','','','','','','','','']
SiteSearchUrls= ['nosite','http://www.animeget.com/search','http://www.anime44.com/anime/search?search_submit=Go&key=','http://www.animeplus.tv/anime/search?search_submit=Go&key=','http://www.gooddrama.net/drama/search?stype=drama&search_submit=Go&key=','No Search Engine for VideoZone','http://dubbedanimeon.com/?s=','','','','','','','']
SiteSearchMethod= ['nosite','post','get','get','get','VideoZone','get','','','','','','','']
Sites=['animeget.com','anime44.com','animeplus.tv','gooddrama.net','anime44.co.uk','dubbedanimeon.com','dubhappy.eu','watchdub.com']
MyAlphabet=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
MyColors=['red','blue','darkblue','grey','maroon','teal','cornflowerblue','cornflowerblue','','','','']
MyBrowser=['User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3']
### ############################################################################################################
MyVideoLinkSrcMatches=['src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"' ,'src="(.+?)"' ,'src="(.+?)"', 'src="(.+?)"']
MyVideoLinkSrcMatchesB=['src="(.+?)"', '<embed.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"', '<iframe.+?src="(.+?)"' ,'src="(.+?)"' ,'src="(.+?)"', 'src="(.+?)"']
MyVideoLinkBrackets=['<iframe.+?src="(.+?)"', '<embed.+?src="(.+?)"', '<object.+?data="(.+?)"']
MyAlphabet= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
MyBrowser= ['User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3']
MySourcesV= ['videoweed.es', 'video44.net', 'novamov.com', 'dailymotion.com', 'videofun.me', 'yourupload.com', 'video.google.com', 'vidzur.com', 'upload2.com','putlocker.com','videoslasher.com','vidbull.com', 'uploadc.com', 'veevr.com', 'rutube.ru']
#MySourcesV= ['videoweed.es', 'video44.net', 'novamov.com', 'dailymotion.com', 'videofun.me', 'yourupload.com', 'video.google.com', 'vidzur.com', 'upload2.com','putlocker.com','videoslasher.com','vidbull.com', 'UploadC', 'veevr.com', 'rutube.ru', 'MP4UPLOAD' ,'AUENGINE']
MyIconsV= [artPath + 'videoweed.jpg', artPath + 'video44a.png', artPath + 'novamov.jpg', artPath + 'dailymotion.jpg', artPath + 'videofun.png', artPath + 'yourupload.jpg', artPath + 'googlevideo.gif', artPath + 'vidzur.png', artPath + 'upload2.png', artPath + 'putlocker.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png', artPath + 'BLANK.png']#BLANK.png
MyNamesV= ['VideoWeed', 'Video44', 'NovaMov', 'DailyMotion', 'VideoFun', 'YourUpload', 'Google Video', 'VidZur', 'Upload2', 'PutLocker', 'VideoSlasher', 'VidBull', 'UploadC', 'Veevr', 'RuTube', 'MP4Upload' ,'AUEngine']
MyColorsV= ['lime', 'red', 'silver', 'green', 'cyan', 'grey', 'blue', 'orange', 'white', 'white', 'white', 'white', 'white', 'white', 'white', 'white', 'white', 'white', 'white']
### ############################################################################################################
### ############################################################################################################
def getURLr(url,dReferer):
try:
req=urllib2.Request(url,dReferer)
req.add_header(MyBrowser[0],MyBrowser[1])
req.add_header('Referer',dReferer)
response=urllib2.urlopen(req)
link=response.read()
response.close()
return(link)
except urllib2.URLError, e: debob(e); debob(url); return('none');
except Exception, e: debob(e); debob(url); return('none');
except: return('none')
def getURL(url):
try:
req=urllib2.Request(url)
req.add_header(MyBrowser[0],MyBrowser[1])
response=urllib2.urlopen(req)
link=response.read()
response.close()
return(link)
except urllib2.URLError, e: debob(e); debob(url); return('none');
except Exception, e: debob(e); debob(url); return('none');
except: return('none');
def postURL(url,postStr):
postData=urllib.urlencode(postStr)
req=urllib2.Request(url,postData)
req.add_header(MyBrowser[0],MyBrowser[1])
response=urllib2.urlopen(req)
link=response.read()
response.close()
return(link)
def notification(header="", message="", sleep=5000 ):
xbmc.executebuiltin( "XBMC.Notification(%s,%s,%i)" % ( header, message, sleep ) )
#notify(msg=message, title=header, delay=sleep, image=ICON)
#notify(msg=message, title='[COLOR green][B]'+header+'[/B][/COLOR]', delay=sleep, image=ICON0)
### ############################################################################################################
##Example##VaddDir('[COLOR blue]' + text[0] + '[/COLOR]', '', 0, '', False)
def addFolder(name,name2,url,type2,mode,iconimage,categoryA='Blank'):
###addDir(name,name2,url,type2,mode,iconimage,fanimage)
if ('http://' in iconimage) or (artPath in iconimage): t=''
else: iconimage = artPath + iconimage
mainSite='http://'+SiteBits[type2]+'/'
addDir(name,name2,mainSite + url,type2,mode,iconimage,fanart,categoryA)
#addDirD(name,name2,mainSite + url,type2,mode,artPath + iconimage,fanart,'wow')
### from videolinks.py ###
#def addFolder(name,name2,url,type2,mode,iconimage):
# ##addDir(name,name2,url,type2,mode,iconimage,fanimage)
# addDir(name,name2,mainSite + url,type2,mode,artPath + iconimage,fanart)
def addDirF(name,name2,url,favcmd,type2=0,mode=0,iconimage=ICON0,fanimage=fanart0,categoryA='Blank'):
if (debugging==True): print 'Category: ',category,categoryA
categoryA=category+' ::: '+categoryA
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&nm="+urllib.quote_plus(name2)+"&tp="+str(type2)+"&scr="+urllib.quote_plus(iconimage)+"&fan="+urllib.quote_plus(fanimage)+"&show="+urllib.quote_plus(name2)+"&cat="+categoryA+'&fav='+favcmd
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name } )
liz.setProperty( "Fanart_Image", fanimage )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
return ok
def addDir(name,name2,url,type2,mode,iconimage,fanimage,categoryA='Blank'):
if (debugging==True): print 'Category: ',category,categoryA
categoryA=category+' ::: '+categoryA
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&nm="+urllib.quote_plus(name2)+"&tp="+str(type2)+"&scr="+urllib.quote_plus(iconimage)+"&fan="+urllib.quote_plus(fanimage)+"&show="+urllib.quote_plus(name2)+"&cat="+categoryA
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name } )
liz.setProperty( "Fanart_Image", fanimage )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
return ok
def addDirD(name,name2,url,type2,mode,iconimage,fanimage,doSorting=False,categoryA='Blank',Labels='none'):#,plot='Blank',genres='none listed',status='none',released='unknown',rating='none',others='none'):
if Labels=='none': Labels={ "Title" : name }
if categoryA=='Blank': categoryA=name
#if (debugging==True): print 'Category: ',category,categoryA
categoryA=category+' ::: '+categoryA
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&nm="+urllib.quote_plus(name2)+"&tp="+str(type2)+"&scr="+urllib.quote_plus(iconimage)+"&fan="+urllib.quote_plus(fanimage)+"&show="+urllib.quote_plus(name2)+"&cat="+urllib.quote_plus(categoryA)
#
if (debugging==True): print u
vc_tag=visited_DoCheck(u)
#if (name=='Maburaho'): visited_add(u)
if (debugging==True): print vc_tag
#
ok=True
liz=xbmcgui.ListItem(vc_tag+name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels= Labels ) #"Title": "'" + name + "'", "Plot" : plot, "Genres" : genres } )
liz.setProperty( "Fanart_Image", fanimage )
sysname = urllib.quote_plus(name)
sysurl = urllib.quote_plus(url)
sysscr = urllib.quote_plus(iconimage)
sysfan = urllib.quote_plus(fanimage)
#handle adding context menus
contextMenuItems = []
if (debugging==True): print getsetbool('enable-showurl')
if __settings__.getSetting("enable-showurl") == "true":#doesn't work for some odd reason >> #if getsetbool('enable-showurl') == 'true':#
contextMenuItems.append(('[B][COLOR orange]Show[/COLOR][/B] ~ [B]URL[/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s)' % (sys.argv[0],mode , sysname, urllib.quote_plus(name2), type2, 'showurl', sysurl, sysscr, sysfan)))
contextMenuItems.append(('[B][COLOR green]ADD[/COLOR][/B] ~ [B][COLOR tan]Favorite[/COLOR][/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s&show=%s)' % (sys.argv[0],mode , sysname, urllib.quote_plus(name2), type2, 'add', sysurl, sysscr, sysfan,urllib.quote_plus(name2))))
contextMenuItems.append(('[B][COLOR red]REMOVE[/COLOR][/B] ~ [B][COLOR tan]Favorite[/COLOR][/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s&show=%s)' % (sys.argv[0],mode , sysname, urllib.quote_plus(name2), type2, 'rem', sysurl, sysscr, sysfan,urllib.quote_plus(name2))))
contextMenuItems.append(('Show Information', 'XBMC.Action(Info)'))
#
#contextMenuItems.append(('[B][COLOR orange]Test[/COLOR][/B] ~ [B]Test[/B]',"notification(%s,%s)" % (sysname,sysurl)))
if (debugging==True): print getset('enable-clearfavorites')
if __settings__.getSetting("enable-clearfavorites") == "true":#if getset('enable-clearfavorites')==True:
contextMenuItems.append(('[B][COLOR yellow]Clear[/COLOR][/B] ~ [B][COLOR tan]Favorites[/COLOR][/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s)' % (sys.argv[0],mode , sysname, urllib.quote_plus(name2), type2, 'clr', sysurl, sysscr, sysfan)))
liz.addContextMenuItems(contextMenuItems, replaceItems=False)#True#liz.addContextMenuItems(contextMenuItems)
if doSorting==True:
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_TITLE)
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
return ok
def addDirV(name,name2,url,type2,mode,iconimage,fanimage,categoryA=''):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&nm="+urllib.quote_plus(name2)+"&tp="+str(type2)+"&cat="+categoryA
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name } )
liz.setProperty( "Fanart_Image", fanimage )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
return ok
#def VaddDir(name, url, mode, iconimage, fanimage, is_folder=False,categoryA=''):#VANILLA ADDDIR (kept for reference)
# u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&cat="+categoryA
# ok=True
# liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
# liz.setInfo( type="Video", infoLabels={ "Title": name } )
# liz.setProperty( "Fanart_Image", fanimage )
# ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=is_folder)
# return ok
def VaddDir(name, url, mode, iconimage, fanimage, is_folder=False,categoryA=''):#VANILLA ADDDIR (kept for reference)
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&cat="+categoryA
#if (debugging==True): print u
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name } )
liz.setProperty( "Fanart_Image", fanimage )
contextMenuItems = []
if __settings__.getSetting("enable-showurl") == "true":
contextMenuItems.append(('[B][COLOR orange]Show[/COLOR][/B] ~ [B]URL[/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s)' % (sys.argv[0],mode , urllib.quote_plus(name), urllib.quote_plus(name), 877, 'showurl', urllib.quote_plus(url), urllib.quote_plus(iconimage), urllib.quote_plus(fanimage))))
liz.addContextMenuItems(contextMenuItems, replaceItems=True)#True#liz.addContextMenuItems(contextMenuItems)
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=is_folder)
return ok
### from theanimehighway.py ###
#def addLink(name,url,iconimage):
# ok=True
# liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
# liz.setInfo( type="Video", infoLabels={ "Title": name } )
# ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
# return ok
def addLink(name,url,iconimage=ICON,fanimage=fanart,shoname='none',downloadable=True):
ok=True
if shoname=='none':
try: shoname=show
except: shoname=name
if fanimage==fanart:
try: fanimage=imgfan
except: pass
if iconimage in MyIconsV:
try:
iconimage=scr
except: pass
#
#liz=xbmcgui.ListItem(name, iconImage=artPath+"blank.gif", thumbnailImage=iconimage)
liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
##if (debugging==True): print 'sitename name: '+SiteNames[type2] + name
##liz.setInfo( type="Video", infoLabels={ "Title": name } )
Studio=name
if (' - [COLOR grey]' in Studio): Studio = Studio.split(' - [COLOR grey]')[0]
if (' [COLOR grey]- ' in Studio): Studio = Studio.split(' [COLOR grey]- ')[0]
if ('[COLOR grey] - ' in Studio): Studio = Studio.split('[COLOR grey] - ')[0]
if (' - [COLOR' in Studio): Studio = Studio.split(' - [COLOR')[0]
showtitle=shoname
if (' [COLOR lime](English Dubbed)[/COLOR]' in showtitle):
Studio += ' [COLOR lime](English Dubbed)[/COLOR]'
showtitle = showtitle.replace(' [COLOR lime](English Dubbed)[/COLOR]','')
elif ('English Dubbed' in showtitle): Studio += ' [COLOR lime](English Dubbed)[/COLOR]'
elif ('Eng Dubbed' in showtitle): Studio += ' [COLOR lime](English Dubbed)[/COLOR]'
elif ('Dubbed' in showtitle): Studio += ' [COLOR lime](Dubbed)[/COLOR]'
elif ('English Subbed' in showtitle): Studio += ' [COLOR lime](English Subbed)[/COLOR]'
elif ('Eng Subbed' in showtitle): Studio += ' [COLOR lime](English Subbed)[/COLOR]'
elif ('Subbed' in showtitle): Studio += ' [COLOR lime](Subbed)[/COLOR]'
liz.setInfo( type="Video", infoLabels={ "Title": showtitle, "Studio": Studio } )
#liz.setProperty( "Fanart_Image", fanimage )
contextMenuItems = []
if (debugging==True): print getset('enable-showurl')
if __settings__.getSetting("enable-showurl") == "true":#if getset('enable-showurl')=='true':
contextMenuItems.append(('[B][COLOR orange]Show[/COLOR][/B] ~ [B]URL[/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s)' % (sys.argv[0],0 , urllib.quote_plus(shoname), urllib.quote_plus(shoname), 0, 'showurl', urllib.quote_plus(url), iconimage, fanimage)))
if (__settings__.getSetting("enable-downloading") == "true") and (downloadable == True):#if getset('enable-downloading',True)=='True':
#if ('videofun.me' not in url) and ('videoweed.es' not in url) and ('dailymotion.com' not in url):
if ('novamov.com' not in url) and ('videoweed.es' not in url) and ('dailymotion.com' not in url):
contextMenuItems.append(('[B][COLOR purple]Download[/COLOR][/B] ~ [B]File[/B]', 'XBMC.RunPlugin(%s?mode=%s&name=%s&nm=%s&tp=%s&fav=%s&url=%s&scr=%s&fan=%s)' % (sys.argv[0],0 , urllib.quote_plus(shoname), urllib.quote_plus(shoname), 0, 'download', urllib.quote_plus(url), iconimage, fanimage)))
liz.addContextMenuItems(contextMenuItems, replaceItems=True)#True#liz.addContextMenuItems(contextMenuItems)
##liz.addContextMenuItems([('[B][COLOR green]D[/COLOR][/B][B]ownload[/B]',"downloadfile(url,name)")])
#liz.addContextMenuItems([('[B][COLOR green]D[/COLOR][/B][B]ownload[/B]',"XBMC.RunPlugin(%s?mode=%s&name=%s&url=%s)"%(sys.argv[0],999,name,url))])
##xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_LABEL)
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
return ok
### ############################################################################################################
def getset(idSetting):#,defaultValue=''):#Addon.getSetting('idNameOfSetting')
return __settings__.getSetting(idSetting)#==defaultValue
def getsetbool(idSetting):#Addon.getSetting('idNameOfSetting') #Method seems to be an utter failure for BOOL(true/false)'s
#if (debugging==True): print __settings__.getSetting(idSetting) == 'true'
return __settings__.getSetting(idSetting) == 'true'
def getsetbool_(idSetting):#Addon.getSetting('idNameOfSetting') #Method seems to be an utter failure for BOOL(true/false)'s
#if (debugging==True): print __settings__.getSetting(idSetting) == 'true'
#try: tst=__settings__.getSetting(idSetting) == 'true'
try: tst=__settings__.getSetting(idSetting)
except: tst='False'
if (tst=='true') or (tst=='True') or (tst=='TRUE'): return True
else: return False
#return __settings__.getSetting(idSetting) == 'true'
### ############################################################################################################
def download_it_now(url,name):## mode=1901 ##
name=name.strip()
if ('[/COLOR]' in name): name=name.replace('[/COLOR]','')
if ('[COLOR lime]' in name): name=name.replace('[COLOR lime]','')
if ('[/color]' in name): name=name.replace('[/color]','')
if ('[color lime]' in name): name=name.replace('[color lime]','')
#if ('' in name): name=name.replace('','')
#if ('' in name): name=name.replace('','')
#if ('' in name): name=name.replace('','')
notification(name,'Attempting Download...')
download_file_prep(url,name,name,name)
## Example of how to connect to this addon's download feature from another plugin: ##
#### xbmc.executebuiltin('XBMC.RunPlugin(%s?mode=1901&url=%s&name=%s)' % ('plugin://plugin.video.theanimehighway/', urllib.quote_plus(stream_url), urllib.quote_plus(title)))
#### Simply make sure to include the quoted name and url for this function to work.
#### File must be for a downloadable file or video stream, not for a page with a video on it.
def download_metapack(url, dest, displayname=False):
print 'Downloading Metapack'
print 'URL: %s' % url
print 'Destination: %s' % dest
if not displayname:
displayname = url
dlg = xbmcgui.DialogProgress()
dlg.create('Downloading', '', displayname)
start_time = time.time()
if os.path.isfile(dest):
print 'File to be downloaded already esists'
return True
try:
urllib.urlretrieve(url, dest, lambda nb, bs, fs: _pbhook(nb, bs, fs, dlg, start_time))
except:
#only handle StopDownloading (from cancel),
#ContentTooShort (from urlretrieve), and OS (from the race condition);
#let other exceptions bubble
if sys.exc_info()[0] in (urllib.ContentTooShortError, StopDownloading, OSError):
return False
else:
raise
return True
###
### Dialog DialogBusy DialogButton Menu DialogContentSettings DialogContentMenu DialogExtendedProgressBar
### DialogFavourites DialogKaiToast DialogKeyboard DialogOK DialogProgress DialogVolumeBar DialogVideoScan
### DialogVideoInfo DialogTextViewer DialogSlider DialogSelect DialogSeekBar DialogYesNo
###
def download_file(url='',name='temp',localfilename='temp',localpath=artPath,filext='.flv'):
t=''
###url='https://github.com/HIGHWAY99/plugin.video.theanimehighway/archive/master.zip'
###localfilename='plugin.video.theanimehighway.zip'
###localpath=__home__
#localfilewithpath=os.path.join(localpath,localfilename)
#if (debugging==True): print 'Attempting to download "' + localfilename + '" to "' + localfilewithpath + '" from: ' + url
###dialogbox('To: ' + localfilewithpath,'Download File: ' + localfilename,'From: ' + url,'[COLOR red]This is still being tested.[/COLOR]')
#if os.path.isfile(localfilewithpath):
# if (debugging==True): print 'File to be downloaded already esists.'
# notification('Download: '+localfilename,'File already exists.')#This function may never happen.
# return
#dialog = xbmcgui.Dialog()
#if dialog.yesno('Download File', 'Do you wish to download this file?','File: ' + localfilename,'To: ' + localpath):
# notification('Attempting to Download File',localfilename + '[CR] This function is still being tested.')#This function may never happen.
# try: dp = xbmcgui.DialogProgressBG() ## Only works on daily build of XBMC.
# except: dp = xbmcgui.DialogProgress()
# dp.create('Downloading', '', localfilename)
# ####
# ####urllib.urlretrieve(url, dest, lambda nb, bs, fs: _pbhookb(nb, bs, fs, dlg, start_time))
# ####
# urllib.urlretrieve(url, localfilewithpath, lambda nb, bs, fs: _pbhookb(nb, bs, fs, dlg, start_time))
# #urllib.urlretrieve(url, localfilewithpath)
# notification('Download File','Download Complete.[CR] ' + localfilename,15000)
# dialogbox_ok('File Size: ' + str(os.path.getsize(localfilewithpath)) + ' (bytes)','Download Complete','Note:','Make sure the size seems right.')
# ###total_size += os.path.getsize(fp)
###
###
###notification('Download File','Sorry this feature is not yet implimented.')#This function may never happen.
def _pbhookb(numblocks, blocksize, filesize, dlg, start_time):
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)
mbs = '%.02f MB of %.02f MB' % (currently_downloaded, total)
est = 'Speed: %.02f Kb/s ' % kbps_speed
est += 'ETA: %02d:%02d' % divmod(eta, 60)
dlg.update(percent, mbs, est)
except:
percent = 100
dlg.update(percent)
#if dlg.iscanceled(): ## used for xbmcgui.DialogProgress() but causes an error with xbmcgui.DialogProgressBG()
# dlg.close()
# raise StopDownloading('Stopped Downloading')
def download_file_frodo(url='',name='temp',localfilename='temp',localpath=artPath,filext='.flv'):
localfilewithpath=os.path.join(localpath,localfilename)
if (debugging==True): print 'Attempting to download "' + localfilename + '" to "' + localfilewithpath + '" from: ' + url
#dialogbox('To: ' + localfilewithpath,'Download File: ' + localfilename,'From: ' + url,'[COLOR red]This is still being tested.[/COLOR]')
if os.path.isfile(localfilewithpath):
if (debugging==True): print 'File to be downloaded already esists.'
notification('Download: '+localfilename,'File already exists.')#This function may never happen.
return
dialog = xbmcgui.Dialog()
if dialog.yesno('Download File', 'Do you wish to download this file?','File: ' + localfilename,'To: ' + localpath):
notification('Attempting to Download File',localfilename + '[CR] This function is still being tested.')#This function may never happen.
dp = xbmcgui.DialogProgress()
dp.create('Downloading', '', localfilename)
start_time = time.time()
urllib.urlretrieve(url, localfilewithpath, lambda nb, bs, fs: _pbhookb_frodo(nb, bs, fs, dp, start_time)) #urllib.urlretrieve(url, localfilewithpath)
##urllib.urlretrieve(url, localfilewithpath, lambda nb, bs, fs: _pbhookb_frodo(nb, bs, fs, dlg, start_time)) #urllib.urlretrieve(url, localfilewithpath)
notification('Download File','Download Complete.[CR] ' + localfilename,15000)
dialogbox_ok('File Size: ' + str(os.path.getsize(localfilewithpath)) + ' (bytes)','Download Complete','Note:','Make sure the size seems right.')
#total_size += os.path.getsize(fp)
#notification('Download File','Sorry this feature is not yet implimented.')#This function may never happen.
def _pbhookb_frodo(numblocks, blocksize, filesize, dlg, start_time):
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)
mbs = '%.02f MB of %.02f MB' % (currently_downloaded, total)
est = 'Speed: %.02f Kb/s ' % kbps_speed
est += 'ETA: %02d:%02d' % divmod(eta, 60)
dlg.update(percent, mbs, est)
except:
percent = 100
dlg.update(percent)
if dlg.iscanceled(): ## used for xbmcgui.DialogProgress() but causes an error with xbmcgui.DialogProgressBG()
dlg.close()
raise StopDownloading('Stopped Downloading')
def filename_filter_out_year(name=''):
years=re.compile(' \((\d+)\)').findall('__'+name+'__')
for year in years:
name=name.replace(' ('+year+')','')
name=name.strip()
return name
def filename_filter_colorcodes(name=''):
if ('[/color]' in name): name=name.replace('[/color]','')
if ('[/COLOR]' in name): name=name.replace('[/COLOR]','')
if ('[color lime]' in name): name=name.replace('[color lime]','')
if ('[COLOR lime]' in name): name=name.replace('[COLOR lime]','')
if ('[COLOR green]' in name): name=name.replace('[COLOR green]','')
if ('[COLOR yellow]' in name): name=name.replace('[COLOR yellow]','')
if ('[COLOR red]' in name): name=name.replace('[COLOR red]','')
if ('[b]' in name): name=name.replace('[b]','')
if ('[B]' in name): name=name.replace('[B]','')
if ('[/b]' in name): name=name.replace('[/b]','')
if ('[/B]' in name): name=name.replace('[/B]','')
if ('[cr]' in name): name=name.replace('[cr]','')
if ('[CR]' in name): name=name.replace('[CR]','')
if ('[i]' in name): name=name.replace('[i]','')
if ('[I]' in name): name=name.replace('[I]','')
if ('[/i]' in name): name=name.replace('[/i]','')
if ('[/I]' in name): name=name.replace('[/I]','')
if ('[uppercase]' in name): name=name.replace('[uppercase]','')
if ('[UPPERCASE]' in name): name=name.replace('[UPPERCASE]','')
if ('[lowercase]' in name): name=name.replace('[lowercase]','')
if ('[LOWERCASE]' in name): name=name.replace('[LOWERCASE]','')
name=name.strip()
#if ('' in name): name=name.replace('','')
#if ('' in name): name=name.replace('','')
#if ('' in name): name=name.replace('','')
return name
def Download_PrepExt(url,ext='.flv'):
if '.zip' in url: ext='.zip' #Compressed Files
elif '.rar' in url: ext='.rar'
elif '.z7' in url: ext='.z7'
elif '.png' in url: ext='.png' #images
elif '.jpg' in url: ext='.jpg'
elif '.gif' in url: ext='.gif'
elif '.bmp' in url: ext='.bmp'
elif '.jpeg' in url: ext='.jpeg'
elif '.mp4' in url: ext='.mp4' #Videos
elif '.mpeg' in url: ext='.mpeg'
elif '.avi' in url: ext='.avi'
elif '.flv' in url: ext='.flv'
elif '.wmv' in url: ext='.wmv'
elif '.mp3' in url: ext='.mp3' #others
elif '.txt' in url: ext='.txt'
#else: ext='.flv' #Default File Extention ('.flv')
return ext
def download_file_prep(url,name='none',name2='none',show='none',filext='none'):
#
if filext=='none':
if '.zip' in url: filext='.zip' #Compressed Files
elif '.rar' in url: filext='.rar'
elif '.z7' in url: filext='.z7'
elif '.png' in url: filext='.png' #images
elif '.jpg' in url: filext='.jpg'
elif '.gif' in url: filext='.gif'
elif '.mp4' in url: filext='.mp4' #Videos
elif '.mpeg' in url: filext='.mpeg'
elif '.avi' in url: filext='.avi'
elif '.flv' in url: filext='.flv'
elif '.wmv' in url: filext='.wmv'
elif '.mp3' in url: filext='.mp3' #others
elif '.txt' in url: filext='.txt'
else: filext='.flv' #Default File Extention ('.flv')
try: name=filename_filter_colorcodes(name)
except: name=''
try: name2=filename_filter_colorcodes(name2)
except: name2=name
try: show=filename_filter_colorcodes(show)
except: show=name
filname = name + filext
dialog = xbmcgui.Dialog()
if dialog.yesno('Local Path', 'Where would you like to download to?', '', filname, 'Shows', 'Movies'):
localpath = getset('folder-movie')#__settings__.getSetting('folder-movie')
else:
localpath = getset('folder-show')#__settings__.getSetting('folder-show')
if (debugging==True): print localpath
#download_file(url,name,filname,localpath) ## For nightly builds 13.x+
download_file_frodo(url,name,filname,localpath) ## For Frodo builds 12.x
#
#def downloadfile(url,name):
# import SimpleDownloader as downloader
# downloader = downloader.SimpleDownloader()
# url='http://www.xbmcswift.com/en/develop/api.html'
# dlfold='/tmp'
# #dlfold='F:\\xbmc\\theanimehighway\\'
# params = { "url": url, "download_path": dlfold, "Title": name }
# #params = { "url": url, "download_path": "F:\\xbmc\\theanimehighway\\", "Title": name, "live": "true", "duration": "20" }
# filenm = name + ".txt"
# #filenm = name + ".mp4"
# notification('file download: ' + name, 'Downloading "' + url + '" to "' + filenm + '"')
# downloader.download(filenm, params)
### ############################################################################################################
#def dialogboxyesno(txtMessage="",txtHeader="",txt3="",txt4=""):
# dialog = xbmcgui.Dialog()
# if dialog.yesno(txtHeader, txtMessage, txt3, txt4):
def dialogbox_ok(txtMessage="",txtHeader="",txt3="",txt4=""):
dialog = xbmcgui.Dialog()
ok = dialog.ok(txtHeader, txtMessage, txt3, txt4)
#keyboard = xbmc.Keyboard(txtMessage, txtHeader, passwordField)#("text to show","header text", True="password field"/False="show text")
#import win64clipboard as wc
def copy_to_clipboard(msg):
notification('Copy-to-Clipboard','Sorry this feature is not yet implimented.')
#
#
#if sys.platform == 'win32':
# wc.OpenClipboard()
# wc.EmptyClipboard()
# wc.SetClipboardData(win32con.CF_TEXT, msg)
# wc.CloseClipboard()
#
#
def showkeyboard(txtMessage="",txtHeader="",passwordField=False):
if txtMessage=='None': txtMessage=''
keyboard = xbmc.Keyboard(txtMessage, txtHeader, passwordField)#("text to show","header text", True="password field"/False="show text")
keyboard.doModal()
if keyboard.isConfirmed():
return keyboard.getText()
else:
return False # return ''
def dialogbox_number(Header="",n='',type=0):
#Types: #0 : ShowAndGetNumber #1 : ShowAndGetDate #2 : ShowAndGetTime #3 : ShowAndGetIPAddress dialog = xbmcgui.Dialog()
dlg=xbmcgui.Dialog()
if (n==''): r=dlg.numeric(1,Header)
else: r=dlg.numeric(1,Header,n)
return r
### ############################################################################################################
def checkForPartNo(url,partInfo=''):
url=urllib.unquote_plus(url)
if '_part_' in urllib.unquote_plus(url):
try:
matchaptn=re.compile('_part_(.+?).').findall(url)
partInfo=' - Part # ' + matchaptn[0]
except:
partInfo=' - Part # ' + 'Unknown'
elif '-part-' in urllib.unquote_plus(url):
try:
matchaptn=re.compile('-part-(.+?).').findall(url)
partInfo=' - Part # ' + matchaptn[0]
except:
partInfo=' - Part # ' + 'Unknown'
elif 'part' in urllib.unquote_plus(url):
try:
matchaptn=re.compile('part(.+?).').findall(url)
partInfo=' - Part # ' + matchaptn[0]
except:
temp=''
return partInfo
### ############################################################################################################
def aSortMeth(sM,h=int(sys.argv[1])):
xbmcplugin.addSortMethod(handle=h, sortMethod=sM)
def set_view(content='none',view_mode=50,do_sort=False):
if (debugging==True): print 'content type: ',content
if (debugging==True): print 'view mode: ',view_mode
h=int(sys.argv[1])
#try: h=int(sys.argv[1])
#except: h=_addon.handle
if (content is not 'none'): xbmcplugin.setContent(h, content)
#types: # set_view()
# 50 CommonRootView
# 51 FullWidthList
# 500 ThumbnailView
# 501 PosterWrapView
# 508 PosterWrapView2_Fanart
# 505 WideIconView
#
#
# set content type so library shows more views and info
if (tfalse(addst("auto-view"))==True):
xbmc.executebuiltin("Container.SetViewMode(%s)" % view_mode)
# set sort methods - probably we don't need all of them
#aSortMeth(xbmcplugin.SORT_METHOD_NONE)
aSortMeth(xbmcplugin.SORT_METHOD_UNSORTED)
aSortMeth(xbmcplugin.SORT_METHOD_TITLE)
aSortMeth(xbmcplugin.SORT_METHOD_TITLE_IGNORE_THE)
aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_TITLE)
aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE)
aSortMeth(xbmcplugin.SORT_METHOD_LABEL)
aSortMeth(xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_RATING)
aSortMeth(xbmcplugin.SORT_METHOD_DATE)
aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_YEAR)
#aSortMeth(xbmcplugin.SORT_METHOD_PROGRAM_COUNT)
aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)
aSortMeth(xbmcplugin.SORT_METHOD_GENRE)
#
aSortMeth(xbmcplugin.SORT_METHOD_FILE)
#aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)
#aSortMeth(xbmcplugin.SORT_METHOD_VIDEO_RATING)
#aSortMeth(xbmcplugin.SORT_METHOD_STUDIO)
#aSortMeth(xbmcplugin.SORT_METHOD_STUDIO_IGNORE_THE)
#aSortMeth(xbmcplugin.SORT_METHOD_PLAYLIST_ORDER)
aSortMeth(xbmcplugin.SORT_METHOD_EPISODE)
aSortMeth(xbmcplugin.SORT_METHOD_DURATION)
#aSortMeth(xbmcplugin.SORT_METHOD_BITRATE)
#
if (do_sort == True):
#aSortMeth(h, xbmcplugin.SORT_METHOD_TITLE)#xbmcplugin.SORT_METHOD_LABEL
xbmcplugin.addSortMethod(h, xbmcplugin.SORT_METHOD_TITLE)#xbmcplugin.SORT_METHOD_LABEL
#
####xbmcplugin.addSortMethod(handle=h, sortMethod=xbmcplugin.SORT_METHOD_TRACKNUM)
# #SORT_METHOD_NONE, SORT_METHOD_UNSORTED, SORT_METHOD_VIDEO_TITLE,
# # SORT_METHOD_TRACKNUM, SORT_METHOD_FILE, SORT_METHOD_TITLE
# # SORT_METHOD_TITLE_IGNORE_THE, SORT_METHOD_LABEL
# # SORT_METHOD_LABEL_IGNORE_THE, SORT_METHOD_VIDEO_SORT_TITLE,
# # SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE
### ############################################################################################################
### from theanimehighway.py ###
#def showurl(name,url,scr=ICON0,imgfan=fanart0,type2=0,mode=0):
# copy_to_clipboard(url)
# if (debugging==True): print url, name, scr, imgfan
# kmsg=showkeyboard(url, name)
def showurl(name,url,scr=ICON,imgfan=fanart,type2=0,mode=0):
copy_to_clipboard(url)
if (debugging==True): print url, name, scr, imgfan
kmsg=showkeyboard(url, name)
### ############################################################################################################
def metaArt_empty():
saved_fans = cache.get('MetaArt_')
fans = []
cache.set('MetaArt_', str(fans))
notification('[B][COLOR orange]Fanart[/COLOR][/B]','[B] Your Cached Fanart(s) Have Been Wiped Clean. Bye Bye.[/B]')
def emptyFavorites():
saved_favs = cache.get('favourites_')
favs = []
cache.set('favourites_', str(favs))
notification('[B][COLOR orange]Favorites[/COLOR][/B]','[B] Your Favorites Have Been Wiped Clean. Bye Bye.[/B]')
def addfavorite(name,url,scr=ICON0,imgfan=fanart0,tp2=0,mode=0):
if (debugging==True): print name,url,scr,imgfan,tp2,mode
saved_favs = cache.get('favourites_')
favs = []
if saved_favs:
favs = eval(saved_favs)
if favs:
if (name,url,scr,imgfan,tp2,mode) in favs:
notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] Already in your Favorites[/B]')
#xbmc.executebuiltin("XBMC.Notification([B][COLOR orange]"+name.upper()+"[/COLOR][/B],[B] Already in your Favourites[/B],5000,"")")
return
favs.append((name,url,scr,imgfan,tp2,mode))
cache.set('favourites_', str(favs))
notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] Added to Favorites[/B]')
#xbmc.executebuiltin("XBMC.Notification([B][COLOR orange]"+name.upper()+"[/COLOR][/B],[B] Added to Favourites[/B],5000,"")")
def removefavorite(name,url,scr=ICON0,imgfan=fanart0,tp2=0,mode=0):#,scr,imgfan
if (debugging==True): print name,url,scr,imgfan,tp2,mode
saved_favs = cache.get('favourites_')
if saved_favs:
favs = eval(saved_favs)
if (name,url,scr,imgfan,tp2,mode) in favs:
favs.remove((name,url,scr,imgfan,tp2,mode))
cache.set('favourites_', str(favs))
notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] Removed from Favorites[/B]')
if (debugging==True): print name+' Removed from Favorites.'
#set_view('tvshows',int(getset('viewmode-favs')),True)
#VaddDir('[COLOR maroon] Visit with [COLOR tan]Highway[/COLOR] and others @ [COLOR white]#XBMCHUB[/COLOR] on [COLOR white]irc.freenode.net[/COLOR]:6667 [/COLOR]', '', 0, ICON, fanart, False)
#LastPage=page_last_update()
#xbmc.executebuiltin("XBMC.Container.Update(%s)" % (LastPage))
xbmc.executebuiltin("XBMC.Container.Refresh")
#VaddDir('[COLOR maroon] Visit with [COLOR tan]Highway[/COLOR] and others @ [COLOR white]#XBMCHUB[/COLOR] on [COLOR white]irc.freenode.net[/COLOR]:6667 [/COLOR]', '', 0, ICON, fanart, False)
##xbmc.Container.Refresh
#xbmc.sleep(4000)
elif ((name) in favs):
favs.remove((name))
cache.set('favourites_', str(favs))
notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] Removed from Favorites[/B]')
if (debugging==True): print name+' Removed from Favorites. (Hopefully)'
xbmc.executebuiltin("XBMC.Container.Refresh")
elif favs:
tf=False
for (_name,_url,_scr,_imgfan,_tp2,_mode) in favs:
if (name==_name):
favs.remove((name,_url,_scr,_imgfan,_tp2,_mode))
cache.set('favourites_', str(favs))
notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] Removed from Favorites[/B]')
if (debugging==True): print name+' Removed from Favorites. (Hopefully)'
tf=True
xbmc.executebuiltin("XBMC.Container.Refresh")
return
if (tf==False): notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] not found in your Favorites[/B]')
else:
notification('[B][COLOR orange]'+name.upper()+'[/COLOR][/B]','[B] not found in your Favorites[/B]')
#xbmc.executebuiltin("XBMC.Notification([B][COLOR orange]"+name.upper()+"[/COLOR][/B],[B] Removed from Favourites[/B],5000,"")")
def metaArt_add(show_name,show_title_thetvdb,show_id,url_thetvdb,show_fanart,show_poster,show_bannner,show_desc,show_genres,show_status,show_language,show_network,show_rating):#metaArt_add(match_showname,match_showid,match_thetvdb_url,match_fanart,match_poster,match_banner)
##if (debugging==True): print name,url,scr,imgfan,tp2,mode
saved_fans = cache.get('MetaArt_')
fans = []
if saved_fans:
fans = eval(saved_fans)
if fans:
if (show_name,show_id,url_thetvdb,show_fanart,show_poster,show_bannner,show_desc) in fans:
#notification('[B][COLOR orange]'+show_name.upper()+'[/COLOR][/B]','[B] Already in your Cached Fanart(s).[/B]')
return
fans.append((show_name,show_title_thetvdb,show_id,url_thetvdb,show_fanart,show_poster,show_bannner,show_desc,show_genres,show_status,show_language,show_network,show_rating))
cache.set('MetaArt_', str(fans))
#notification('[B][COLOR orange]'+show_name.upper()+'[/COLOR][/B]','[B] Added to MetaArt[/B]')
##xbmc.executebuiltin("XBMC.Notification([B][COLOR orange]"+name.upper()+"[/COLOR][/B],[B] Added to Favourites[/B],5000,"")")
### ############################################################################################################
def getAlphaFolder(alphaTxt='',typeTxt='',slashTxt=''):
if type2==5: return 'subanime/'
#elif mode==211: return 'alpha-anime/'
#elif mode==311: return 'alpha-movies/'
else: return alphaTxt+typeTxt+slashTxt
def getAlphaEnd(typeTxt='',alphaTxt=''):
if (type2==5) and (typeTxt=='anime'): return '-2'
elif (type2==5) and (typeTxt=='movies'): return '-3'
else: return alphaTxt
def showlistdir(vLetterA,vLetterB,vImageC):#SitePrefixes#SiteSufixes
addFolder('[COLOR ' + MyColors[1] + ']' + vLetterB + '[/COLOR]','shows',getAlphaFolder('alpha-','anime','/') + vLetterA + getAlphaEnd('anime') + SiteSufixes[type2],type2,6,'Glossy_Black\\' + vImageC + '.png')
def movielistdir(vLetterA,vLetterB,vImageC):
addFolder('[COLOR ' + MyColors[1] + ']' + vLetterB + '[/COLOR]','movies',getAlphaFolder('alpha-','movies','/') + vLetterA + getAlphaEnd('movies') + SiteSufixes[type2],type2,6,'Glossy_Black\\' + vImageC + '.png')
### ############################################################################################################
def clean_filename(filename):
# filename = _1CH.unescape(filename)
return re.sub('[/:"*?<>|]+', ' ', filename)
def ParseDescription(plot): ## Cleans up the dumb number stuff thats ugly.
if ('&#' in plot) and (';' in plot):
if ("&" in plot): plot=plot.replace('&' ,'&')#&#x27;
if ("–" in plot): plot=plot.replace("–",";") #unknown
if ("‘" in plot): plot=plot.replace("‘","'")
if ("’" in plot): plot=plot.replace("’","'")
if ("“" in plot): plot=plot.replace('“','"')
if ("”" in plot): plot=plot.replace('”','"')
if ("×" in plot): plot=plot.replace('×' ,'x')
if ("'" in plot): plot=plot.replace(''' ,"'")
if ("ô" in plot): plot=plot.replace('ô' ,"o")
if ("·" in plot): plot=plot.replace('·' ,"-")
if ("û" in plot): plot=plot.replace('û' ,"u")
if ("à" in plot): plot=plot.replace('à' ,"a")
if ("ƥ" in plot): plot=plot.replace('ƥ',"")
if ("é" in plot): plot=plot.replace('é' ,"e")
if ("â" in plot): plot=plot.replace('â' ,"a")
if ('&#' in plot) and (';' in plot):
try: matches=re.compile('&#(.+?);').findall(plot)
except: matches=''
if (matches is not ''):
for match in matches:
if (match is not '') and (match is not ' ') and ("&#"+match+";" in plot): plot=plot.replace("&#"+match+";" ,"")
#if ("\xb7" in plot): plot=plot.replace('\xb7' ,"-")
#if ('&#' in plot) and (';' in plot): plot=unescape_(plot)
return plot
def unescape_(s):
p = htmllib.HTMLParser(None)
p.save_bgn()
p.feed(s)
return p.save_end()
def check_ifUrl_isHTML(pathUrl): ## Doesn't work yet. Needs Fixed.
######## 'http://s12.trollvid.net/videos/'+testString+'/'+vid_id1+'.mp4'
##timeout=10
##socket.setdefaulttimeout(timeout) # timeout in seconds
if (debugging==True): print 'TestingUrl: '+pathUrl
try:
req=urllib2.Request(pathUrl)#,timeout=6)
tUrl=urllib2.urlopen(req)
return True
except:
return False
### ############################################################################################################
def visited_DoCheck(urlToCheck,s='[B][COLOR yellowgreen]@[/COLOR][/B] ',e='[COLOR black]@[/COLOR] '):
#visited_empty()
#return ''
vc=visited_check(urlToCheck)
if (vc==True): return s
else:
##visited_add(urlToCheck)
return e
def visited_check(urlToCheck):
try: saved_visits = cache.get('visited_')
except: return False
erNoFavs='XBMC.Notification([B][COLOR orange]Favorites[/COLOR][/B],[B]You have no favorites saved.[/B],5000,"")'
if not saved_visits: return False #xbmc.executebuiltin(erNoFavs)
if saved_visits == '[]': return False #xbmc.executebuiltin(erNoFavs)
if saved_visits:
visits = eval(saved_visits)
if (urlToCheck in visits): return True
return False
def visited_empty():
saved_favs = cache.get('visited_')
favs = []
cache.set('visited_', str(favs))
notification('[B][COLOR orange]Visited[/COLOR][/B]','[B] Your Visited Data has been wiped clean. Bye Bye.[/B]')
def visited_add(urlToAdd):
if (urlToAdd==''): return ''
elif (urlToAdd==None): return ''
if (debugging==True): print 'checking rather url has been visited: ' + urlToAdd
saved_visits = cache.get('visited_')
visits = []
if saved_visits:
#if (debugging==True): print 'saved visits: ',saved_visits
visits = eval(saved_visits)
if visits:
if (urlToAdd) in visits: return
visits.append((urlToAdd))
cache.set('visited_', str(visits))
def qp_get(n): ## Deals with errors in using None type within a urllib.quote_plus().
#print n
if (n==''): return ''
elif (n==None): return ''
else: return urllib.quote_plus(n)
def st_get(n): ## Deals with errors in using None type within a str().
#print n
if (n==None): return ''
else: return str(n)
def page_last_get(defaultLastPage=sys.argv[0]+'?mode=0'):
try: last_visited = cache.get('lastpage')
except: return defaultLastPage