-
Notifications
You must be signed in to change notification settings - Fork 7
/
default.py
3442 lines (2371 loc) · 90.5 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
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
#
# Copyright (C) 2014-
# Sean Poyser (seanpoyser@gmail.com)
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with XBMC; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# http://www.gnu.org/copyleft/gpl.html
#
import xbmc
import xbmcaddon
import xbmcplugin
import xbmcgui
import os
import urllib
import re
import quicknet
import player
import favourite
import history
import utils
import cache
import sfile
import parameters
ADDONID = utils.ADDONID
ADDON = utils.ADDON
HOME = utils.HOME
ROOT = utils.ROOT
PROFILE = utils.PROFILE
VERSION = utils.VERSION
ICON = utils.ICON
FANART = utils.FANART
SEARCH = utils.SEARCH
BLANK = 'NULL'
GETTEXT = utils.GETTEXT
TITLE = utils.TITLE
FRODO = utils.FRODO
GOTHAM = utils.GOTHAM
HELIX = utils.HELIX
FILENAME = utils.FILENAME
FOLDERCFG = utils.FOLDERCFG
PLAYMEDIA_MODE = utils.PLAYMEDIA_MODE
ACTIVATEWINDOW_MODE = utils.ACTIVATEWINDOW_MODE
RUNPLUGIN_MODE = utils.RUNPLUGIN_MODE
ACTION_MODE = utils.ACTION_MODE
SHOWPICTURE_MODE = utils.SHOWPICTURE_MODE
MANUAL_CMD = 'SF_MANUAL_CMD_'
DISPLAYNAME = utils.DISPLAYNAME
# -----Addon Modes ----- #
_IGNORE = -10
_MAIN = -2
_SUPERSEARCH = 0 #also in capture.py
_SUPERSEARCHDEF = 10 #also in capture.py
_EXTSEARCH = 25 #used to trigger new Super Search from outside of addon
_SEPARATOR = 50
_SETTINGS = 100
_VIEWTYPE = 150
_ADDTOXBMC = 200
_ADDTOSF = 250
_COPYTOSF = 275
_XBMC = 300
_FOLDER = utils._FOLDER
_NEWFOLDER = 500
_PLAYMEDIA = 600
_ACTIVATEWINDOW = 650
_ACTIVATEWINDOW_XBMC = 660
_ACTIVATESEARCH = 675
_REMOVEFOLDER = 700
_REMOVEFAVE = 800
_RENAMEFOLDER = 900
_RENAMEFAVE = 1000
_THUMBFAVE = 1500
_THUMBFOLDER = 1600
_PLAYBACKMODE = 1700
_EDITTERM = 1900
_EDITFOLDER = 2000
_EDITFAVE = 2100
_SECURE = 2200
_UNSECURE = 2300
_PLAYLIST = 2400
_COLOURFOLDER = 2500
_COLOURFAVE = 2600
_RECOMMEND_KEY = 2700 #also in capture.py
_RECOMMEND_KEY_A = 2710
_RECOMMEND_IMDB = 2800
_PLAYTRAILER = 2900
_EDITSEARCH = 3000
_IMPORT = 3100
_IPLAY = 3200
_PLAYLISTFILE = 3300
_PLAYLISTITEM = 3400
_PLAYLISTBROWSE = 3500
_DELETEPLAYLIST = 3600
_COPY_PLAY_TO_SF = 3700
_COPY_PLAY_TO_SF_ITEM = 3800
_PLAYPLAYLIST = 3900
_URLPLAYLIST = 4000
_HISTORYSHOW = 4100
_HISTORYADD = 4200
_HISTORYREMOVE = 4300
_MANUAL = 4400
_CUT = 4500
_COPY = 4600
_PASTE = 4700
_CUTFOLDER = 4800
_COPYFOLDER = 4900
_PASTEFOLDER = 5000
_IEXPLORE = 5100
_PLAY_FILE = 5200
_PLAY_FOLDER = 5300
_PLAY_SUPER_FOLDER = 5400
_PLAY_SUPER_FOLDER_EXT = 5450
# --------------------- Addon Settings --------------------- #
SHOWNEW = ADDON.getSetting('SHOWNEW') == 'true'
SHOWIMPORT = ADDON.getSetting('SHOWIMPORT') == 'true'
SHOWSEP = ADDON.getSetting('SHOWSEP') == 'true'
SHOWSS = ADDON.getSetting('SHOWSS') == 'true'
CONTEXTSS = ADDON.getSetting('CONTEXTSS') == 'true'
SHOW_FANART = ADDON.getSetting('SHOW_FANART') == 'true'
SHOWRECOMMEND = ADDON.getSetting('SHOWRECOMMEND') == 'true'
PLAY_PLAYLISTS = ADDON.getSetting('PLAY_PLAYLISTS') == 'true'
METARECOMMEND = ADDON.getSetting('METARECOMMEND') == 'true'
SYNOPSRECOMMEND = ADDON.getSetting('SYNOPSRECOMMEND') == 'true'
RECOMMENDAUTO = ADDON.getSetting('RECOMMENDFIRST') == 'true'
CONTEXTRECOMMEND = ADDON.getSetting('CONTEXTRECOMMEND') == 'true'
REMOTE = ADDON.getSetting('REMOTE') == 'true'
SHOWIPLAY = ADDON.getSetting('SHOWIPLAY') == 'true'
SHOWIHISTORY = ADDON.getSetting('SHOWREMEMBER') == 'true'
SHOWIEXPLORE = ADDON.getSetting('SHOWIEXPLORE') == 'true'
COPY_PLAYLISTS = ADDON.getSetting('COPY_PLAYLISTS') == 'true'
ALLOW_PLAYLIST_DELETE = ADDON.getSetting('ALLOW_PLAYLIST_DELETE') == 'true'
DISABLEMOVIEVIEW = ADDON.getSetting('DISABLEMOVIEVIEW') == 'true'
DEBUG = ADDON.getSetting('DEBUG') == 'true'
DLG_MENU = ADDON.getSetting('CONTEXT_STYLE') == '1'
DEFAULT_FANART = ADDON.getSetting('DEFAULT_FANART')
SHOWXBMC = utils.SHOWXBMC
INHERIT = utils.INHERIT
ALPHA_SORT = utils.ALPHA_SORT
LABEL_NUMERIC = utils.LABEL_NUMERIC
if xbmcgui.getCurrentWindowId() == 10000:
LABEL_NUMERIC = False
TMDB_API_KEY='302783d0fefc7b8a97ab7cc7f42a2cde'
try: VIEWTYPE = int(ADDON.getSetting('VIEWTYPE'))
except: VIEWTYPE = 0
ART_LANDSCAPE = int(ADDON.getSetting('ART_LANDSCAPE'))
ART_BANNER = int(ADDON.getSetting('ART_BANNER'))
ART_POSTER = int(ADDON.getSetting('ART_POSTER'))
CONTENTTYPE = ADDON.getSetting('CONTENTTYPE')
CONTENTTYPES = {}
CONTENTTYPES[GETTEXT(35029)] = 'files'
CONTENTTYPES[GETTEXT(35030)] = 'songs'
CONTENTTYPES[GETTEXT(35031)] = 'artists'
CONTENTTYPES[GETTEXT(35032)] = 'albums'
CONTENTTYPES[GETTEXT(35033)] = 'movies'
CONTENTTYPES[GETTEXT(35034)] = 'tvshows'
CONTENTTYPES[GETTEXT(35035)] = 'episodes'
CONTENTTYPES[GETTEXT(35036)] = 'musicvideos'
CONTENTTYPES[GETTEXT(35037)] = ''
if ADDON.getSetting('SHOW_STARTUP_TXT') == 'true':
utils.DialogOK(ADDON.getSetting('STARTUP_TXT'))
ADDON.setSetting('SHOW_STARTUP_TXT', 'false')
if REMOTE:
LOCATION = len(ADDON.getSetting('LOCATION')) > 0
else:
LOCATION = False
if DEFAULT_FANART == '1':
FANART = ADDON.getSetting('DEFAULT_IMAGE')
if DEFAULT_FANART == '2':
FANART = BLANK
CONTENTMODE = False
ISEARCH_EMPTY = '__iSearch__'
NUMBER_SEP = utils.NUMBER_SEP
# ---------------------------------------------------------- #
utils.CheckVersion()
global nItem
nItem = 0
global separator
separator = False
global currentFolder
currentFolder = PROFILE
global addingMainItems
addingMainItems = False
def main():
global addingMainItems
addingMainItems = True
addMainItems()
addingMainItems = False
parseFolder(PROFILE)
def setViewType():
view = utils.getViewType()
if view == None:
return False
ADDON.setSetting('VIEWTYPE', str(view))
return True
def addSuperSearch():
global separator
if not SHOWSS:
return
separator = False
addDir(GETTEXT(30054), _SUPERSEARCH, thumbnail=SEARCH, isFolder=True, infolabels={'plot':GETTEXT(30195)})
separator = True
def addNewFolderItem(path):
global currentFolder
currentFolder = path
global separator
if SHOWNEW:
separator = False
addDir(GETTEXT(30004), _NEWFOLDER, path=path, thumbnail=ICON, isFolder=False, infolabels={'plot':GETTEXT(30199)})
separator = True
def addSeparatorItem(menu=None):
global separator
separator = False
if SHOWSEP:
addDir('', _SEPARATOR, thumbnail=BLANK, isFolder=False, menu=menu)
def populatePasteMenu(menu):
global currentFolder
type = xbmcgui.Window(10000).getProperty('SF_TYPE').lower()
if len(type) == 0:
return
if type == 'capture':
menu.append((GETTEXT(30258), 'XBMC.RunPlugin(%s?mode=%d&paste=%s)' % (sys.argv[0], _PASTE, urllib.quote_plus(currentFolder))))
return
folder = 'folder' in type
cut = 'cut' in type
src = xbmcgui.Window(10000).getProperty('SF_FOLDER')
if folder:
if cut and currentFolder == xbmcgui.Window(10000).getProperty('SF_FILE'):
return
menu.append((GETTEXT(30182), 'XBMC.RunPlugin(%s?mode=%d&paste=%s)' % (sys.argv[0], _PASTEFOLDER, urllib.quote_plus(currentFolder))))
return
if src == currentFolder:
return
menu.append((GETTEXT(30179), 'XBMC.RunPlugin(%s?mode=%d&paste=%s)' % (sys.argv[0], _PASTE, urllib.quote_plus(currentFolder))))
def addGlobalMenuItem(menu, item, ignore, label, thumbnail, u, keyword, fanart, meta):
if mode == _FOLDER or mode == _MAIN or mode == _XBMC:
populatePasteMenu(menu)
if not ignore:
try: addFavouriteMenuItem(menu, label, thumbnail, u, keyword, fanart, meta)
except: pass
if mode != _XBMC:
cmd = '%s?mode=%d' % (sys.argv[0], _XBMC)
label = GETTEXT(30040) % DISPLAYNAME
menu.append((label, 'XBMC.Container.Update(%s)' % cmd))
if mode == _FOLDER or mode == _MAIN:
path = thepath
if path == '':
path = PROFILE
menu.append((GETTEXT(30004), 'XBMC.RunPlugin(%s?mode=%d&path=%s)' % (sys.argv[0], _NEWFOLDER, urllib.quote_plus(path))))
menu.append((GETTEXT(30166), 'XBMC.RunPlugin(%s?mode=%d&path=%s)' % (sys.argv[0], _MANUAL, urllib.quote_plus(path))))
menu.append((GETTEXT(30204), 'XBMC.RunPlugin(%s?mode=%d)' % (sys.argv[0], _VIEWTYPE)))
menu.append((GETTEXT(30005), 'XBMC.RunPlugin(%s?mode=%d)' % (sys.argv[0], _SETTINGS)))
addon = utils.findAddon(item)
if addon == None or addon == ADDONID:
return
label = utils.getSettingsLabel(addon)
menu.append((label, 'XBMC.RunPlugin(%s?mode=%d&addon=%s)' % (sys.argv[0], _SETTINGS, urllib.quote_plus(addon))))
def addFavouriteMenuItem(menu, name, thumb, cmd, keyword, fanart, meta):
if mode == _XBMC:
return
if len(name) < 1:
return
#add iRecommend context menu item
if mode is not _SUPERSEARCH and not addingMainItems:
label = removeNumeric(name)
if utils.ADDON.getSetting('STRIPNUMBERS') == 'true':
label = utils.Clean(label)
prefix = GETTEXT(30268)
if label.startswith(prefix):
label = label[len(prefix):]
if CONTEXTSS:
menu.append((GETTEXT(30054), 'XBMC.Container.Update(%s?mode=%d&keyword=%s&image=%s&fanart=%s)' % (sys.argv[0], _SUPERSEARCH, urllib.quote_plus(label), urllib.quote_plus(thumb), urllib.quote_plus(fanart))))
if CONTEXTRECOMMEND:
menu.append((GETTEXT(30088), 'XBMC.Container.Update(%s?mode=%d&keyword=%s&image=%s&fanart=%s)' % (sys.argv[0], _RECOMMEND_KEY, urllib.quote_plus(label), urllib.quote_plus(thumb), urllib.quote_plus(fanart))))
label = GETTEXT(30006) % DISPLAYNAME
menu.append((label, 'XBMC.RunPlugin(%s?mode=%d&name=%s&thumb=%s&cmd=%s&keyword=%s)' % (sys.argv[0], _ADDTOXBMC, urllib.quote_plus(name), urllib.quote_plus(thumb), urllib.quote_plus(cmd), urllib.quote_plus(keyword))))
try: meta = urllib.quote_plus(utils.convertDictToURL(meta))
except: meta = ''
if not addableToSF():
return
menu.append((GETTEXT(30047), 'XBMC.RunPlugin(%s?mode=%d&name=%s&thumb=%s&cmd=%s&keyword=%s&meta=%s)' % (sys.argv[0], _ADDTOSF, urllib.quote_plus(name), urllib.quote_plus(thumb), urllib.quote_plus(cmd), urllib.quote_plus(keyword), meta)))
fave = convertSFToFave(name, thumb, cmd, keyword)
fave[2] = favourite.updateSFOption(fave[2], 'meta', meta)
menu.append((GETTEXT(30209), 'XBMC.RunPlugin(%s?mode=%d&name=%s&thumb=%s&cmd=%s&fanart=%s&meta=%s)' % (sys.argv[0], _COPYTOSF, urllib.quote_plus(fave[0]), urllib.quote_plus(fave[1]), urllib.quote_plus(fave[2]), urllib.quote_plus(fanart), meta)))
def addableToSF():
if mode == _SUPERSEARCH:
return True
if mode == _HISTORYSHOW:
return True
if mode == _RECOMMEND_KEY:
return True
if mode == _RECOMMEND_IMDB:
return True
if mode == _RECOMMEND_KEY_A:
return True
return False
def removeNumeric(text):
if not LABEL_NUMERIC:
return text
root = text.split(NUMBER_SEP, 1)[0]
if root.startswith('['):
root = root.rsplit(']', 1)[0] + ']'
else:
root = ''
return root + text.split(NUMBER_SEP, 1)[-1]
def convertSFToFave(name, thumb, cmd, keyword):
p = utils.get_params(cmd.replace('?', '&'))
name = removeNumeric(name)
try:
mode = int(p['mode'])
if mode == _FOLDER:
label = urllib.unquote_plus(p['label'])
path = urllib.unquote_plus(p['path'])
path = utils.convertToHome(path)
label = removeNumeric(label)
cmd = '%s?label=%s&mode=%d&path=%s' % (sys.argv[0], label, _FOLDER, urllib.quote_plus(path))
except:
mode = _IGNORE
cmd = '"%s"' % cmd
folder = mode == _FOLDER
search = mode == _SUPERSEARCH
edit = mode == _EDITTERM
activate = mode == _ACTIVATESEARCH
activateW = mode == _ACTIVATEWINDOW
recommend = mode == _RECOMMEND_KEY or mode == _RECOMMEND_IMDB
iPlay = mode == _IPLAY
history = mode == _HISTORYSHOW
playSF = mode == _PLAY_SUPER_FOLDER
isSF = cmd.startswith('"plugin://%s' % ADDONID)
isCached = False
if activateW:
isCached = utils.DialogYesNo(GETTEXT(30207))
try: fanart = urllib.unquote_plus(p['fanart'])
except: fanart = ''
if activate:
cmd = urllib.unquote_plus(p['cmd'])
elif isCached or playSF:
cmd = 'PlayMedia(%s)' % cmd
elif isSF:
cmd = cmd.replace('+', '%20')
cmd = 'ActivateWindow(%d,%s,return)' % (utils.getCurrentWindowId(), cmd)
if activateW:
cmd = cmd.replace('mode=%d' % _ACTIVATEWINDOW, 'mode=%d' % _ACTIVATEWINDOW_XBMC)
else:
fanart = ''
cmd = 'PlayMedia(%s)' % cmd
if search:
name = GETTEXT(30054)
if edit:
name = GETTEXT(30054)
cmd = cmd.replace('&mode=%d' % _EDITTERM, '&mode=%d' % _SUPERSEARCH)
if recommend:
name = GETTEXT(30088)
if search and ('keyword' not in cmd):
find = '&mode=%d' % _SUPERSEARCH
replace = '%s&keyword=%s' % (find, ISEARCH_EMPTY)
cmd = cmd.replace(find, replace)
if not cmd.lower().endswith(',return)'):
cmd = cmd[:-1] + ',return)'
if folder:
thumbnail, fanart = utils.getFolderThumb(path)
#cmd = favourite.addFanart(cmd, fanart)
cmd = favourite.addFanart(cmd, fanart)
keyword = urllib.unquote_plus(keyword)
if len(keyword) > 0:
name += ' - %s' % keyword
fave = [name, thumb, cmd]
return fave
def addToSF(name, thumb, cmd, keyword, meta):
text = GETTEXT(30019)
folder = utils.GetSFFolder(text)
if not folder:
return False
fave = convertSFToFave(name, thumb, cmd, keyword)
fave[2] = favourite.updateSFOption(fave[2], 'meta', urllib.quote_plus(meta))
file = os.path.join(folder, FILENAME)
#if it is already in there don't add again
if favourite.findFave(file, fave[2])[0]:
return False
return addToFile(fave, file)
def addToFile(fave, file):
cmd = fave[2]
#if it is already in there don't add again
if favourite.findFave(file, cmd)[0]:
return False
faves = favourite.getFavourites(file, validate=False)
faves.append(fave)
favourite.writeFavourites(file, faves)
return True
def addToXBMC(name, thumb, cmd, keyword):
fave = convertSFToFave(name, thumb, cmd, keyword)
file = os.path.join('special://profile', FILENAME)
return addToFile(fave, file)
def refresh():
xbmc.executebuiltin('Container.Refresh')
def removeAutoplay(path):
cfg = os.path.join(path, FOLDERCFG)
parameters.clearParam('AUTOPLAY', cfg)
refresh()
def addAutoplay(path):
cfg = os.path.join(path, FOLDERCFG)
parameters.setParam('AUTOPLAY', 'True', cfg)
refresh()
def showXBMCFolder():
global currentFolder
currentFolder = 'special://profile'
file = os.path.join(currentFolder, FILENAME)
parseFile(file)
def parseFile(file, sortorder=0, label_numeric=None, index=0):
if sortorder == 0:
sortorder = 1 if ALPHA_SORT else 2
global separator
faves = favourite.getFavourites(file)
if label_numeric == None:
label_numeric = LABEL_NUMERIC
text = GETTEXT(30099) % DISPLAYNAME if mode == _XBMC else GETTEXT(30068)
if sortorder == 1: #ALPHA_SORT:
faves = sorted(faves, key=lambda x: utils.CleanForSort(x))
for fave in faves:
utils.log(fave)
label = fave[0]
thumb = fave[1]
cmd = fave[2]
fanart = favourite.getFanart(cmd)
desc = favourite.getOption(cmd, 'desc')
meta = favourite.getOption(cmd, 'meta')
manualUnset = MANUAL_CMD in cmd
infolabel = utils.convertURLToDict(meta)
if len(desc) > 0:
infolabel['plot'] = urllib.unquote(desc)
menu = []
menu.append((text, 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s&name=%s&thumb=%s)' % (sys.argv[0], _EDITFAVE, urllib.quote_plus(file), urllib.quote_plus(cmd), urllib.quote_plus(label), urllib.quote_plus(thumb))))
if not PLAY_PLAYLISTS:
import playlist
if playlist.isPlaylist(cmd):
menu.append((GETTEXT(30084), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _PLAYLIST, urllib.quote_plus(file), urllib.quote_plus(cmd))))
menu.append((GETTEXT(30178), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _COPY, urllib.quote_plus(file), urllib.quote_plus(cmd))))
#menu.append((GETTEXT(30177), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _CUT, urllib.quote_plus(file), urllib.quote_plus(cmd))))
type = _ACTIVATEWINDOW
isFolder = True
if manualUnset:
type = _IGNORE
isFolder = False
elif 'playmedia(' in cmd.lower():
type = _PLAYMEDIA
isFolder = False
label, index = utils.addPrefixToLabel(index, label, label_numeric)
path = checkForSuperFolderLink(cmd)
if path:
addDir(label, _FOLDER, path=path, thumbnail=thumb, isFolder=True, menu=menu, fanart=fanart, infolabels=infolabel)
else:
addDir(label, type, cmd=cmd, thumbnail=thumb, isFolder=isFolder, menu=menu, fanart=fanart, infolabels=infolabel)
separator = len(faves) > 0
def checkForSuperFolderLink(cmd):
try:
if not cmd.startswith('ActivateWindow'):
return None
if 'plugin://plugin.program.super.favourites' not in cmd:
return None
params = utils.get_params(cmd)
mode = int(params['mode'])
if mode <> _FOLDER:
return None
if 'path' in params:
path = params['path'].replace('\\', '/')
if path.replace('\\', '/').startswith(PROFILE):
return path
if 'folder' in params:
folder = params['folder'].replace('\\', '/')
folder = os.path.join(PROFILE, folder)
return folder
except:
pass
return None
def addMainItems():
if mode != _MAIN:
return
global separator
addSuperSearch()
if SHOWIEXPLORE:
separator = False
folder = 'DefaultFolder.png'
addDir(GETTEXT(30225), _IEXPLORE, thumbnail=folder, isFolder=True, infolabels={'plot':GETTEXT(30227)})
separator = True
if SHOWIPLAY:
separator = False
thumbnail = 'DefaultVideoPlaylists.png'
fanart = ''
label = GETTEXT(30146) % DISPLAYNAME
addDir(label, _IPLAY, thumbnail=thumbnail, isFolder=True, fanart=fanart, infolabels={'plot':GETTEXT(30196)})
separator = True
addNewFolderItem(PROFILE)
if SHOWXBMC:
separator = False
thumbnail, fanart = utils.getFolderThumb(PROFILE, True)
label = GETTEXT(30040) % DISPLAYNAME
addDir(label, _XBMC, thumbnail=thumbnail, isFolder=True, fanart=fanart, infolabels={'plot':GETTEXT(30197)})
separator = True
if SHOWIMPORT and LOCATION:
separator = False
thumbnail = 'DefaultFile.png'
fanart = ''
addDir(GETTEXT(30125), _IMPORT, thumbnail=thumbnail, isFolder=False, fanart=fanart, infolabels={'plot':GETTEXT(30198)})
separator = True
def playSuperFolder(path, id):
if not path:
path = PROFILE
import locking
if not locking.unlock(path):
return
file = os.path.join(path, FILENAME)
faves = favourite.getFavourites(file)
if ALPHA_SORT:
faves = sorted(faves, key=lambda x: utils.CleanForSort(x))
items = []
for fave in faves:
label = fave[0]
thumb = fave[1]
cmd = fave[2]
try:
cmd = re.compile('"(.+?)"').search(cmd).group(1)
cmd = favourite.removeSFOptions(cmd)
items.append([label, cmd, thumb])
except:
pass
utils.log('Play Super Folder - Items')
utils.log(items)
utils.playItems(items, id)
def playFolder(folder):
if sfile.isfile(folder):
folder = sfile.getfolder(folder)
files = utils.parseFolder(folder, subfolders=False)
items = []
for file in files:
items.append([file[0], file[1]])
utils.playItems(items)
def playFile(filename):
#cmd = 'PlayMedia(%s)' % path
#xbmc.executebuiltin(cmd)
items = [[sfile.getfilename(filename), filename]]
utils.playItems(items)
def iExplore(path=None):
file = 'DefaultMovies.png'
folder = 'DefaultFolder.png'
if not path:
path = xbmcgui.Dialog().browse(3, GETTEXT(30226), 'files', '', False, False)
try: path = path.rsplit(os.sep, 1)[0] + os.sep
except: return
try: items = utils.parseFolder(path)
except: items = []
index = 0
for item in items:
label = item[0]
url = item[1].replace('\\', '/')
isFile = item[2]
title = label
label, index = utils.addPrefixToLabel(index, label)
menu = []
if isFile:
menu.append((GETTEXT(30230), 'XBMC.RunPlugin(%s?mode=%d&path=%s)' % (sys.argv[0], _PLAY_FOLDER, urllib.quote_plus(url))))
menu.append((GETTEXT(30047), 'XBMC.RunPlugin(%s?mode=%d&path=%s&label=%s&thumb=%s)' % (sys.argv[0], _COPY_PLAY_TO_SF_ITEM, urllib.quote_plus(url), urllib.quote_plus(title), urllib.quote_plus(file))))
addDir(label, _PLAY_FILE, path=url, thumbnail=file, isFolder=False, menu=menu, infolabels={'plot':GETTEXT(30229) % title})
else:
menu.append((GETTEXT(30231), 'XBMC.RunPlugin(%s?mode=%d&path=%s)' % (sys.argv[0], _PLAY_FOLDER, urllib.quote_plus(url))))
menu.append((GETTEXT(30047), 'XBMC.RunPlugin(%s?mode=%d&path=%s&label=%s&thumb=%s)' % (sys.argv[0], _COPY_PLAY_TO_SF, urllib.quote_plus(url), urllib.quote_plus(title), urllib.quote_plus(folder))))
addDir(label, _IEXPLORE, path=url, thumbnail=folder, isFolder=True, menu=menu, infolabels={'plot':GETTEXT(30228) % title})
def parseFolder(folder):
global separator
global currentFolder
currentFolder = folder
try: current, dirs, files = sfile.walk(folder)
except: return
dirs = sorted(dirs, key=str.lower)
folderConfig = os.path.join(folder, FOLDERCFG)
folderConfig = parameters.getParams(folderConfig)
label_numeric = parameters.getParam('NUMERICAL', folderConfig)
sortorder = parameters.getParam('SORT', folderConfig)
if label_numeric:
label_numeric = label_numeric.lower() == 'true'
else:
label_numeric = LABEL_NUMERIC
try: sortorder = int(sortorder)
except: sortorder = 0
index = 0
for dir in dirs:
path = os.path.join(current, dir)
folderConfig = os.path.join(path, FOLDERCFG)
visible = 'true' if DEBUG else parameters.getParam('VISIBLE', folderConfig)
if visible and visible.lower() == 'false':
continue
folderConfig = parameters.getParams(folderConfig)
lock = parameters.getParam('LOCK', folderConfig)
colour = parameters.getParam('COLOUR', folderConfig)
desc = parameters.getParam('DESC', folderConfig)
autoplay = parameters.getParam('AUTOPLAY', folderConfig)
meta = parameters.getParam('META', folderConfig)
infolabel = utils.convertURLToDict(meta)
if desc:
infolabel = {'plot':desc}
menu = []
menu.append((GETTEXT(30067), 'XBMC.RunPlugin(%s?mode=%d&path=%s&name=%s)' % (sys.argv[0], _EDITFOLDER, urllib.quote_plus(path), urllib.quote_plus(dir))))
if autoplay:
menu.append((GETTEXT(30235), 'XBMC.Container.Update(%s?mode=%d&path=%s)' % (sys.argv[0], _FOLDER, urllib.quote_plus(path))))
else:
menu.append((GETTEXT(30232), 'XBMC.RunPlugin(%s?mode=%d&path=%s)' % (sys.argv[0], _PLAY_SUPER_FOLDER, urllib.quote_plus(path))))
#if lock: #lock is now on Edit Super Folder menu
# menu.append((GETTEXT(30077), 'XBMC.RunPlugin(%s?mode=%d&path=%s&name=%s)' % (sys.argv[0], _UNSECURE, urllib.quote_plus(path), urllib.quote_plus(dir))))
#else:
# menu.append((GETTEXT(30076), 'XBMC.RunPlugin(%s?mode=%d&path=%s&name=%s)' % (sys.argv[0], _SECURE, urllib.quote_plus(path), urllib.quote_plus(dir))))
thumbnail, fanart = utils.getFolderThumb(path)
if not lock:
menu.append((GETTEXT(30181), 'XBMC.RunPlugin(%s?mode=%d&path=%s)' % (sys.argv[0], _COPYFOLDER, urllib.quote_plus(path))))
#menu.append((GETTEXT(30180), 'XBMC.RunPlugin(%s?mode=%d&path=%s)' % (sys.argv[0], _CUTFOLDER, urllib.quote_plus(path))))
if label_numeric:
prefix, index = utils.getPrefix(index)
dir = prefix + dir
if colour and colour.lower() <> 'none':
dir = '[COLOR %s]%s[/COLOR]' % (colour, dir)
mode = _PLAY_SUPER_FOLDER if autoplay else _FOLDER
isFolder = not autoplay
isPlayable = not isFolder
addDir(dir, mode, path=path, thumbnail=thumbnail, isFolder=isFolder, menu=menu, fanart=fanart, infolabels=infolabel, isPlayable=isPlayable)
if len(dirs) > 0:
separator = True
file = os.path.join(folder, FILENAME)
parseFile(file, sortorder, label_numeric, index)
def getColour():
filename = os.path.join(HOME, 'resources', 'colours', 'Color.xml')
if not sfile.exists(filename):
return None
menu = [[GETTEXT(30087), 'SF_RESET']]
f = sfile.readlines(filename)
for line in f:
if 'name' in line:
name = line.split('"')[1]
menu.append(['[COLOR %s]%s[/COLOR]' % (name, name), name])
if len(menu) < 2:
return None
import menus
if DLG_MENU:
option = menus.selectMenu(GETTEXT(30086), menu)
else:
option = menus.showMenu(ADDONID, menu)
#option = menus.selectMenu(GETTEXT(30086), menu)
if option < 0:
return None
return option
def getImage():
root = HOME.split(os.sep, 1)[0] + os.sep
image = xbmcgui.Dialog().browse(2,GETTEXT(30044), 'files', '', False, False, root)
if image and image != root:
return image
return None
def getSkinImage():
image = ''
skin = xbmc.getSkinDir().lower()
icon = os.path.join(HOME, 'resources', skin, 'icons')
items = ['Super Favourite']
if sfile.exists(icon):
f = sfile.file(icon, 'r')
for line in f:
items.append(line.strip())
f.close()
if (len(items) > 1) and utils.DialogYesNo(GETTEXT(30046)):
import imagebrowser
return imagebrowser.getImage(ADDONID, items)
return getImage()
def removeFanartFolder(path):
folderConfig = os.path.join(path, FOLDERCFG)
parameters.setParam('FANART', '', folderConfig)
return True
def removeThumbFolder(path):
folderConfig = os.path.join(path, FOLDERCFG)
parameters.setParam('ICON', '', folderConfig)
return True
def fanartFolder(path,image=None):
if not image:
image = getImage()
if not image:
return False
image = utils.convertToHome(image)
folderConfig = os.path.join(path, FOLDERCFG)
parameters.setParam('FANART', image, folderConfig)
return True
def thumbFolder(path, image=None):
if not image:
image = getImage()
if not image:
return False
folderConfig = os.path.join(path, FOLDERCFG)
parameters.setParam('ICON', utils.convertToHome(image), folderConfig)
return True
def removeMetaFave(file, cmd):
return pasteMetaFave(file, cmd, '')
def pasteMetaFave(file, cmd, meta_clip):
fave, index, nFaves = favourite.findFave(file, cmd)
if not fave:
return False
fave[2] = favourite.updateSFOption(cmd, 'meta', urllib.quote_plus(meta_clip))