forked from Giftie/script.cinema.experience
/
addon.py
592 lines (568 loc) · 31.6 KB
/
addon.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
# -*- coding: utf-8 -*-
# constants
__script__ = "Cinema Experience"
__author__ = "nuka1195-giftie-ackbarr"
__url__ = "https://github.com/Giftie/script.cinema.experience"
__version__ = "2.0.57"
__scriptID__ = "script.cinema.experience"
import xbmcgui, xbmc, xbmcaddon, os, re, sys
import traceback
import time
from urllib import quote_plus
from threading import Thread
#from multiprocessing import Process as Thread
from shutil import copy2
import __builtin__
_A_ = xbmcaddon.Addon( __scriptID__ )
# language method
_L_ = _A_.getLocalizedString
# settings method
_S_ = _A_.getSetting
number_of_features = int( _S_( "number_of_features" ) ) + 1
playback = ""
BASE_CACHE_PATH = os.path.join( xbmc.translatePath( "special://profile" ), "Thumbnails", "Video" )
BASE_CURRENT_SOURCE_PATH = os.path.join( xbmc.translatePath( "special://profile/addon_data/" ), os.path.basename( _A_.getAddonInfo('path') ) )
BASE_RESOURCE_PATH = xbmc.translatePath( os.path.join( _A_.getAddonInfo('path'), 'resources' ) )
sys.path.append( os.path.join( BASE_RESOURCE_PATH, "lib" ) )
headings = ( _L_(32600), _L_(32601), _L_(32602), _L_(32603), _L_(32604), _L_(32605), _L_(32606), _L_(32607), _L_(32608), _L_(32609), _L_(32610), _L_(32611), _L_(32612) )
header = "Cinema Experience"
time_delay = 200
image = xbmc.translatePath( os.path.join( _A_.getAddonInfo("path"), "icon.png") )
autorefresh = xbmc.executehttpapi( "GetGuiSetting(1; videoplayer.adjustrefreshrate)" ).replace( "<li>", "" )
screensaver = xbmc.executehttpapi( "GetGUISetting(3;screensaver.mode)" ).replace( "<li>", "" )
playlist = xbmc.PlayList( xbmc.PLAYLIST_VIDEO )
prev_trigger = ""
script_header = "[ %s ]" % __scriptID__
from ce_playlist import _get_special_items, _wait_until_end, build_music_playlist, _rebuild_playlist
from slides import _fetch_slides
from new_trailer_downloader import downloader
from utils import settings_to_log
from pre_eden_code import _store_playlist, _get_queued_video_info, _build_playlist
from xbmcvfs import delete as delete_file
from xbmcvfs import exists as exists
from xbmcvfs import copy as file_copy
#TODO: Check to see if module is moved to /userdata/addon_data/script.cinema.experience
try:
if not exists( os.path.join( BASE_CURRENT_SOURCE_PATH, "ha_scripts", "home_automation.py" ) ) and _S_( "ha_enable") == "true":
source = os.path.join( BASE_RESOURCE_PATH, "ha_scripts", "home_automation.py" )
destination = os.path.join( BASE_CURRENT_SOURCE_PATH, "ha_scripts", "home_automation.py" )
os.mkdir( os.path.join( BASE_CURRENT_SOURCE_PATH, "ha_scripts" ) )
file_copy( source, destination )
xbmc.log( "[ script.cinema.experience ] - home_automation.py copied", level=xbmc.LOGNOTICE )
sys.path.append( os.path.join( BASE_CURRENT_SOURCE_PATH, "ha_scripts" ) )
from home_automation import activate_on
# Import HA module set ha_imported to True if successful
ha_imported = True
except ImportError:
# or ha_imported to False if unsuccessful
ha_imported = False
#ce_pause_time = float( int( _S_("pause_time") ) )
ce_pause_time = float( 2.5 )
__builtin__.slide_settings = { "trivia_total_time": int( float( _S_( "trivia_total_time" ) ) ),
"trivia_folder": xbmc.translatePath( _S_( "trivia_folder" ) ),
"trivia_slide_time": int( float( _S_( "trivia_slide_time" ) ) ),
"trivia_intro": _S_( "trivia_intro" ),
"trivia_music": _S_( "trivia_music" ),
"trivia_adjust_volume": _S_( "trivia_adjust_volume" ),
"trivia_fade_volume": _S_( "trivia_fade_volume" ),
"trivia_fade_time": int( float( _S_( "trivia_fade_time" ) ) ),
"trivia_music_file": xbmc.translatePath( _S_( "trivia_music_file" ) ),
"trivia_music_folder": xbmc.translatePath( _S_( "trivia_music_folder" ) ),
"trivia_music_volume": int( float( _S_( "trivia_music_volume" ) ) ),
"trivia_unwatched_only": _S_( "trivia_unwatched_only" ) == "true"
}
def footprints():
xbmc.log( "[ script.cinema.experience ] - Script Name: %s" % __script__, level=xbmc.LOGNOTICE )
xbmc.log( "[ script.cinema.experience ] - Script ID: %s" % __scriptID__, level=xbmc.LOGNOTICE )
xbmc.log( "[ script.cinema.experience ] - Script Version: %s" % __version__, level=xbmc.LOGNOTICE )
xbmc.log( "[ script.cinema.experience ] - Autorefresh - Before Script: %s" % autorefresh, level=xbmc.LOGNOTICE )
xbmc.log( "[ script.cinema.experience ] - Starting Window ID: %s" % xbmcgui.getCurrentWindowId(), level=xbmc.LOGNOTICE )
def _load_trigger_list():
xbmc.log( "[script.cinema.experience] - Loading Trigger List", level=xbmc.LOGNOTICE)
try:
# set base watched file path
base_path = os.path.join( BASE_CURRENT_SOURCE_PATH, "trigger_list.txt" )
# open path
usock = open( base_path, "r" )
# read source
trigger_list = eval( usock.read() )
# close socket
usock.close()
except:
xbmc.log( "[script.cinema.experience] - Error Loading Trigger List", level=xbmc.LOGNOTICE)
traceback.print_exc()
trigger_list = []
return trigger_list
def _clear_watched_items( clear_type ):
xbmc.log( "[ script.cinema.experience ] - _clear_watched_items( %s )" % ( clear_type ), level=xbmc.LOGNOTICE )
# initialize base_path
base_paths = []
# clear trivia or trailers
if ( clear_type == "ClearWatchedTrailers" ):
# trailer settings, grab them here so we don't need another _S_() object
settings = { "trailer_amt_db_file": xbmc.translatePath( _S_( "trailer_amt_db_file" ) ) }
# handle AMT db special
sys.path.append( os.path.join( BASE_RESOURCE_PATH, "lib", "scrapers") )
from amt_database import scraper as scraper
Scraper = scraper.Main( settings=settings )
# update trailers
Scraper.clear_watched()
# set base watched file path
base_paths += [ os.path.join( BASE_CURRENT_SOURCE_PATH, "amt_current_watched.txt" ) ]
base_paths += [ os.path.join( BASE_CURRENT_SOURCE_PATH, "local_watched.txt" ) ]
else:
# set base watched file path
base_paths = [ os.path.join( BASE_CURRENT_SOURCE_PATH, "trivia_watched.txt" ) ]
try:
# set proper message
message = ( 32531, 32541, )[ sys.argv[ 1 ] == "ClearWatchedTrailers" ]
# remove watched status file(s)
for base_path in base_paths:
# remove file if it exists
if ( exists( base_path ) ):
delete_file( base_path )
except:
# set proper message
message = ( 32532, 32542, )[ sys.argv[ 1 ] == "ClearWatchedTrailers" ]
# inform user of result
ok = xbmcgui.Dialog().ok( _L_( 32000 ), _L_( message ) )
def _view_changelog( ):
xbmc.log( "[ script.cinema.experience ] - _view_changelog()", level=xbmc.LOGNOTICE )
def _view_readme( ):
xbmc.log( "[ script.cinema.experience ] - _view_readme()", level=xbmc.LOGNOTICE )
def _check_compatible():
try:
# spam plugin statistics to log
xbmc.log( "[ script.cinema.experience ] - Version - %s-r%s' initialized!" % ( __version__, __svn_revision__.replace( "$", "" ).replace( "Revision", "" ).replace( ":", "" ).strip() ), level=xbmc.LOGNOTICE )
# get xbmc revision
xbmc_rev = int( xbmc.getInfoLabel( "System.BuildVersion" ).split( " r" )[ -1 ][ : 5 ] )
# compatible?
ok = xbmc_rev >= int( __XBMC_Revision__ )
except:
# error, so unknown, allow to run
xbmc_rev = 0
ok = 2
# spam revision info
xbmc.log( "[ script.cinema.experience ] - ** Required XBMC Revision: r%s **" % ( __XBMC_Revision__, ), level=xbmc.LOGNOTICE )
xbmc.log( "[ script.cinema.experience ] - ** Found XBMC Revision: r%d [%s] **" % ( xbmc_rev, ( "Not Compatible", "Compatible", "Unknown", )[ ok ], ), level=xbmc.LOGNOTICE )
return ok
def _clear_playlists( mode="both" ):
# clear playlists
if mode=="video" or mode=="both":
vplaylist = playlist
vplaylist.clear()
xbmc.log( "[ script.cinema.experience ] - Video Playlist Cleared", level=xbmc.LOGNOTICE )
if mode=="music" or mode=="both":
mplaylist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
mplaylist.clear()
xbmc.log( "[ script.cinema.experience ] - Music Playlist Cleared", level=xbmc.LOGNOTICE )
def voxcommando():
playlistsize = playlist.size()
if playlistsize > 1:
movie_titles = ""
for feature_count in range (1, playlistsize + 1):
movie_title = playlist[ feature_count - 1 ].getdescription()
xbmc.log( "[ script.cinema.experience ] - Feature #%-2d - %s" % ( feature_count, movie_title ), level=xbmc.LOGNOTICE )
movie_titles = movie_titles + movie_title + "<li>"
movie_titles = movie_titles.rstrip("<li>")
if _S_( "voxcommando" ) == "true":
xbmc.executehttpapi( "Broadcast(<b>CElaunch." + str(playlistsize ) + "<li>" + movie_titles + "</b>;33000)" )
else:
# get the queued video info
movie_title = playlist[ 0 ].getdescription()
xbmc.log( "[ script.cinema.experience ] - Feature - %s" % movie_title, level=xbmc.LOGNOTICE )
if _S_( "voxcommando" ) == "true":
xbmc.executehttpapi( "Broadcast(<b>CElaunch<li>" + movie_title + "</b>;33000)" )
def _sqlquery( sqlquery ):
movie_list = []
movies = []
xbmc.executehttpapi( "SetResponseFormat()" )
xbmc.executehttpapi( "SetResponseFormat(OpenField,)" )
sqlquery = "SELECT movieview.c00 FROM movieview JOIN genrelinkmovie ON genrelinkmovie.idMovie=movieview.idMovie JOIN genre ON genrelinkmovie.idGenre=genre.idGenre WHERE strGenre='Action' ORDER BY RANDOM() LIMIT 4"
xbmc.log( "[ script.cinema.experience ] - SQL: %s" % ( sqlquery, ), level=xbmc.LOGDEBUG )
try:
sqlresult = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sqlquery ), )
xbmc.log( "[ script.cinema.experience ] - sqlresult: %s" % sqlresult, level=xbmc.LOGDEBUG )
movies = sqlresult.split("</field>")
movie_list = movies[ 0:len( movies ) -1 ]
except:
xbmc.log( "[ script.cinema.experience ] - Error searching database", level=xbmc.LOGNOTICE )
return movie_list
def auto_refresh( before, mode ):
xbmc.log( "[ script.cinema.experience ] - auto_refresh( %s, %s )" % ( before, mode ), level=xbmc.LOGNOTICE )
# turn off autorefresh
if _S_( "autorefresh" ) == "true" and before == "True" and mode=="disable":
xbmc.executehttpapi( "SetGUISetting(1; videoplayer.adjustrefreshrate; False)" )
# turn on autorefresh
elif _S_( "autorefresh" ) == "true" and before == "True" and mode=="enable":
xbmc.executehttpapi( "SetGUISetting(1; videoplayer.adjustrefreshrate; True)" )
status = True
status = xbmc.executehttpapi( "GetGuiSetting(1; videoplayer.adjustrefreshrate)" ).strip("<li>")
xbmc.log( "[ script.cinema.experience ] - Autorefresh Status: %s" % status, level=xbmc.LOGNOTICE )
def trivia_intro():
xbmc.log( "[ script.cinema.experience ] - ## Intro ##", level=xbmc.LOGNOTICE)
play_list = playlist
play_list.clear()
# initialize intro lists
playlist_intro = []
# get trivia intro videos
_get_special_items( playlist=play_list,
items=( 0, 1, 1, 2, 3, 4, 5, )[ int( _S_( "trivia_intro" ) ) ],
path=( xbmc.translatePath( _S_( "trivia_intro_file" ) ), xbmc.translatePath( _S_( "trivia_intro_folder" ) ), )[ int( _S_( "trivia_intro" ) ) > 1 ],
genre=_L_( 32609 ),
index=0,
media_type="video"
)
if not int( _S_( "trivia_intro" ) ) == 0:
xbmc.Player().play( play_list )
def start_downloader( mpaa, genre, equivalent_mpaa ):
# start the downloader if Play Mode is set to stream and if scraper is not Local or XBMC_library
if ( int( _S_( "trailer_play_mode" ) ) == 1 ) and ( not ( int( _S_( "trailer_scraper" ) ) in (2, 3) ) ):
xbmc.log( "[ script.cinema.experience ] - Starting Downloader Thread", level=xbmc.LOGNOTICE )
thread = Thread( target=downloader, args=( mpaa, equivalent_mpaa ) )
thread.start()
#_genre = genre.replace( " / ", "_" )
#downloader_path = os.path.join( BASE_RESOURCE_PATH, "lib", "new_trailer_downloader.py,mpaa=%s;genre=%s" % ( equivalent_mpaa, _genre ) )
#print downloader_path
#xbmc.executebuiltin( "XBMC.RunScript(%s)" % downloader_path )
else:
pass
def activate_ha( trigger = None, prev_trigger = None, mode="thread" ):
if _S_( "ha_enable" ) == "true" and ha_imported:
if _S_( "ha_multi_trigger" ) == "true" and prev_trigger == trigger:
pass
elif mode != "thread":
activate_on( trigger )
else:
thread = Thread( name='ha_trigger', target=activate_on, args=( trigger, ) )
thread.start()
if not trigger in ( _L_( 32618 ), _L_( 32619 ) ):
prev_trigger = trigger
return prev_trigger
def _play_trivia( mpaa, genre, plist, equivalent_mpaa ):
activate_ha( _L_( 32613 ) ) # Script Start - Or where it seems to be
# if trivia path and time to play the trivia slides
pDialog = xbmcgui.DialogProgress()
pDialog.create( __script__, _L_( 32520 ) )
pDialog.update( 0 )
if int( _S_( "trivia_mode" ) ) == 2: # Start Movie Quiz Script
xbmc.log( "[ script.cinema.experience ] - Starting script.moviequiz", level=xbmc.LOGNOTICE )
start_downloader( mpaa, genre, equivalent_mpaa )
try:
_MA_= xbmcaddon.Addon( "script.moviequiz" )
BASE_MOVIEQUIZ_PATH = xbmc.translatePath( _MA_.getAddonInfo('path') )
sys.path.append( BASE_MOVIEQUIZ_PATH )
try:
import quizlib.question as question
xbmc.log( "[ script.cinema.experience ] - Loaded question module", level=xbmc.LOGNOTICE )
except ImportError:
traceback.print_exc()
xbmc.log( "[ script.cinema.experience ] - Failed to Load question module", level=xbmc.LOGNOTICE )
except:
traceback.print_exc()
try:
import quizlib.mq_ce_play as moviequiz
xbmc.log( "[ script.cinema.experience ] - Loaded mq_ce_play module", level=xbmc.LOGNOTICE )
except ImportError:
traceback.print_exc()
xbmc.log( "[ script.cinema.experience ] - Failed to Load mq_ce_play module", level=xbmc.LOGNOTICE )
except:
traceback.print_exc()
pDialog.close()
activate_ha( _L_( 32613 ) ) # Script Start - Or where it seems to be
trivia_intro()
if playlist.size() > 0:
_wait_until_end()
xbmc.sleep(500) # wait .5 seconds
path = _MA_.getAddonInfo('path')
question_type = 1
mode = ( True, False )[int( _S_( "trivia_moviequiz_mode" ) ) ]
mpaa = ( _S_( "trivia_rating" ), equivalent_mpaa, )[ _S_( "trivia_limit_query" ) == "true" ]
question_limit = int( float( _S_( "trivia_moviequiz_qlimit" ) ) )
completion = moviequiz.runCinemaExperience( question_type, mode, mpaa, genre, question_limit )
if completion:
xbmc.log( "[ script.cinema.experience ] - Completed script.moviequiz", level=xbmc.LOGNOTICE )
else:
xbmc.log( "[ script.cinema.experience ] - Failed in script.moviequiz", level=xbmc.LOGNOTICE )
except:
traceback.print_exc()
xbmc.log( "[ script.cinema.experience ] - Failed to start script.moviequiz", level=xbmc.LOGNOTICE )
_rebuild_playlist( plist )
import xbmcscript_player as script
script.Main()
xbmc.sleep(500) # wait .5 seconds
xbmc.Player().play( playlist )
elif _S_( "trivia_folder" ) and int( _S_( "trivia_mode" ) ) == 1: # Start Slide Show
start_downloader( mpaa, genre, equivalent_mpaa )
## update dialog with new message
pDialog.update( -1, _L_( 32510 ) )
# trivia settings, grab them here so we don't need another _S_() object
if not int( _S_( "trivia_music" ) )== 0:
pDialog.update( -1, _L_( 32511 ) )
build_music_playlist()
# set the proper mpaa rating user preference
mpaa = ( _S_( "trivia_rating" ), equivalent_mpaa, )[ _S_( "trivia_limit_query" ) == "true" ]
xbmc.log( "[ script.cinema.experience ] - Slide MPAA Rating: %s" % equivalent_mpaa, level=xbmc.LOGNOTICE )
# import trivia module and execute the gui
pDialog.update( 50 )
slide_playlist = _fetch_slides( equivalent_mpaa )
pDialog.close()
trivia_intro()
if playlist.size() > 0:
activate_ha( _L_( 32609 ) ) # Trivia Intro
_wait_until_end()
xbmc.sleep(1500) # wait 1.5 seconds
from xbmcscript_trivia import Trivia
xbmc.log( "[ script.cinema.experience ] - Starting Trivia script", level=xbmc.LOGNOTICE )
activate_ha( _L_( 32615 ) ) # Trivia Start
__builtin__.plist = plist
__builtin__.slide_playlist = slide_playlist
__builtin__.movie_mpaa = mpaa
__builtin__.movie_genre = genre
ui = Trivia( "script-CExperience-trivia.xml", _A_.getAddonInfo('path'), "default", "720p" )
ui.doModal()
del ui
# we need to activate the video window
xbmc.sleep(500) # wait .5 seconds
xbmc.executebuiltin( "XBMC.ActivateWindow(2005)" )
xbmc.Player().play( playlist )
elif int( _S_( "trivia_mode" ) ) == 0: # No Trivia
# no trivia slide show so play the video
pDialog.close()
start_downloader( mpaa, genre, equivalent_mpaa )
_rebuild_playlist( plist )
# play the video playlist
import xbmcscript_player as script
script.Main()
activate_ha( _L_( 32613 ) ) # Script Start - Or where it seems to be
xbmc.sleep(500) # wait .5 seconds
xbmc.Player().play( playlist )
def start_script( library_view = "oldway" ):
messy_exit = False
xbmc.log( "[ script.cinema.experience ] - Library_view: %s" % library_view, level=xbmc.LOGNOTICE )
# turn off autorefresh
early_exit = False
autorefresh_movie = False
movie_next = False
prev_trigger = None
auto_refresh( autorefresh, "disable" )
if library_view != "oldway":
xbmc.executebuiltin( "ActivateWindow(videolibrary,%s,return)" % library_view )
# wait until Video Library shows
while not xbmc.getCondVisibility( "Container.Content(movies)" ):
pass
if _S_( "enable_notification" ) == "true":
xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % (header, _L_( 32546 ), 300000, image) )
# wait until playlist is full to the required number of features
xbmc.log( "[ script.cinema.experience ] - Waiting for queue to be filled with %s Feature films" % number_of_features, level=xbmc.LOGNOTICE )
count = 0
while playlist.size() < number_of_features:
if playlist.size() > count:
xbmc.log( "[ script.cinema.experience ] - User queued %s of %s Feature films" % (playlist.size(), number_of_features), level=xbmc.LOGNOTICE )
header1 = header + " - Feature " + "%d" % playlist.size()
message = _L_( 32543 ) + playlist[playlist.size() -1].getdescription()
if _S_( "enable_notification" ) == "true":
xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % (header1, message, time_delay, image) )
count = playlist.size()
xbmc.sleep(time_delay*2)
if not xbmc.getCondVisibility( "Container.Content(movies)" ):
early_exit = True
break
xbmc.log( "[ script.cinema.experience ] - User queued %s Feature films" % playlist.size(), level=xbmc.LOGNOTICE )
if not early_exit:
header1 = header + " - Feature " + "%d" % playlist.size()
message = _L_( 32543 ) + playlist[playlist.size() -1].getdescription()
if _S_( "enable_notification" ) == "true":
xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % (header1, message, time_delay, image) )
early_exit = False
# If for some reason the limit does not get reached and the window changed, cancel script
if playlist.size() < number_of_features and library_view != "oldway":
if _S_( "enable_notification" ) == "true":
xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % (header, _L_( 32544 ), time_delay, image) )
_clear_playlists()
else:
mpaa, audio, genre, movie, equivalent_mpaa = _get_queued_video_info( feature = 0 )
voxcommando()
plist = _store_playlist() # need to store movie playlist
_play_trivia( mpaa, genre, plist, equivalent_mpaa )
_clear_playlists( "music" )
trigger_list = _load_trigger_list()
count = -1
stop_check = 0
paused = False
# prelim programming for adding - Activate script and other additions
while not playlist.getposition() == ( playlist.size() - 1 ):
try:
pauseCheck = xbmc.Player().getTime()
xbmc.sleep( int( ce_pause_time * 1000 ) )
if xbmc.Player().isPlayingVideo():
stop_check = 0
if ( xbmc.Player().getTime() == pauseCheck ) and not paused:
prev_trigger = activate_ha( _L_( 32618 ), prev_trigger )
paused = True
elif not ( xbmc.Player().getTime() == pauseCheck ) and paused:
prev_trigger = activate_ha( _L_( 32619 ), prev_trigger )
paused = False
else:
pass
elif not xbmc.Player().isPlayingVideo():
xbmc.log( "[ script.cinema.experience ] - Video may have stopped", level=xbmc.LOGNOTICE )
except:
if xbmc.getCondVisibility( "Container.Content(movies)" ):
xbmc.log( "[ script.cinema.experience ] - Video Definitely Stopped", level=xbmc.LOGNOTICE )
messy_exit = True
break
#if stop_check == 60:
# xbmc.log( "[ script.cinema.experience ] - Video Definitely Stopped", level=xbmc.LOGNOTICE )
# messy_exit = True
# break
#else:
# xbmc.sleep( 1000 )
# stop_check += 1
if playlist.getposition() > count:
try:
xbmc.log( "[ script.cinema.experience ] - Item From Trigger List: %s" % trigger_list[ playlist.getposition() ], level=xbmc.LOGNOTICE )
except:
xbmc.log( "[ script.cinema.experience ] - Problem With Trigger List", level=xbmc.LOGNOTICE )
xbmc.log( "[ script.cinema.experience ] - Playlist Position: %s Playlist Size: %s " % ( ( playlist.getposition() + 1 ), ( playlist.size() ) ), level=xbmc.LOGNOTICE )
if not playlist.getposition() == ( playlist.size() - 1 ):
prev_trigger = activate_ha( trigger_list[ playlist.getposition() ], prev_trigger )
if trigger_list[ playlist.getposition() ] == "Movie":
if _S_( "autorefresh" ) == "true" and _S_( "autorefresh_movie" ) == "true":
auto_refresh( autorefresh, "enable" )
autorefresh_movie = True
else:
if autorefresh_movie:
auto_refresh( autorefresh, "disable" )
autorefresh_movie = False
xbmc.log( "[ script.cinema.experience ] - autorefresh_movie: %s" % autorefresh_movie, level=xbmc.LOGNOTICE )
count = playlist.getposition()
else:
break # Reached the last item in the playlist
if not playlist.size() < 1 and not messy_exit: # To catch an already running script when a new instance started
xbmc.log( "[ script.cinema.experience ] - Playlist Position: %s Playlist Size: %s " % ( playlist.getposition() + 1, ( playlist.size() ) ), level=xbmc.LOGNOTICE )
prev_trigger = activate_ha( trigger_list[ playlist.getposition() ], prev_trigger, "normal" )
if trigger_list[ playlist.getposition() ] == "Movie":
xbmc.log( "[ script.cinema.experience ] - Item From Trigger List: %s" % trigger_list[ playlist.getposition() ], level=xbmc.LOGNOTICE )
if _S_( "autorefresh" ) == "true" and _S_( "autorefresh_movie" ) == "true":
auto_refresh( autorefresh, "enable" )
autorefresh_movie = True
else:
xbmc.log( "[ script.cinema.experience ] - Item From Trigger List: %s" % trigger_list[ playlist.getposition() ], level=xbmc.LOGNOTICE )
if autorefresh_movie:
auto_refresh( autorefresh, "disable" )
autorefresh_movie == False
messy_exit = False
_wait_until_end()
else:
xbmc.log( "[ script.cinema.experience ] - User might have pressed stop", level=xbmc.LOGNOTICE )
xbmc.log( "[ script.cinema.experience ] - Stopping Script", level=xbmc.LOGNOTICE )
messy_exit = False
return messy_exit
if __name__ == "__main__" :
xbmc.sleep( 2000 )
footprints()
prev_trigger = ""
loglevel = int(xbmc.executehttpapi( "GetLogLevel" ).replace( "<li>", "" ) )
xbmc.log( "[ script.cinema.experience ] - Log Level: %s" % loglevel, level=xbmc.LOGNOTICE )
settings_to_log( BASE_CURRENT_SOURCE_PATH, script_header )
# check to see if an argv has been passed to script
xbmcgui.Window(10025).setProperty( "CinemaExperienceRunning", "True" )
try:
try:
if sys.argv[ 1 ]:
xbmc.log( "[ script.cinema.experience ] - Script Started With: %s" % sys.argv[ 1 ], level=xbmc.LOGNOTICE )
try:
_command = ""
titles = ""
if sys.argv[ 1 ] == "ClearWatchedTrivia" or sys.argv[ 1 ] == "ClearWatchedTrailers":
_clear_watched_items( sys.argv[ 1 ] )
exit = True
elif sys.argv[ 1 ] == "ViewChangelog":
_view_changelog()
exit = True
elif sys.argv[ 1 ] == "ViewReadme":
_view_readme()
exit = True
elif sys.argv[ 1 ] == "oldway":
_A_.setSetting( id='number_of_features', value='0' ) # set number of features to 1
_clear_playlists()
xbmc.sleep( 250 )
xbmc.executebuiltin( "Action(Queue,%d)" % ( xbmcgui.getCurrentWindowId() - 10000, ) )
xbmc.log( "[ script.cinema.experience ] - Action(Queue,%d)" % ( xbmcgui.getCurrentWindowId() - 10000, ), level=xbmc.LOGNOTICE )
# we need to sleep so the video gets queued properly
xbmc.sleep( 250 )
autorefresh_movie = False
exit = start_script( "oldway" )
elif sys.argv[ 1 ].startswith( "command" ): # Command Arguments
_sys_arg = sys.argv[ 1 ].replace("<li>",";")
_command = re.split(";", _sys_arg, maxsplit=1)[1]
xbmc.log( "[ script.cinema.experience ] - Command Call: %s" % _command, level=xbmc.LOGNOTICE )
if _command.startswith( "movie_title" ): # Movie Title
_clear_playlists()
if _command.startswith( "movie_title;" ):
titles = re.split(";", _command, maxsplit=1)[1]
elif _command.startswith( "movie_title=" ):
titles = re.split("=", _command, maxsplit=1)[1]
movie_titles = titles.split( ";" )
if not movie_titles == "":
_build_playlist( movie_titles )
autorefresh_movie = False
exit = start_script( "oldway" )
else:
exit = False
elif _command.startswith( "sqlquery" ): # SQL Query
_clear_playlists()
sqlquery = re.split(";", _command, maxsplit=1)[1]
movie_titles = _sqlquery( sqlquery )
if not movie_titles == "":
_build_playlist( movie_titles )
autorefresh_movie = False
exit = start_script( "oldway" )
else:
exit = False
elif _command.startswith( "open_settings" ): # Open Settings
_A_.openSettings()
exit = False
else:
_clear_playlists()
exit = start_script( sys.argv[ 1 ].lower() )
except:
traceback.print_exc()
except:
if not int( xbmcgui.getCurrentWindowId() ) == 10001: # Not Started from Addon/Programs window
#start script in 'Old Way' if the script is called with out argv... queue the movie the old way
_A_.setSetting( id='number_of_features', value='0' ) # set number of features to 1
_clear_playlists()
xbmc.executebuiltin( "Action(Queue,%d)" % ( xbmcgui.getCurrentWindowId() - 10000, ) )
xbmc.log( "[ script.cinema.experience ] - Action(Queue,%d)" % ( xbmcgui.getCurrentWindowId() - 10000, ), level=xbmc.LOGNOTICE )
# we need to sleep so the video gets queued properly
xbmc.sleep( 500 )
autorefresh_movie = False
exit = start_script( "oldway" )
else:
_A_.openSettings()
exit = True
# turn on autorefresh if script turned it off
#xbmc.executebuiltin("Notification( %s, %s, %d, %s)" % (header, _L_( 32545 ), time_delay, image) )
xbmc.log( "[ script.cinema.experience ] - messy_exit: %s" % exit, level=xbmc.LOGNOTICE )
if exit:
pass
else:
_clear_playlists()
if _S_( "autorefresh" ) == "true":
auto_refresh( autorefresh, "enable" )
prev_trigger = activate_ha( _L_( 32614 ), None, "normal" ) # Script End
_A_.setSetting( id='number_of_features', value='%d' % (number_of_features - 1) )
xbmc.executehttpapi( "SetGUISetting(3,screensaver.mode,%s)" % screensaver )
xbmcgui.Window(10025).setProperty( "CinemaExperienceRunning", "False" )
except:
traceback.print_exc()
# if script fails, changes settings back
if _S_( "autorefresh" ) == "true":
auto_refresh( autorefresh, "enable" )
_A_.setSetting( id='number_of_features', value='%d' % (number_of_features - 1) )
xbmc.executehttpapi( "SetGUISetting(3,screensaver.mode,%s)" % screensaver )
prev_trigger = activate_ha( _L_( 32614 ), None, "normal" ) # Script End
xbmcgui.Window(10025).setProperty( "CinemaExperienceRunning", "False" )
#sys.modules.clear()