-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.py
3388 lines (3179 loc) · 180 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
# -*- coding: latin-1 -*-
import xbmcgui
import xbmcaddon
addon = xbmcaddon.Addon()
addon_path = addon.getAddonInfo('path')
REMOTE_DBG = False
# append pydev remote debugger
if REMOTE_DBG:
# Make pydev debugger works for auto reload.
# Note pydevd module need to be copied in XBMC\system\python\Lib\pysrc
try:
import pysrc.pydevd as pydevd
# stdoutToServer and stderrToServer redirect stdout and stderr to eclipse console
pydevd.settrace('localhost', stdoutToServer=True, stderrToServer=True)
except ImportError:
sys.stderr.write("Error: " +
"You must add org.python.pydev.debug.pysrc to your PYTHONPATH.")
sys.exit(1)
class blankWindow(xbmcgui.WindowXML):
def onInit(self):
pass
def selectchoice():
success = False
Choice = ['1 - Proposition de films','2 - Voir mes bandes-annonces', '3 - Suggestions','4 - Rechercher un film','5 - Gestion des bandes-annonces','6 - Consulter ses listes','7 - Quitter']
selectedchoice = xbmcgui.Dialog().select(u"Que voulez vous faire ?", Choice)
if not selectedchoice == -1:
selectedchoice = Choice[selectedchoice]
if selectedchoice == '1 - Proposition de films':
selectedchoice = 1
success = True
elif selectedchoice == '2 - Voir mes bandes-annonces':
selectedchoice = 2
success = True
elif selectedchoice == '3 - Suggestions':
selectedchoice = 3
success = True
elif selectedchoice == '4 - Rechercher un film':
selectedchoice=4
success = True
elif selectedchoice == '5 - Gestion des bandes-annonces':
selectedchoice=5
success = True
elif selectedchoice == '6 - Consulter ses listes':
selectedchoice=6
success = True
else:
success = False
return success, selectedchoice
sortie= False
bs = blankWindow('script-BlankWindow.xml', addon_path,'default',)
bs.show()
while sortie==False:
success, choix = selectchoice()
if success:
if choix==1:
import xbmc
import xbmcgui
import xbmcaddon
import random
import simplejson
import time
import SelectionFilters as sf
from datetime import date
ACTION_PREVIOUS_MENU = 10
ACTION_SELECT_ITEM = 7
ACTION_MOUSE_LEFT_CLICK = 100
filterGenres=None
filterYear=None
filterlast=None
filterUnwatched=None
filterdisney=None
_A_ = xbmcaddon.Addon()
_S_ = _A_.getSetting
actualyear = date.today().year
addon = xbmcaddon.Addon()
addon_path = addon.getAddonInfo('path')
hide_info = addon.getSetting('hide_info_sur')
exit_requested = False
class movieWindow(xbmcgui.WindowXMLDialog):
def onInit(self):
global trailer
global do_timeout
if hide_info == 'false':
w=infoWindow('script-DialogVideoInfo.xml',addon_path,'default')
do_timeout=True
w.doModal()
do_timeout=False
del w
if exit_requested:
xbmc.Player().stop()
else:
xbmc.Player().play(trailer["trailer"])
self.getControl(30011).setLabel(trailer["title"] + ' - ' + str(trailer["year"]))
self.getControl(30011).setVisible(True)
while xbmc.Player().isPlaying():
xbmc.sleep(250)
self.close()
def onAction(self, action):
ACTION_PREVIOUS_MENU = 10
ACTION_BACK = 92
ACTION_ENTER = 7
ACTION_I = 11
ACTION_LEFT = 1
ACTION_RIGHT = 2
ACTION_UP = 3
ACTION_DOWN = 4
ACTION_TAB = 18
ACTION_STOP = 13
xbmc.log('action =' + str(action.getId()))
global exit_requested
global movie_file
if action == ACTION_PREVIOUS_MENU or action == ACTION_LEFT or action == ACTION_BACK or action == ACTION_STOP:
xbmc.Player().stop()
exit_requested = True
self.close()
if action == ACTION_RIGHT or action == ACTION_TAB:
xbmc.Player().stop()
if action == ACTION_ENTER:
exit_requested = True
xbmc.Player().stop()
movie_file = trailer["file"]
self.getControl(30011).setVisible(False)
self.close()
if action == ACTION_I or action == ACTION_UP:
self.getControl(30011).setVisible(False)
w=infoWindow('script-DialogVideoInfo.xml',addon_path,'default')
w.doModal()
self.getControl(30011).setVisible(True)
class infoWindow(xbmcgui.WindowXMLDialog):
def onInit(self):
self.getControl(30001).setImage(trailer["thumbnail"])
self.getControl(30003).setImage(trailer["fanart"])
self.getControl(30002).setLabel(trailer["title"])
directors = trailer["director"]
movieDirector=''
for director in directors:
movieDirector = movieDirector + director + ', '
if not movieDirector =='':
movieDirector = movieDirector[:-2]
self.getControl(30005).setLabel(movieDirector)
writers = trailer["writer"]
movieWriter=''
for writer in writers:
movieWriter = movieWriter + writer + ', '
if not movieWriter =='':
movieWriter = movieWriter[:-2]
actors = trailer["cast"]
movieActor=''
actorcount=0
for actor in actors:
actorcount = actorcount + 1
movieActor = movieActor + actor['name'] + ", "
if actorcount == 6: break
if not movieActor == '':
movieActor = movieActor[:-2]
self.getControl(30007).setLabel(movieWriter)
self.getControl(30006).setLabel(movieActor)
self.getControl(30009).setText(trailer["plot"])
movieStudio=''
studios=trailer["studio"]
for studio in studios:
movieStudio = movieStudio + studio + ', '
if not movieStudio =='':
movieStudio = movieStudio[:-2]
self.getControl(30010).setLabel(movieStudio + ' - ' + str(trailer["year"]))
movieGenre=''
genres = trailer["genre"]
for genre in genres:
movieGenre = movieGenre + genre + ' / '
if not movieGenre =='':
movieGenre = movieGenre[:-3]
self.getControl(30011).setLabel(str(trailer["runtime"] / 60) + ' Minutes - ' + movieGenre)
imgRating='ratings/notrated.png'
if trailer["mpaa"].startswith('G'): imgRating='ratings/g.png'
if trailer["mpaa"] == ('G'): imgRating='ratings/g.png'
if trailer["mpaa"].startswith('Rated G'): imgRating='ratings/g.png'
if trailer["mpaa"].startswith('PG '): imgRating='ratings/pg.png'
if trailer["mpaa"] == ('PG'): imgRating='ratings/pg.png'
if trailer["mpaa"].startswith('Rated PG'): imgRating='ratings/pg.png'
if trailer["mpaa"].startswith('PG-13 '): imgRating='ratings/pg13.png'
if trailer["mpaa"] == ('PG-13'): imgRating='ratings/pg13.png'
if trailer["mpaa"].startswith('Rated PG-13'): imgRating='ratings/pg13.png'
if trailer["mpaa"].startswith('R '): imgRating='ratings/r.png'
if trailer["mpaa"] == ('R'): imgRating='ratings/r.png'
if trailer["mpaa"].startswith('Rated R'): imgRating='ratings/r.png'
if trailer["mpaa"].startswith('NC17'): imgRating='ratings/nc17.png'
if trailer["mpaa"].startswith('Rated NC17'): imgRating='ratings/nc1.png'
self.getControl(30013).setImage(imgRating)
if do_timeout:
xbmc.sleep(5000)
xbmc.Player().play(trailer["trailer"])
self.close()
def onAction(self, action):
ACTION_PREVIOUS_MENU = 10
ACTION_BACK = 92
ACTION_ENTER = 7
ACTION_I = 11
ACTION_LEFT = 1
ACTION_RIGHT = 2
ACTION_UP = 3
ACTION_DOWN = 4
ACTION_TAB = 18
ACTION_STOP = 13
xbmc.log('action =' + str(action.getId()))
global do_timeout
global exit_requested
global movie_file
if action == ACTION_PREVIOUS_MENU or action == ACTION_LEFT or action == ACTION_BACK or action == ACTION_STOP:
do_timeout=False
xbmc.Player().stop()
exit_requested=True
self.close()
if action == ACTION_I or action == ACTION_DOWN:
self.close()
if action == ACTION_RIGHT or action == ACTION_TAB:
xbmc.Player().stop()
self.close()
if action == ACTION_ENTER:
movie_file = trailer["file"]
xbmc.Player().stop()
exit_requested=True
self.close()
class blankWindow(xbmcgui.WindowXML):
def onInit(self):
pass
class XBMCPlayer(xbmc.Player):
def __init__( self, *args, **kwargs ):
pass
def onPlayBackStarted(self):
pass
def onPlayBackStopped(self):
global exit_requested
pass
def log(txt):
message = 'script.watchlist: %s' % txt
xbmc.log(msg=message, level=xbmc.LOGDEBUG)
#####################
# set our preferences
#####################
# Defaults
numRuntime = int(float(_S_( "longruntime" ) ) )
numTrailers = 3
promptGenres = promptYear = promptUnwatched = promptdisney = fanartMode = playlistMode = promptlast = False
if (_S_("runmode")) == "1":
# User has set defined mode in settings
promptUser = False
if (_S_("filtergenres")) == "0":
promptGenres = True
elif (_S_("filtergenres")) == "1":
promptGenres = False
filterGenres = True
else:
promptGenres = False
filterGenres = False
if (_S_("filteryear")) == "0":
promptYear = True
elif (_S_("filteryear")) == "1":
promptYear = False
filterYear = True
else:
promptYear = False
filterYear = False
if (_S_("filterdisney")) == "0":
promptdisney = True
elif (_S_("filterdisney")) == "1":
promptdisney = False
filterdisney = True
else:
promptdisney = False
filterdisney = False
if (_S_("filterlast")) == "0":
promptlast = True
elif (_S_("filterlast")) == "1":
promptlast = False
filterlast = True
else:
promptlast = False
filterlast = False
if (_S_("filterunwatched")) == "0":
promptUnwatched = True
elif (_S_("filterunwatched")) == "1":
promptUnwatched = False
filterUnwatched = True
else:
promptUnwatched = False
filterUnwatched = False
trailerMode = _S_( "trailermode" ) == "true"
numTrailers = int(float(_S_( "numtrailers" ) ) )
playlistMode = _S_("playlistmode") == "true"
else:
# if not, we're in prompt mode
promptUser = True
filterUnwatched = filterYear = filterGenres = filterdisney = trailerMode = filterlast = False
playlistMode = _S_("playlistmode") == "true"
def getMovieLibrary():
# get the raw JSON output
try:
moviestring = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "fields": ["genre", "playcount", "file"]}, "id": 1}')
moviestring = unicode(moviestring, 'utf-8', errors='ignore')
movies = simplejson.loads(moviestring)
testError = movies["result"]
except:
moviestring = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "properties": ["title","playcount", "lastplayed", "studio", "writer", "plot", "votes", "top250", "originaltitle", "director", "tagline", "fanart", "runtime", "mpaa", "rating", "thumbnail", "file", "year", "genre", "trailer","set","dateadded","cast"]}, "id": 1}')
moviestring = unicode(moviestring, 'utf-8', errors='ignore')
movies = simplejson.loads(moviestring)
return movies
def BuildFilter(movies):
filter = sf.SelectionFilters()
askGenres = askYear = askdisney = askUnwatched = askTrailer = asklast = runtime = 0
if promptUser or promptUnwatched:
askUnwatched = xbmcgui.Dialog().yesno("Films vus","Seulement les films non vus ?")
if askUnwatched or filterUnwatched:
filter.SetFilter("unwatched", True)
unwatched = True
else:
unwatched = False
if promptUser:
askTrailer = xbmcgui.Dialog().yesno("Voir des bandes-annonces", "Voulez vous voir des bandes annonces ?")
if askTrailer:
global trailerMode
trailerMode = True
if promptUser or promptGenres:
askGenres = xbmcgui.Dialog().yesno("Filtrer sur un genre", "Voulez-vous choisir un genre ?")
if askGenres or filterGenres:
success, genre = selectGenre(unwatched, trailerMode)
if success:
filter.SetFilter("genre", True, genre=genre)
if promptUser or promptYear:
askYear = xbmcgui.Dialog().yesno(u"Filtrer sur l'année", u"Voulez-vous filtrer sur l'année ?")
if askYear or filterYear:
success, year = selectYear(unwatched, trailerMode)
if success:
filter.SetFilter("year", True, year=year)
if promptUser or promptlast:
asklast = xbmcgui.Dialog().yesno(u"Date de téléchargement", u"Voulez-vous filtrer sur la date de téléchargement?")
if asklast or filterlast:
success, last = selectlast(unwatched, trailerMode)
if success:
filter.SetFilter("last", True, last=last)
askRuntime = xbmcgui.Dialog().yesno(u"Filtrer durée", "Voulez-vous ignorer les films longs ?")
if askRuntime:# or filterYear:
runtime = numRuntime*60
filter.SetFilter("runtime", True, runtime=runtime)
if promptUser or promptdisney:
askdisney = xbmcgui.Dialog().yesno("Filtrer les Disney", "Voulez-vous ignorer les Walt Disney ?")
if askdisney or filterdisney:
disney = u"Walt Disney"
filter.SetFilter("disney", True, disney=disney)
return filter
def selectGenre(filterWatched, trailer):
success = False
selectedGenre = ""
myGenres = []
for movie in moviesJSON["result"]["movies"]:
# Let's get the movie genres
# If we're only looking at unwatched movies then restrict list to those movies
if (( filterWatched and movie["playcount"] == 0 ) or not filterWatched) and ((trailer and not movie["trailer"] == "") or not trailer):
#print movie["trailer"]
test = simplejson.dumps(movie["genre"],ensure_ascii=False, encoding='utf8')
#test = unicode(test, 'utf8', errors='ignore')
test = test.replace('"','')
test = test.replace(']','')
test = test.replace('[','')
genres = test.split(", ")
for genre in genres:
# check if the genre is a duplicate
if not genre in myGenres:
# if not, add it to our list
myGenres.append(genre)
myGenres.append("3D")
# sort the list alphabetically
mySortedGenres = sorted(myGenres)
# prompt user to select genre
selectGenre = xbmcgui.Dialog().select("Choisissez le genre :", mySortedGenres)
# check whether user cancelled selection
if not selectGenre == -1:
# get the user's chosen genre
selectedGenre = mySortedGenres[selectGenre]
success = True
else:
success = False
# return the genre and whether the choice was successfull
return success, selectedGenre
def selectYear(filterWatched, trailer):
success = False
selectedYear = ""
# sort the list alphabetically
myYear = [u'Cette année',u'2 dernières années', u'5 dernières années', u'10 dernières années', u'15 dernières années', u'20 dernières années', u'30 dernières années',u'50 dernières années']
# prompt user to select genre
selectYear = xbmcgui.Dialog().select(u"A partir de quelle année ", myYear)
# check whether user cancelled selection
if not selectYear == -1:
# get the user's chosen genre
selectedYear = myYear[selectYear].encode('utf-8')
if selectedYear == u'Cette année'.encode('utf-8'):
selectedYear = int(actualyear) - 0
success = True
elif selectedYear == u'2 dernières années'.encode('utf-8'):
selectedYear = int(actualyear) - 2
success = True
elif selectedYear == u'5 dernières années'.encode('utf-8'):
selectedYear = int(actualyear) - 5
success = True
elif selectedYear == u'10 dernières années'.encode('utf-8'):
selectedYear = int(actualyear) - 10
success = True
elif selectedYear == u'15 dernières années'.encode('utf-8'):
selectedYear = int(actualyear) - 15
success = True
elif selectedYear == u'20 dernières années'.encode('utf-8'):
selectedYear = int(actualyear) - 20
success = True
elif selectedYear == u'30 dernières années'.encode('utf-8'):
selectedYear = int(actualyear) - 30
success = True
elif selectedYear == u'50 dernières années'.encode('utf-8'):
selectedYear = int(actualyear) - 50
success = True
else:
success = False
# return the year and whether the choice was successfult
return success, selectedYear
def selectlast(filterWatched, trailer):
success = False
selectedlast = ""
# sort the list alphabetically
mylast = [u'Aujourdhui',u'Cette semaine', u'Ces 15 derniers jours', u'Ce mois', u'Ces 2 derniers mois', u'Ces 3 derniers mois', u'Ces 6 derniers mois',u'Cette année']
# prompt user to select genre
selectlast = xbmcgui.Dialog().select(u"Téléchargé depuis quand ?", mylast)
# check whether user cancelled selection
if not selectlast == -1:
# get the user's chosen genre
selectedlast = mylast[selectlast]
if selectedlast == u'Aujourdhui':
selectedlast = 1
success = True
elif selectedlast == u'Cette semaine':
selectedlast = 7
success = True
elif selectedlast == u'Ces 15 derniers jours':
selectedlast = 15
success = True
elif selectedlast == u'Ce mois':
selectedlast = 31
success = True
elif selectedlast == u'Ces 2 derniers mois':
selectedlast = 62
success = True
elif selectedlast == u'Ces 3 derniers mois':
selectedlast = 93
success = True
elif selectedlast == u'Ces 6 derniers mois':
selectedlast = 186
success = True
elif selectedlast == u'Cette année'.encode('utf-8'):
selectedlast = 365
success = True
else:
success = False
# return the year and whether the choice was successfult
return success, selectedlast
def getVideoPlaylists():
videostring = unicode(xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory": "special://videoplaylists"}, "id": 1}'), errors='ignore')
myVideoPlaylists = simplejson.loads(videostring)
return myVideoPlaylists
def chooseVideoPlaylist(videoPlaylists):
myPlaylists = {}
selectPlaylist = []
for playlist in videoPlaylists["result"]["files"]:
myPlaylists[playlist["label"]] = playlist["file"]
selectPlaylist.append(playlist["label"])
#selectPlaylist.append("Cancel")
a = xbmcgui.Dialog().select("Select playlist",selectPlaylist)
if not a == -1:
playliststring = unicode(xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory": "' + myPlaylists[selectPlaylist[a]] + '", "media": "video"}, "id": 1}'), errors='ignore')
myVideoPlaylists = simplejson.loads(playliststring)
showfiles = []
for movie in myVideoPlaylists["result"]["files"]:
showfiles.append(movie["file"])
return True, showfiles
else:
return False, ""
def getTrailers(movieList, numTrailers):
trailerList = []
global trailer
global do_timeout
global exit_requested
global trailerMode
global movie_file
movie_file=''
exit_requested = False
player = XBMCPlayer()
# We need to check that we have enough trailers to meet our user's requirements
if len(movieList) <= numTrailers:
# if we don't then we need to limit the number of trailers to show
listLimit = len(movieList)
else:
listLimit = numTrailers
# Build list of trailers
myRandomMovies = []
while len(trailerList) < listLimit:
movieN = random.choice(movieList)
if not movieN in trailerList:
trailerList.append(movieN)
myRandomMovies.append(movieN)
if trailerMode:
while not exit_requested:
for item in trailerList:
trailer=item
myMovieWindow=movieWindow('script-trailerwindow.xml', addon_path,'default',)
myMovieWindow.doModal()
del myMovieWindow
if exit_requested:
break
if not exit_requested:
while player.isPlaying():
xbmc.sleep(250)
exit_requested=True
randomList = []
i = 1
for movie in myRandomMovies:
movietitle = simplejson.dumps(movie["label"],ensure_ascii=False, encoding='utf8')
movietitle = movietitle.replace('"','')
movieyear = simplejson.dumps(movie["year"],ensure_ascii=False, encoding='utf8')
movieyear = movieyear.replace('"','')
moviegenre = simplejson.dumps(movie["genre"],ensure_ascii=False, encoding='utf8')
moviegenre = moviegenre.replace('"','')
movielenghth = simplejson.dumps(movie["runtime"]/3600,ensure_ascii=False, encoding='utf8')
movielenghth = movielenghth.replace('"','')
movielenghtm = simplejson.dumps((movie["runtime"] -(int(movielenghth)*3600))/60,ensure_ascii=False, encoding='utf8')
movielenghth = movielenghth.replace('"','')
movielenghtm = movielenghtm.replace('"','')
randomList.append(str(i) + ' : '+ movietitle + ' (' +movieyear+') - ' + moviegenre +' - ' +movielenghth + 'h' + movielenghtm +'min')
i+=1
if movie_file:
success = True
myMovie=movie_file
else:
if randomList == []:
a = xbmcgui.Dialog().ok('Dommage', u'Aucun de vos films ne repond aux critères')
else:
a = xbmcgui.Dialog().select("Quel film voulez-vous lancer :", randomList)
if not a == -1 and not randomList == []:
success = True
myMovie = simplejson.dumps(myRandomMovies[a]["file"],ensure_ascii=False, encoding='utf8')
else:
success = False
myMovie = ""
return success, myMovie
def FilterMovies(movies, filter, trailer):
filteredlist = []
for movie in movies["result"]["movies"]:
if ((trailer and not movie["trailer"] == '') or not trailer):
if filter.MeetsCriteria(movie):
filteredlist.append(movie)
return filteredlist
global movie_file
moviesJSON = getMovieLibrary()
filter = BuildFilter(moviesJSON)
# apply filter to our library
filteredMovies = FilterMovies(moviesJSON, filter, trailerMode)
success, myMovie = getTrailers(filteredMovies, numTrailers)
if success:
sortie=True
xbmc.executebuiltin('Playmedia(' + myMovie.encode('utf-8') + ')')
elif _S_( "randommode" )=='true':
randomMovie = random.choice(filteredMovies)
sortie=True
xbmc.executebuiltin('Playmedia(' + randomMovie["file"].encode('utf-8') + ')')
elif choix==2:
import xbmc
import xbmcgui
import sys
import os
import random
import simplejson as json
import time
import datetime
import xbmcaddon
from datetime import date
addon = xbmcaddon.Addon()
number_trailers = addon.getSetting('number_trailers')
do_curtains = addon.getSetting('do_animation')
do_year = addon.getSetting('do_year')
do_genre = addon.getSetting('do_genre')
do_last = addon.getSetting('do_last')
hide_info = addon.getSetting('hide_info')
addon_path = addon.getAddonInfo('path')
hide_watched = addon.getSetting('hide_watched')
watched_days = addon.getSetting('watched_days')
resources_path = xbmc.translatePath( os.path.join( addon_path, 'resources' ) ).decode('utf-8')
media_path = xbmc.translatePath( os.path.join( resources_path, 'media' ) ).decode('utf-8')
open_curtain_path = xbmc.translatePath( os.path.join( media_path, 'OpenSequence.mp4' ) ).decode('utf-8')
close_curtain_path = xbmc.translatePath( os.path.join( media_path, 'ClosingSequence.mp4' ) ).decode('utf-8')
selectedGenre =''
exit_requested = False
movie_file = ''
viewed=[]
actualyear = date.today().year
if len(sys.argv) == 2:
do_genre ='false'
else:
do_password='false'
trailer=''
do_timeout = False
def askGenres():
addon = xbmcaddon.Addon()
# default is to select from all movies
selectGenre = False
# ask user whether they want to select a genre
a = xbmcgui.Dialog().yesno("Genre", "Voulez-vous choisir un genre ?")
# deal with the output
if a == 1:
# set filter
selectGenre = True
return selectGenre
def selectGenre():
success = False
selectedGenre = ""
myGenres = []
trailerstring = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "properties": ["genre", "playcount", "file", "trailer"]}, "id": 1}')
trailerstring = unicode(trailerstring, 'utf-8', errors='ignore')
trailers = json.loads(trailerstring)
for movie in trailers["result"]["movies"]:
# Let's get the movie genres
genres = movie["genre"]
for genre in genres:
# check if the genre is a duplicate
if not genre in myGenres and not genre =='':
# if not, add it to our list
myGenres.append(genre)
myGenres.append("3D")
# sort the list alphabetically
mySortedGenres = sorted(myGenres)
# prompt user to select genre
selectGenre = xbmcgui.Dialog().select('Choisissez un genre', mySortedGenres)
# check whether user cancelled selection
if not selectGenre == -1:
# get the user's chosen genre
selectedGenre = mySortedGenres[selectGenre].encode('utf-8')
success = True
else:
success = False
# return the genre and whether the choice was successfult
return success, selectedGenre
def askyear():
# default is to select from all movies
selectyear = False
# ask user whether they want to select a year
a = xbmcgui.Dialog().yesno(u"Filtrer sur l'année", u"Voulez-vous filtrer sur l'année ?")
# deal with the output
if a == 1:
# set filter
selectyear = True
return selectyear
def selectYear():
success = False
selectedYear = ""
# sort the list alphabetically
myYear = [u'Cette année', u'2 dernères années', u'5 dernères années', u'10 dernères années', u'15 dernères années', u'20 dernères années', u'30 dernères années', u'50 dernères années']
# prompt user to select genre
selectYear = xbmcgui.Dialog().select(u"A partir de quelle année ", myYear)
# check whether user cancelled selection
if not selectYear == -1:
# get the user's chosen genre
selectedYear = myYear[selectYear]
if selectedYear == u'Cette année':
selectedYear = int(actualyear) - 0
success = True
elif selectedYear == u'2 dernères années':
selectedYear = int(actualyear) - 2
success = True
elif selectedYear == u'5 dernères années':
selectedYear = int(actualyear) - 5
success = True
elif selectedYear == u'10 dernères années':
selectedYear = int(actualyear) - 10
success = True
elif selectedYear == u'15 dernères années':
selectedYear = int(actualyear) - 15
success = True
elif selectedYear == u'20 dernères années':
selectedYear = int(actualyear) - 20
success = True
elif selectedYear == u'30 dernères années':
selectedYear = int(actualyear) - 30
success = True
elif selectedYear == u'50 dernères années':
selectedYear = int(actualyear) - 50
success = True
else:
success = False
# return the year and whether the choice was successfult
return success, selectedYear
def asklast():
# default is to select from all movies
selectlast = False
# ask user whether they want to select a year
a = xbmcgui.Dialog().yesno(u"Date de téléchargement", u"Voulez-vous filtrer sur la date de téléchargement ?")
# deal with the output
if a == 1:
# set filter
selectlast = True
return selectlast
def selectlast():
success = False
selectedlast = ""
# sort the list alphabetically
mylast = ['Aujourdhui', 'Cette semaine', 'Ces 15 derniers jours', 'Ce mois', 'Ces 2 derniers mois', 'Ces 3 derniers mois', 'Ces 6 derniers mois', u'Cette année']
# prompt user to select genre
selectlast = xbmcgui.Dialog().select(u"Téléchargé depuis quand ?", mylast)
# check whether user cancelled selection
if not selectlast == -1:
# get the user's chosen genre
selectedlast = mylast[selectlast]
if selectedlast == 'Aujourdhui':
selectedlast = 1
success = True
elif selectedlast == 'Cette semaine':
selectedlast = 7
success = True
elif selectedlast == 'Ces 15 derniers jours':
selectedlast = 15
success = True
elif selectedlast == 'Ce mois':
selectedlast = 31
success = True
elif selectedlast == 'Ces deux derniers mois':
selectedlast = 62
success = True
elif selectedlast == 'Ces 3 derniers mois':
selectedlast = 93
success = True
elif selectedlast == 'Ces 6 derniers mois':
selectedlast = 186
success = True
elif selectedlast == u'Cette année':
selectedlast = 365
success = True
else:
success = False
# return the year and whether the choice was successfult
return success, selectedlast
def getTrailers(genre,year,last):
# get the raw JSON output
list3D=[]
if last == '':
if genre == '3D':
trailerstring = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "lastplayed", "studio", "writer", "plot", "votes", "top250", "originaltitle", "director", "tagline", "fanart", "runtime", "mpaa", "rating", "thumbnail", "file", "year", "genre", "trailer","cast"], "filter": { "and":[{"field": "year", "operator": "greaterthan", "value": "%s"}]}}, "id": 1}' % (str(year)))
else:
trailerstring = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "lastplayed", "studio", "writer", "plot", "votes", "top250", "originaltitle", "director", "tagline", "fanart", "runtime", "mpaa", "rating", "thumbnail", "file", "year", "genre", "trailer","cast"], "filter": { "and":[{"field": "genre", "operator": "contains", "value": "%s"},{"field": "year", "operator": "greaterthan", "value": "%s"}]}}, "id": 1}' % (genre,str(year)))
else:
if genre == '3D':
trailerstring = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "lastplayed", "studio", "writer", "plot", "votes", "top250", "originaltitle", "director", "tagline", "fanart", "runtime", "mpaa", "rating", "thumbnail", "file", "year", "genre", "trailer","cast"], "filter": { "and":[{"field": "year", "operator": "greaterthan", "value": "%s"},{"field":"dateadded","operator":"inthelast","value":"%s"}]}}, "id": 1}' % (str(year),str(last)))
else:
trailerstring = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "lastplayed", "studio", "writer", "plot", "votes", "top250", "originaltitle", "director", "tagline", "fanart", "runtime", "mpaa", "rating", "thumbnail", "file", "year", "genre", "trailer","cast"], "filter": { "and":[{"field": "genre", "operator": "contains", "value": "%s"},{"field": "year", "operator": "greaterthan", "value": "%s"},{"field":"dateadded","operator":"inthelast","value":"%s"}]}}, "id": 1}' % (genre,str(year),str(last)))
trailerstring = unicode(trailerstring, 'utf-8', errors='ignore')
trailers = json.loads(trailerstring)
if genre =='3D':
for x in trailers['result']['movies']:
if '3DBD' in x['file']:
list3D.append(x)
trailers['result']['movies']=list3D
return trailers
class movieWindow(xbmcgui.WindowXMLDialog):
def onInit(self):
global SelectedGenre
global SelectedYear
global SelectedLast
global trailer
global do_timeout
global viewed
trailer=random.choice(trailers["result"]["movies"])
lastPlay = True
if not trailer["lastplayed"] =='' and hide_watched == 'true':
pd=time.strptime(trailer["lastplayed"],'%Y-%m-%d %H:%M:%S')
pd = time.mktime(pd)
pd = datetime.datetime.fromtimestamp(pd)
lastPlay = datetime.datetime.now() - pd
lastPlay = lastPlay.days
if lastPlay > int(watched_days) or watched_days == '0':
lastPlay = True
else:
lastPlay = False
if trailer["trailer"] != '' and lastPlay and trailer["movieid"] not in viewed:
if hide_info == 'false':
viewed.append(trailer["movieid"])
w=infoWindow('script-DialogVideoInfo.xml',addon_path,'default')
do_timeout=True
w.doModal()
do_timeout=False
del w
if exit_requested:
xbmc.Player().stop()
else:
viewed.append(trailer["movieid"])
xbmc.Player().play(trailer["trailer"])
self.getControl(30011).setLabel(trailer["title"] + ' - ' + str(trailer["year"]))
self.getControl(30011).setVisible(True)
while xbmc.Player().isPlaying():
xbmc.sleep(250)
self.close()
def onAction(self, action):
ACTION_PREVIOUS_MENU = 10
ACTION_BACK = 92
ACTION_ENTER = 7
ACTION_I = 11
ACTION_LEFT = 1
ACTION_RIGHT = 2
ACTION_UP = 3
ACTION_DOWN = 4
ACTION_TAB = 18
ACTION_STOP = 13
xbmc.log('action =' + str(action.getId()))
global exit_requested
global movie_file
if action == ACTION_PREVIOUS_MENU or action == ACTION_LEFT or action == ACTION_BACK or action == ACTION_STOP:
xbmc.Player().stop()
exit_requested = True
self.close()
if action == ACTION_RIGHT or action == ACTION_TAB:
xbmc.Player().stop()
if action == ACTION_ENTER:
exit_requested = True
xbmc.Player().stop()
movie_file = trailer["file"]
self.getControl(30011).setVisible(False)
self.close()
if action == ACTION_I or action == ACTION_UP:
self.getControl(30011).setVisible(False)
w=infoWindow('script-DialogVideoInfo.xml',addon_path,'default')
w.doModal()
self.getControl(30011).setVisible(True)
class infoWindow(xbmcgui.WindowXMLDialog):
def onInit(self):
self.getControl(30001).setImage(trailer["thumbnail"])
self.getControl(30003).setImage(trailer["fanart"])
self.getControl(30002).setLabel(trailer["title"])
directors = trailer["director"]
movieDirector=''
for director in directors:
movieDirector = movieDirector + director + ', '
if not movieDirector =='':
movieDirector = movieDirector[:-2]
self.getControl(30005).setLabel(movieDirector)
writers = trailer["writer"]
movieWriter=''
for writer in writers:
movieWriter = movieWriter + writer + ', '
if not movieWriter =='':
movieWriter = movieWriter[:-2]
actors = trailer["cast"]
movieActor=''
actorcount=0
for actor in actors:
actorcount = actorcount + 1
movieActor = movieActor + actor['name'] + ", "
if actorcount == 6: break
if not movieActor == '':
movieActor = movieActor[:-2]
self.getControl(30007).setLabel(movieWriter)
self.getControl(30006).setLabel(movieActor)
self.getControl(30009).setText(trailer["plot"])
movieStudio=''
studios=trailer["studio"]
for studio in studios:
movieStudio = movieStudio + studio + ', '
if not movieStudio =='':
movieStudio = movieStudio[:-2]
self.getControl(30010).setLabel(movieStudio + ' - ' + str(trailer["year"]))
movieGenre=''
genres = trailer["genre"]
for genre in genres:
movieGenre = movieGenre + genre + ' / '
if not movieGenre =='':
movieGenre = movieGenre[:-3]
self.getControl(30011).setLabel(str(trailer["runtime"] / 60) + ' Minutes - ' + movieGenre)
imgRating='ratings/notrated.png'
if trailer["mpaa"].startswith('G'): imgRating='ratings/g.png'
if trailer["mpaa"] == ('G'): imgRating='ratings/g.png'
if trailer["mpaa"].startswith('Rated G'): imgRating='ratings/g.png'
if trailer["mpaa"].startswith('PG '): imgRating='ratings/pg.png'
if trailer["mpaa"] == ('PG'): imgRating='ratings/pg.png'
if trailer["mpaa"].startswith('Rated PG'): imgRating='ratings/pg.png'
if trailer["mpaa"].startswith('PG-13 '): imgRating='ratings/pg13.png'
if trailer["mpaa"] == ('PG-13'): imgRating='ratings/pg13.png'
if trailer["mpaa"].startswith('Rated PG-13'): imgRating='ratings/pg13.png'
if trailer["mpaa"].startswith('R '): imgRating='ratings/r.png'
if trailer["mpaa"] == ('R'): imgRating='ratings/r.png'
if trailer["mpaa"].startswith('Rated R'): imgRating='ratings/r.png'
if trailer["mpaa"].startswith('NC17'): imgRating='ratings/nc17.png'
if trailer["mpaa"].startswith('Rated NC17'): imgRating='ratings/nc1.png'
self.getControl(30013).setImage(imgRating)
if do_timeout:
xbmc.sleep(5000)
xbmc.Player().play(trailer["trailer"])
self.close()
def onAction(self, action):
ACTION_PREVIOUS_MENU = 10
ACTION_BACK = 92
ACTION_ENTER = 7
ACTION_I = 11
ACTION_LEFT = 1
ACTION_RIGHT = 2
ACTION_UP = 3
ACTION_DOWN = 4
ACTION_TAB = 18
ACTION_STOP = 13
xbmc.log('action =' + str(action.getId()))
global do_timeout
global exit_requested