Skip to content
Browse files

Commit before major code rework

  • Loading branch information...
1 parent 12df282 commit 357898a58b2332275a08e78c60e10f67d7358b22 @Giftie committed
View
804 addon.py
@@ -4,17 +4,17 @@
__script__ = "Cinema Experience"
__author__ = "nuka1195-giftie-ackbarr"
__url__ = "https://github.com/Giftie/script.cinema.experience"
-__version__ = "2.0.57"
+__version__ = "3.0.0"
__scriptID__ = "script.cinema.experience"
-import xbmcgui, xbmc, xbmcaddon, os, re, sys
-import traceback
-import time
+
+
+
+import xbmcgui, xbmc, xbmcaddon, xbmcvfs
+import os, re, sys, socket, traceback, time, __builtin__
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
@@ -22,62 +22,187 @@
# settings method
_S_ = _A_.getSetting
-number_of_features = int( _S_( "number_of_features" ) ) + 1
+true = True
+false = False
+null = None
+
+triggers = ( "Script Start", "Trivia Intro", "Trivia", "Trivia Outro", "Coming Attractions Intro", "Movie Trailer",
+ "Coming Attractions Outro", "Movie Theater Intro", "Countdown", "Feature Presentation Intro", "Audio Format",
+ "MPAA Rating", "Movie", "Feature Presentation Outro", "Movie Theatre Outro", "Intermission", "Script End", "Pause", "Resume" )
+
+trivia_settings = { "trivia_mode": int( _S_( "trivia_mode" ) ),
+ "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": eval( _S_( "trivia_adjust_volume" ) ),
+ "trivia_fade_volume": eval( _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": eval( _S_( "trivia_unwatched_only" ) ),
+ "trivia_limit_query": eval( _S_( "trivia_limit_query" ) )
+ }
+
+trailer_settings = { "trailer_count": ( 0, 1, 2, 3, 4, 5, 10, )[int( float( _S_( "trailer_count" ) ) ) ],
+ "trailer_scraper": ( "amt_database", "amt_current", "local", "xbmc_library", )[int( float( _S_( "trailer_scraper" ) ) ) ],
+ "trailer_play_mode": int( float( _S_( "trailer_play_mode" ) ) ),
+ "trailer_download_folder": xbmc.translatePath( _S_( "trailer_download_folder" ) ),
+ "trailer_folder": xbmc.translatePath( _S_( "trailer_folder" ) ),
+ "trailer_amt_db_file": xbmc.translatePath( _S_( "trailer_amt_db_file" ) ),
+ "trailer_newest_only": eval( _S_( "trailer_newest_only" ) ),
+ "trailer_quality": ( "Standard", "480p", "720p", "1080p" )[ int( float( _S_( "trailer_quality" ) ) ) ],
+ "trailer_quality_url": ( "", "_480p", "_720p", "_720p", )[ int( float( _S_( "trailer_quality" ) ) ) ],
+ "trailer_hd_only": eval( _S_( "trailer_hd_only" ) ),
+ "trailer_limit_mpaa": eval( _S_( "trailer_limit_mpaa" ) ),
+ "trailer_limit_genre": eval( _S_( "trailer_limit_genre" ) ),
+ "trailer_rating": _S_( "trailer_rating" ),
+ "trailer_unwatched_movie_only": eval( _S_( "trailer_unwatched_movie_only" ) ),
+ "trailer_unwatched_only": eval( _S_( "trailer_unwatched_only" ) )
+ }
+
+video_settings = { "mte_intro": ( 0, 1, 1, 2, 3, 4, 5, )[ int( float( _S_( "mte_intro" ) ) ) ],
+ "mte_intro_type": ( "file", "folder" )[ int( float( _S_( "mte_intro" ) ) ) > 1 ],
+ "mte_intro_file": xbmc.translatePath( _S_( "mte_intro_file" ) ).decode('utf-8'),
+ "mte_intro_folder": xbmc.translatePath( _S_( "mte_intro_folder" ) ).decode('utf-8'),
+ "mte_outro": ( 0, 1, 1, 2, 3, 4, 5, )[ int( float( _S_( "mte_outro" ) ) ) ],
+ "mte_outro_type": ( "file", "folder" )[ int( float( _S_( "mte_outro" ) ) ) > 1 ],
+ "mte_outro_file": xbmc.translatePath( _S_( "mte_outro_file" ) ).decode('utf-8'),
+ "mte_outro_folder": xbmc.translatePath( _S_( "mte_outro_folder" ) ).decode('utf-8'),
+ "fpv_intro": ( 0, 1, 1, 2, 3, 4, 5, )[ int( float( _S_( "fpv_intro" ) ) ) ],
+ "fpv_intro_type": ( "file", "folder" )[ int( float( _S_( "fpv_intro" ) ) ) > 1 ],
+ "fpv_intro_file": xbmc.translatePath( _S_( "fpv_intro_file" ) ).decode('utf-8'),
+ "fpv_intro_folder": xbmc.translatePath( _S_( "fpv_intro_folder" ) ).decode('utf-8'),
+ "fpv_outro": ( 0, 1, 1, 2, 3, 4, 5, )[ int( float( _S_( "fpv_outro" ) ) ) ],
+ "fpv_outro_type": ( "file", "folder" )[ int( float( _S_( "fpv_outro" ) ) ) > 1 ],
+ "fpv_outro_file": xbmc.translatePath( _S_( "fpv_outro_file" ) ).decode('utf-8'),
+ "fpv_outro_folder": xbmc.translatePath( _S_( "fpv_outro_folder" ) ).decode('utf-8'),
+ "enable_ratings": eval( _S_( "enable_ratings" ) ),
+ "rating_videos_folder": xbmc.translatePath( _S_( "rating_videos_folder" ) ).decode('utf-8'),
+ "enable_audio": eval( _S_( "enable_audio" ) ),
+ "audio_videos_folder": xbmc.translatePath( _S_( "audio_videos_folder" ) ).decode('utf-8'),
+ "countdown_video": ( 0, 1, 1, 2, 3, 4, 5, )[ int( float( _S_( "countdown_video" ) ) ) ],
+ "countdown_video_type": ( "file", "folder" )[ int( float( _S_( "countdown_video" ) ) ) > 1 ],
+ "countdown_video_file": xbmc.translatePath( _S_( "countdown_video_file" ) ).decode('utf-8'),
+ "countdown_video_folder": xbmc.translatePath( _S_( "countdown_video_folder" ) ).decode('utf-8'),
+ "cav_intro": ( 0, 1, 1, 2, 3, 4, 5, )[ int( float( _S_( "cav_outro" ) ) ) ],
+ "cav_intro_type": ( "file", "folder" )[ int( float( _S_( "cav_intro" ) ) ) > 1 ],
+ "cav_intro_file": xbmc.translatePath( _S_( "cav_intro_file" ) ).decode('utf-8'),
+ "cav_intro_folder": xbmc.translatePath( _S_( "cav_intro_folder" ) ).decode('utf-8'),
+ "cav_outro": ( 0, 1, 1, 2, 3, 4, 5, )[ int( float( _S_( "cav_outro" ) ) ) ],
+ "cav_outro_type": ( "file", "folder" )[ int( float( _S_( "cav_outro" ) ) ) > 1 ],
+ "cav_outro_file": xbmc.translatePath( _S_( "cav_outro_file" ) ).decode('utf-8'),
+ "cav_outro_folder": xbmc.translatePath( _S_( "cav_outro_folder" ) ).decode('utf-8'),
+ "trivia_intro": ( 0, 1, 1, 2, 3, 4, 5, )[ int( float( _S_( "trivia_intro" ) ) ) ],
+ "trivia_intro_type": ( "file", "folder" )[ int( float( _S_( "trivia_intro" ) ) ) > 1 ],
+ "trivia_intro_file": xbmc.translatePath( _S_( "trivia_intro_file" ) ).decode('utf-8'),
+ "trivia_intro_folder": xbmc.translatePath( _S_( "trivia_intro_folder" ) ).decode('utf-8'),
+ "trivia_outro": ( 0, 1, 1, 2, 3, 4, 5, )[ int( float( _S_( "trivia_outro" ) ) ) ],
+ "trivia_outro_type": ( "file", "folder" )[ int( float( _S_( "trivia_outro" ) ) ) > 1 ],
+ "trivia_outro_file": xbmc.translatePath( _S_( "trivia_outro_file" ) ).decode('utf-8'),
+ "trivia_outro_folder": xbmc.translatePath( _S_( "trivia_outro_folder" ) ).decode('utf-8')
+ }
+
+feature_settings = { "enable_notification": eval( _S_( "enable_notification" ) ),
+ "number_of_features": int( float( _S_( "number_of_features" ) ) ),
+ "intermission_video": ( 0, 1, 1, 2, 3, 4, 5, )[ int( float( _S_( "intermission_video" ) ) ) ],
+ "intermission_video_type": ( "file", "folder" )[ int( _S_( "intermission_video" ) ) > 1 ],
+ "intermission_video_file": xbmc.translatePath( _S_( "intermission_video_file" ) ).decode('utf-8'),
+ "intermission_video_folder": xbmc.translatePath( _S_( "intermission_video_folder" ) ).decode('utf-8'),
+ "intermission_audio": eval( _S_( "intermission_audio" ) ),
+ "intermission_ratings": eval( _S_( "intermission_ratings" ) )
+ }
+
+ha_settings = { "ha_enable": eval( _S_( "ha_enable" ) ),
+ "ha_multi_trigger": eval( _S_( "ha_multi_trigger" ) ),
+ "ha_script_start": eval( _S_( "ha_script_start" ) ),
+ "ha_trivia_intro": eval( _S_( "ha_trivia_intro" ) ),
+ "ha_trivia_start": eval( _S_( "ha_trivia_start" ) ),
+ "ha_trivia_outro": eval( _S_( "ha_trivia_outro" ) ),
+ "ha_mte_intro": eval( _S_( "ha_mte_intro" ) ),
+ "ha_cav_intro": eval( _S_( "ha_cav_intro" ) ),
+ "ha_trailer_start": eval( _S_( "ha_trailer_start" ) ),
+ "ha_cav_outro": eval( _S_( "ha_cav_outro" ) ),
+ "ha_fpv_intro": eval( _S_( "ha_fpv_intro" ) ),
+ "ha_mpaa_rating": eval( _S_( "ha_mpaa_rating" ) ),
+ "ha_countdown_video": eval( _S_( "ha_countdown_video" ) ),
+ "ha_audio_format": eval( _S_( "ha_audio_format" ) ),
+ "ha_movie": eval( _S_( "ha_movie" ) ),
+ "ha_fpv_outro": eval( _S_( "ha_fpv_outro" ) ),
+ "ha_mte_outro": eval( _S_( "ha_mte_outro" ) ),
+ "ha_intermission": eval( _S_( "ha_intermission" ) ),
+ "ha_script_end": eval( _S_( "ha_script_end" ) ),
+ "ha_paused": eval( _S_( "ha_paused" ) ),
+ "ha_resumed": eval( _S_( "ha_resumed" ) )
+ }
+
+number_of_features = feature_settings[ "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' ) )
+BASE_CACHE_PATH = os.path.join( xbmc.translatePath( "special://profile" ).decode('utf-8'), "Thumbnails", "Video" )
+BASE_CURRENT_SOURCE_PATH = os.path.join( xbmc.translatePath( "special://profile/addon_data/" ).decode('utf-8'), os.path.basename( _A_.getAddonInfo('path') ) )
+BASE_RESOURCE_PATH = xbmc.translatePath( os.path.join( _A_.getAddonInfo('path').decode('utf-8'), '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") )
+image = xbmc.translatePath( os.path.join( _A_.getAddonInfo("path"), "icon.png") ).decode('utf-8')
playlist = xbmc.PlayList( xbmc.PLAYLIST_VIDEO )
+is_paused = False
prev_trigger = ""
script_header = "[ %s ]" % __scriptID__
-from ce_playlist import _get_special_items, _wait_until_end, build_music_playlist, _rebuild_playlist
+from ce_playlist import _get_special_items, 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
+from pre_eden_code import _store_playlist, _get_queued_video_info
#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":
+ if not xbmcvfs.exists( os.path.join( BASE_CURRENT_SOURCE_PATH, "ha_scripts", "home_automation.py" ) ) and ha_settings[ "ha_enable" ]:
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 )
+ xbmcvfs.mkdir( os.path.join( BASE_CURRENT_SOURCE_PATH, "ha_scripts" ) )
+ xbmcvfs.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
+ from home_automation import Automate
# Import HA module set ha_imported to True if successful
ha_imported = True
except ImportError:
# or ha_imported to False if unsuccessful
+ xbmc.log( "[ script.cinema.experience ] - Failed to import Automate", level=xbmc.LOGNOTICE )
ha_imported = False
+except:
+ traceback.print_exc()
+ ha_imported = False
+
+ce_pause_time = int( float( _S_("ha_pause_time") ) )
+
+class CE_Player( xbmc.Player ):
+ def __init__(self, *args, **kwargs):
+ xbmc.Player.__init__( self )
+
+ def onPlayBackPaused( self ):
+ Launch_automation().launch_automation( trigger = "Pause", prev_trigger = None )
+ is_paused = True
+
+ def onPlayBackResumed( self ):
+ Launch_automation().launch_automation( trigger = "Resumed", prev_trigger = None )
+ is_paused = False
+
+class Launch_automation():
+ def __init__(self, *args, **kwargs):
+ pass
+
+ def launch_automation( self, trigger = None, prev_trigger = None, mode="normal" ):
+ if _S_( "ha_enable" ) == "true":
+ prev_trigger = Automate().activate_ha( trigger, prev_trigger, mode )
+ return prev_trigger
-#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 )
@@ -108,11 +233,10 @@ def _clear_watched_items( clear_type ):
# 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 )
+ Scraper = scraper.Main()
# update trailers
Scraper.clear_watched()
# set base watched file path
@@ -127,37 +251,14 @@ def _clear_watched_items( clear_type ):
# remove watched status file(s)
for base_path in base_paths:
# remove file if it exists
- if ( exists( base_path ) ):
- delete_file( base_path )
+ if ( xbmcvfs.exists( base_path ) ):
+ xbmcvfs.delete( 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":
@@ -168,269 +269,323 @@ def _clear_playlists( mode="both" ):
mplaylist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
mplaylist.clear()
xbmc.log( "[ script.cinema.experience ] - Music Playlist Cleared", level=xbmc.LOGNOTICE )
-# No longer works in Frodo to be removed - might be possible to convert to JSON RPC
-def voxcommando():
- playlistsize = playlist.size()
- if playlistsize > 1:
- movie_titles = ""
- #for feature_count in range (1, playlistsize + 1):
- for feature_count in range (1, playlistsize):
- 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)" )
-# No longer works in Frodo to be removed
-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 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()
- 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 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 )
+def _build_playlist( movies, mode = "movie_titles" ):
+ if mode == "movie_titles":
+ xbmc.log( "[script.cinema.experience] - Movie Title Mode", level=xbmc.LOGNOTICE )
+ for movie in movies:
+ xbmc.log( "[script.cinema.experience] - Movie Title: %s" % movie, level=xbmc.LOGNOTICE )
+ xbmc.executehttpapi( "SetResponseFormat()" )
+ xbmc.executehttpapi( "SetResponseFormat(OpenField,)" )
+ # select Movie path from movieview Limit 1
+ sql = "SELECT movieview.idMovie, movieview.c00, movieview.strPath, movieview.strFileName, movieview.c08, movieview.c14 FROM movieview WHERE c00 LIKE '%s' LIMIT 1" % ( movie.replace( "'", "''", ), )
+ xbmc.log( "[script.cinema.experience] - SQL: %s" % ( sql, ), level=xbmc.LOGDEBUG )
+ # query database for info dummy is needed as there are two </field> formatters
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 )
+ movie_id, movie_title, movie_path, movie_filename, thumb, genre, dummy = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql ), ).split( "</field>" )
+ movie_id = int( movie_id )
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 )
- # trivia settings, grab them here so we don't need another _S_() object
- if not int( _S_( "trivia_music" ) )== 0:
- 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
- slide_playlist = _fetch_slides( equivalent_mpaa )
- trivia_intro()
- if playlist.size() > 0:
- activate_ha( _L_( 32609 ) ) # Trivia Intro
- _wait_until_end()
- xbmc.sleep(500) # wait .5 seconds
- __builtin__.plist = plist
- __builtin__.slide_playlist = slide_playlist
- __builtin__.movie_mpaa = mpaa
- __builtin__.movie_genre = genre
- from xbmcscript_trivia import Trivia
- xbmc.log( "[ script.cinema.experience ] - Starting Trivia script", level=xbmc.LOGNOTICE )
- activate_ha( _L_( 32615 ) ) # Trivia Start
- ui = Trivia( "script-CExperience-trivia.xml", _A_.getAddonInfo('path'), "default", "720p" )
- ui.doModal()
- del ui
- # we need to activate the video window
- xbmc.sleep(5) # wait .005 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
- 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 )
- early_exit = False
- movie_next = False
- prev_trigger = None
- 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 )
+ xbmc.log( "[script.cinema.experience] - Unable to match movie", level=xbmc.LOGERROR )
+ movie_id = 0
+ movie_title = movie_path = movie_filename = thumb = genre = dummy = ""
+ movie_full_path = os.path.join(movie_path, movie_filename).replace("\\\\" , "\\")
+ xbmc.log( "[script.cinema.experience] - Movie Title: %s" % movie_title, level=xbmc.LOGNOTICE )
+ xbmc.log( "[script.cinema.experience] - Movie Path: %s" % movie_path, level=xbmc.LOGNOTICE )
+ xbmc.log( "[script.cinema.experience] - Movie Filename: %s" % movie_filename, level=xbmc.LOGNOTICE )
+ xbmc.log( "[script.cinema.experience] - Full Movie Path: %s" % movie_full_path, level=xbmc.LOGNOTICE )
+ if not movie_id == 0:
+ json_command = '{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 1, "item": {"movieid": %d} }, "id": 1}' % int( movie_id )
+ json_response = xbmc.executeJSONRPC(json_command)
+ xbmc.log( "[script.cinema.experience] - JSONRPC Response: \n%s" % json_response, level=xbmc.LOGDEBUG )
+ xbmc.sleep( 50 )
+ elif mode == "movie_ids":
+ xbmc.log( "[script.cinema.experience] - Movie ID Mode", level=xbmc.LOGNOTICE )
+ for movie_id in movies:
+ xbmc.log( "[script.cinema.experience] - Movie ID: %s" % movie_id, level=xbmc.LOGNOTICE )
+ json_command = '{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 1, "item": {"movieid": %d} }, "id": 1}' % int( movie_id )
+ json_response = xbmc.executeJSONRPC( json_command )
+ xbmc.log( "[script.cinema.experience] - JSONRPC Response: \n%s" % json_response, level=xbmc.LOGDEBUG )
+ xbmc.sleep( 50 )
+
+class Script():
+ def __init__(self, *args, **kwargs):
+ self. init_var()
+
+ def init_var( self ):
+ self.player = CE_Player()
+
+ def start_script( self, library_view = "oldway" ):
+ messy_exit = False
+ xbmc.log( "[ script.cinema.experience ] - Library_view: %s" % library_view, level=xbmc.LOGNOTICE )
+ early_exit = False
+ movie_next = False
+ prev_trigger = None
+ 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) )
- 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()
+ 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)" % (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 )
- 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
+ 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 )
+ plist = _store_playlist() # need to store movie playlist
+ self._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 ):
+ 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 = Launch_automation().launch_automation( trigger_list[ playlist.getposition() ], prev_trigger )
+ count = playlist.getposition()
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 playlist.getposition() > count:
+ break # Reached the last item in the playlist
try:
- xbmc.log( "[ script.cinema.experience ] - Item From Trigger List: %s" % trigger_list[ playlist.getposition() ], level=xbmc.LOGNOTICE )
+ #if not self.player.isPlayingVideo() and not is_paused:
+ if not xbmc.getCondVisibility( "Window.IsActive(fullscreenvideo)" ):
+ xbmc.log( "[ script.cinema.experience ] - Video may have stopped", level=xbmc.LOGNOTICE )
+ messy_exit = True
+ break
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 )
- 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 xbmc.getCondVisibility( "Container.Content(movies)" ):
+ xbmc.log( "[ script.cinema.experience ] - Video Definitely Stopped", level=xbmc.LOGNOTICE )
+ messy_exit = True
+ break
+ 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 = Launch_automation().launch_automation( trigger_list[ playlist.getposition() ], prev_trigger )
+ if trigger_list[ playlist.getposition() ] == "Movie":
+ xbmc.log( "[ script.cinema.experience ] - Item From Trigger List: %s" % trigger_list[ playlist.getposition() ], level=xbmc.LOGNOTICE )
+ else:
+ xbmc.log( "[ script.cinema.experience ] - Item From Trigger List: %s" % trigger_list[ playlist.getposition() ], level=xbmc.LOGNOTICE )
+ messy_exit = False
+ xbmc.sleep(1000)
+ self._wait_until_end()
else:
- xbmc.log( "[ script.cinema.experience ] - Item From Trigger List: %s" % trigger_list[ playlist.getposition() ], level=xbmc.LOGNOTICE )
- messy_exit = False
- _wait_until_end()
+ 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
+ del self.player
+ return messy_exit
+
+ def broadcastUDP( self, data, port = 8278 ): # XBMC's former HTTP API output port is 8278
+ IPADDR = '255.255.255.255'
+ PORTNUM = port
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
+ if hasattr(socket,'SO_BROADCAST'):
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+ s.connect((IPADDR, PORTNUM))
+ s.send(data)
+ s.close()
+
+ def voxcommando():
+ playlistsize = playlist.size()
+ if playlistsize > 1:
+ movie_titles = ""
+ #for feature_count in range (1, playlistsize + 1):
+ for feature_count in range (1, playlistsize):
+ 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 eval( _S_( "voxcommando" ) ):
+ self.broadcastUDP( "<b>CElaunch." + str( playlistsize ) + "<li>" + movie_titles + "</b>", port = 33000 )
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
+ # get the queued video info
+ movie_title = playlist[ 0 ].getdescription()
+ xbmc.log( "[ script.cinema.experience ] - Feature - %s" % movie_title, level=xbmc.LOGNOTICE )
+ if eval( _S_( "voxcommando" ) ):
+ self.broadcastUDP( "<b>CElaunch<li>" + movie_title + "</b>", port = 33000 )
+
+ # No longer works in Frodo to be removed
+ def _sqlquery( self, 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 trivia_intro( self ):
+ 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= "Trivia Intro",
+ index=0,
+ media_type="video"
+ )
+ if not int( _S_( "trivia_intro" ) ) == 0:
+ self.player.play( play_list )
+
+ def start_downloader( self, 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, genre, equivalent_mpaa ) )
+ thread.start()
+ else:
+ pass
+
+ def _wait_until_end( self ): # wait until the end of the playlist(for Trivia Intro)
+ xbmc.log( "[ script.cinema.experience ] - Waiting Until End Of Video", level=xbmc.LOGNOTICE)
+ try:
+ self.psize = int( xbmc.PlayList( xbmc.PLAYLIST_VIDEO ).size() ) - 1
+ xbmc.log( "[ script.cinema.experience ] - Playlist Size: %s" % ( self.psize + 1 ), level=xbmc.LOGDEBUG)
+ while xbmc.PlayList( xbmc.PLAYLIST_VIDEO ).getposition() < self.psize:
+ pass
+ xbmc.log( "[ script.cinema.experience ] - Video TotalTime: %s" % self.player.getTotalTime(), level=xbmc.LOGDEBUG)
+ while self.player.getTime() < ( self.player.getTotalTime() - 1 ):
+ pass
+ xbmc.log( "[ script.cinema.experience ] - Video getTime: %s" % self.player.getTime(), level=xbmc.LOGDEBUG)
+ #xbmc.sleep(400)
+ except:
+ traceback.print_exc()
+ xbmc.log( "[ script.cinema.experience ] - Video either stopped or skipped, Continuing on...", level=xbmc.LOGDEBUG)
+
+ def _play_trivia( self, mpaa, genre, plist, equivalent_mpaa ):
+ Launch_automation().launch_automation( triggers[0] ) # Script Start - Or where it seems to be
+ if int( _S_( "trivia_mode" ) ) == 2: # Start Movie Quiz Script
+ xbmc.log( "[ script.cinema.experience ] - Starting script.moviequiz", level=xbmc.LOGNOTICE )
+ self.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()
+ Launch_automation().launch_automation( triggers[0] ) # Script Start - Or where it seems to be
+ self.trivia_intro()
+ if playlist.size() > 0:
+ self._wait_until_end()
+ xbmc.sleep(500) # wait .5 seconds
+ path = _MA_.getAddonInfo('path')
+ question_type = 1
+ mode = ( True, False )[ int( float( _S_( "trivia_moviequiz_mode" ) ) ) ]
+ mpaa = ( _S_( "trivia_rating" ), equivalent_mpaa, )[ eval( _S_( "trivia_limit_query" ) ) ]
+ 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
+ self.player.play( playlist )
+ elif _S_( "trivia_folder" ) and int( _S_( "trivia_mode" ) ) == 1: # Start Slide Show
+ self.start_downloader( mpaa, genre, equivalent_mpaa )
+ # trivia settings, grab them here so we don't need another _S_() object
+ if not int( _S_( "trivia_music" ) )== 0:
+ build_music_playlist()
+ # set the proper mpaa rating user preference
+ mpaa = ( _S_( "trivia_rating" ), equivalent_mpaa, )[ eval( _S_( "trivia_limit_query" ) ) ]
+ xbmc.log( "[ script.cinema.experience ] - Slide MPAA Rating: %s" % equivalent_mpaa, level=xbmc.LOGNOTICE )
+ # import trivia module and execute the gui
+ slide_playlist = _fetch_slides( equivalent_mpaa )
+ self.trivia_intro()
+ if playlist.size() > 0:
+ Launch_automation().launch_automation( triggers[1] ) # Trivia Intro
+ xbmc.sleep(500) # wait .5 seconds
+ self._wait_until_end()
+ #xbmc.sleep(500) # wait .5 seconds
+ __builtin__.plist = plist
+ __builtin__.slide_playlist = slide_playlist
+ __builtin__.movie_mpaa = mpaa
+ __builtin__.movie_genre = genre
+ from xbmcscript_trivia import Trivia
+ xbmc.log( "[ script.cinema.experience ] - Starting Trivia script", level=xbmc.LOGNOTICE )
+ Launch_automation().launch_automation( triggers[2] ) # Trivia Start
+ ui = Trivia( "script-CExperience-trivia.xml", _A_.getAddonInfo('path'), "default", "720p" )
+ ui.doModal()
+ del ui
+ # we need to activate the video window
+ #xbmc.sleep(5) # wait .005 seconds
+ xbmc.executebuiltin( "XBMC.ActivateWindow(2005)" )
+ self.player.play( playlist )
+ elif int( _S_( "trivia_mode" ) ) == 0: # No Trivia
+ # no trivia slide show so play the video
+ self.start_downloader( mpaa, genre, equivalent_mpaa )
+ _rebuild_playlist( plist )
+ # play the video playlist
+ import xbmcscript_player as script
+ script.Main()
+ Launch_automation().launch_automation( triggers[0] ) # Script Start - Or where it seems to be
+ xbmc.sleep(500) # wait .5 seconds
+ self.player.play( playlist )
+
if __name__ == "__main__" :
- xbmc.sleep( 2000 )
+ #xbmc.sleep( 2000 )
footprints()
prev_trigger = ""
settings_to_log( BASE_CURRENT_SOURCE_PATH, script_header )
@@ -446,12 +601,6 @@ def start_script( library_view = "oldway" ):
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()
@@ -460,7 +609,7 @@ def start_script( library_view = "oldway" ):
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 )
- exit = start_script( "oldway" )
+ exit = Script().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]
@@ -474,7 +623,7 @@ def start_script( library_view = "oldway" ):
movie_titles = titles.split( ";" )
if not movie_titles == "":
_build_playlist( movie_titles )
- exit = start_script( "oldway" )
+ exit = Script().start_script( "oldway" )
else:
exit = False
elif _command.startswith( "sqlquery" ): # SQL Query
@@ -483,15 +632,24 @@ def start_script( library_view = "oldway" ):
movie_titles = _sqlquery( sqlquery )
if not movie_titles == "":
_build_playlist( movie_titles )
- exit = start_script( "oldway" )
+ exit = Script().start_script( "oldway" )
else:
exit = False
elif _command.startswith( "open_settings" ): # Open Settings
_A_.openSettings()
exit = False
+ elif sys.argv[ 1 ].startswith( "movieid=" ):
+ _clear_playlists()
+ movie_id = sys.argv[ 1 ].split("=")[ 1 ]
+ movie_ids = movie_id.split( ";" )
+ if movie_ids:
+ _build_playlist( movie_ids, mode="movie_ids" )
+ exit = Script().start_script( "oldway" )
+ else:
+ exit = False
else:
_clear_playlists()
- exit = start_script( sys.argv[ 1 ].lower() )
+ exit = Script().start_script( sys.argv[ 1 ].lower() )
except:
traceback.print_exc()
except:
@@ -503,7 +661,7 @@ def start_script( library_view = "oldway" ):
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 )
- exit = start_script( "oldway" )
+ exit = Script().start_script( "oldway" )
else:
_A_.openSettings()
exit = True
@@ -513,12 +671,12 @@ def start_script( library_view = "oldway" ):
pass
else:
_clear_playlists()
- prev_trigger = activate_ha( _L_( 32614 ), None, "normal" ) # Script End
+ prev_trigger = Launch_automation().launch_automation( triggers[16], None ) # Script End
_A_.setSetting( id='number_of_features', value='%d' % (number_of_features - 1) )
xbmcgui.Window(10025).setProperty( "CinemaExperienceRunning", "False" )
except:
traceback.print_exc()
# if script fails, changes settings back
_A_.setSetting( id='number_of_features', value='%d' % (number_of_features - 1) )
- prev_trigger = activate_ha( _L_( 32614 ), None, "normal" ) # Script End
+ prev_trigger = Launch_automation().launch_automation( triggers[16], None ) # Script End
xbmcgui.Window(10025).setProperty( "CinemaExperienceRunning", "False" )
View
213 resources/ha_scripts/home_automation.py
@@ -2,98 +2,127 @@
# to make sure it does not get over written when updating the script
import xbmc, xbmcaddon
+import socket, sys
+from threading import Thread
-_A_ = xbmcaddon.Addon('script.cinema.experience')
-_L_ = _A_.getLocalizedString
-_S_ = _A_.getSetting
+triggers = sys.modules[ "__main__" ].triggers
+ha_settings = sys.modules[ "__main__" ].ha_settings
-def activate_on( trigger = "None" ):
- """
- Scripting to trigger almost anything(HA, other scripts, etc...) when videos start.
-
- Usage:
- activate_on( "Movie" )
- will trigger code that is set under the Movie heading.
+class Automate:
+ def __init__( self ):
+ pass
+
+ def broadcastUDP( self, data, port = 8278 ): # XBMC's former HTTP API output port is 8278
+ IPADDR = '255.255.255.255'
+ PORTNUM = port
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
+ if hasattr(socket,'SO_BROADCAST'):
+ s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+ s.connect((IPADDR, PORTNUM))
+ s.send(data)
+ s.close()
+
+ def activate_ha( self, trigger = None, prev_trigger = None, mode="thread" ):
+ if ha_settings[ "ha_enable" ]:
+ if ha_settings[ "ha_multi_trigger" ] and prev_trigger == trigger:
+ pass
+ elif mode != "thread":
+ self.activate_on( trigger )
+ else:
+ thread = Thread( name='ha_trigger', target=self.activate_on, args=( trigger, ) )
+ thread.start()
+ if not trigger in ( "Pause", "Resumed" ):
+ prev_trigger = trigger
+ return prev_trigger
+
+ def activate_on( self, trigger = None ):
+ """
+ Scripting to trigger almost anything(HA, other scripts, etc...) when videos start.
- """
- if trigger == "None":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - No Trigger Sent, Returning", level=xbmc.LOGNOTICE )
- return
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - activate_on( %s ) Triggered" % trigger, level=xbmc.LOGNOTICE )
- # Script Start
- if trigger == _L_( 32613 ) and _S_( "ha_script_start" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32613 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Trivia Intro
- elif trigger == _L_( 32609 ) and _S_( "ha_trivia_intro" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32609 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Trivia
- elif trigger ==_L_( 32615 ) and _S_( "ha_trivia_start" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32615 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Trivia Outro
- elif trigger ==_L_( 32610 ) and _S_( "ha_trivia_outro" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32610 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Movie Theatre Intro
- elif trigger ==_L_( 32607 ) and _S_( "ha_mte_intro" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32607 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Coming Attractions Intro
- elif trigger ==_L_( 32600 ) and _S_( "ha_cav_intro" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32600 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Trailer
- elif trigger ==_L_( 32605 ) and _S_( "ha_trailer_start" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32605 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Coming Attractions Outro
- elif trigger ==_L_( 32608 ) and _S_( "ha_cav_outro" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32608 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Feature Presentation Intro
- elif trigger ==_L_( 32601 ) and _S_( "ha_fpv_intro" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32601 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # MPAA Rating
- elif trigger ==_L_( 32603 ) and _S_( "ha_mpaa_rating" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32603 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Countdown
- elif trigger ==_L_( 32611 ) and _S_( "ha_countdown_video" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32611 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Audio Format
- elif trigger ==_L_( 32606 ) and _S_( "ha_audio_format" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32606 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Movie
- elif trigger ==_L_( 32616 ) and _S_( "ha_movie" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32616 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Feature Presentation Outro
- elif trigger ==_L_( 32602 ) and _S_( "ha_fpv_outro" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32602 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Movie Theatre Intro
- elif trigger ==_L_( 32617 ) and _S_( "ha_mte_outro" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32617 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Intermission
- elif trigger ==_L_( 32612 ) and _S_( "ha_intermission" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32612 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Script End
- elif trigger ==_L_( 32614 ) and _S_( "ha_script_end" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32614 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Paused
- elif trigger ==_L_( 32618 ) and _S_( "ha_paused" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32618 ), level=xbmc.LOGNOTICE )
- # place code below this line
- # Resumed
- elif trigger ==_L_( 32619 ) and _S_( "ha_resumed" ) == "true":
- xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - %s Triggered" % _L_( 32619 ), level=xbmc.LOGNOTICE )
- # place code below this line
-
+ Usage:
+ activate_on( "Movie" )
+ will trigger code that is set under the Movie heading.
+
+ """
+ if not trigger:
+ xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - No Trigger Sent, Returning", level=xbmc.LOGNOTICE )
+ return
+ xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - activate_on( %s ) Triggered" % trigger, level=xbmc.LOGNOTICE )
+ if trigger in triggers:
+ xbmc.log( "[script.cinema.experience] - [ home_automation.py ] - Trigger %s" % trigger, level=xbmc.LOGNOTICE )
+ # Script Start
+ if trigger == "Script Start" and ha_settings[ "ha_script_start" ]:
+ # place code below this line
+ pass
+ # Trivia Intro
+ elif trigger == "Trivia Intro" and ha_settings[ "ha_trivia_intro" ]:
+ pass
+ # place code below this line
+ # Trivia
+ elif trigger == "Trivia" and ha_settings[ "ha_trivia_start" ]:
+ pass
+ # place code below this line
+ # Trivia Outro
+ elif trigger == "Trivia Outro" and ha_settings[ "ha_trivia_outro" ]:
+ pass
+ # place code below this line
+ # Movie Theatre Intro
+ elif trigger == "Movie Theater Intro" and ha_settings[ "ha_mte_intro" ]:
+ pass
+ # place code below this line
+ # Coming Attractions Intro
+ elif trigger == "Coming Attractions Intro" and ha_settings[ "ha_cav_intro" ]:
+ pass
+ # place code below this line
+ # Trailer
+ elif trigger == "Movie Trailer" and ha_settings[ "ha_trailer_start" ]:
+ pass
+ # place code below this line
+ # Coming Attractions Outro
+ elif trigger == "Coming Attractions Outro" and ha_settings[ "ha_cav_outro" ]:
+ pass
+ # place code below this line
+ # Feature Presentation Intro
+ elif trigger == "Feature Presentation Intro" and ha_settings[ "ha_fpv_intro" ]:
+ pass
+ # place code below this line
+ # MPAA Rating
+ elif trigger == "MPAA Rating" and ha_settings[ "ha_mpaa_rating" ]:
+ pass
+ # place code below this line
+ # Countdown
+ elif trigger == "Countdown" and ha_settings[ "ha_countdown_video" ]:
+ pass
+ # place code below this line
+ # Audio Format
+ elif trigger == "Audio Format" and ha_settings[ "ha_audio_format" ]:
+ pass
+ # place code below this line
+ # Movie
+ elif trigger == "Movie" and ha_settings[ "ha_movie" ]:
+ pass
+ # place code below this line
+ # Feature Presentation Outro
+ elif trigger == "Feature Presentation Outro" and ha_settings[ "ha_fpv_outro" ]:
+ pass
+ # place code below this line
+ # Movie Theatre Intro
+ elif trigger == "Movie Theatre Outro" and ha_settings[ "ha_mte_outro" ]:
+ pass
+ # place code below this line
+ # Intermission
+ elif trigger == "Intermission" and ha_settings[ "ha_intermission" ]:
+ pass
+ # place code below this line
+ # Script End
+ elif trigger == "Script End" and ha_settings[ "ha_script_end" ]:
+ pass
+ # place code below this line
+ # Paused
+ elif trigger == "Pause" and ha_settings[ "ha_paused" ]:
+ pass
+ # place code below this line
+ # Resumed
+ elif trigger == "Resume" and ha_settings[ "ha_resumed" ]:
+ pass
+ # place code below this line
View
2 resources/language/English/strings.xml
@@ -201,4 +201,6 @@
<string id="32918">Trigger when paused</string>
<string id="32919">Trigger when resumed</string>
<string id="32920">Enable the Home Automation Script</string>
+ <string id="32921">Must use Trivia Slide Show as well to provide time for script to download trailer(s)</string>
+ <string id="32922"> Delay to determine if movie is paused(in 100ms steps, ie 20 = 2000 ms = 2 secs</string>
</strings>
View
97 resources/lib/ce_playlist.py
@@ -13,8 +13,12 @@
_A_ = xbmcaddon.Addon( __scriptID__ )
# language method
_L_ = _A_.getLocalizedString
-# settings method
-_S_ = _A_.getSetting
+
+trivia_settings = sys.modules["__main__"].trivia_settings
+trailer_settings = sys.modules["__main__"].trailer_settings
+feature_settings = sys.modules["__main__"].feature_settings
+video_settings = sys.modules["__main__"].video_settings
+
#tmp_paths = []
BASE_CACHE_PATH = os.path.join( xbmc.translatePath( "special://profile" ), "Thumbnails", "Video" )
@@ -29,37 +33,24 @@
log_sep = "-"*70
-def _get_trailers( items, mpaa, genre, movie, mode = "download" ):
+def _get_trailers( items, equivalent_mpaa, mpaa, genre, movie, mode = "download" ):
xbmc.log( "[script.cinema.experience] - [ce_playlist.py] - _get_trailers started", level=xbmc.LOGDEBUG )
# return if not user preference
+ settings = trailer_settings
if not items:
return []
- # 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" ) ),
- "trailer_folder": xbmc.translatePath( _S_( "trailer_folder" ) ),
- "trailer_rating": _S_( "trailer_rating" ),
- "trailer_limit_mpaa": _S_( "trailer_limit_mpaa" ) == "true",
- "trailer_limit_genre": _S_( "trailer_limit_genre" ) == "true",
- "trailer_play_mode": int( _S_( "trailer_play_mode" ) ),
- "trailer_hd_only": _S_( "trailer_hd_only" ) == "true",
- "trailer_quality": int( _S_( "trailer_quality" ) ),
- "trailer_unwatched_movie_only": _S_( "trailer_unwatched_movie_only" ) == "true",
- "trailer_unwatched_only": _S_( "trailer_unwatched_only" ) == "true",
- "trailer_newest_only": _S_( "trailer_newest_only" ) == "true",
- "trailer_count": ( 0, 1, 2, 3, 4, 5, 10, )[ int( _S_( "trailer_count" ) ) ],
- "trailer_scraper": ( "amt_database", "amt_current", "local", "xbmc_library", )[ int( _S_( "trailer_scraper" ) ) ]
- }
- if int( _S_( "trailer_play_mode" ) ) == 1 and mode == "playlist" and int( _S_( "trailer_scraper" ) ) < 2:
+ if settings[ "trailer_play_mode" ] == 1 and mode == "playlist" and settings[ "trailer_scraper" ] in ( "amt_database", "amt_current" ):
settings[ "trailer_scraper" ] = "local"
- settings[ "trailer_folder" ] = _S_( "trailer_download_folder" )
+ settings[ "trailer_folder" ] = settings[ "trailer_download_folder" ]
# get the correct scraper
+ print settings[ "trailer_scraper" ]
+ print settings[ "trailer_play_mode" ]
sys.path.append( os.path.join( BASE_RESOURCE_PATH, "lib", "scrapers" ) )
exec "from %s import scraper as scraper" % ( settings[ "trailer_scraper" ], )
- Scraper = scraper.Main( mpaa, genre, settings, movie )
+ Scraper = scraper.Main( equivalent_mpaa, mpaa, genre, settings, movie )
# fetch trailers
trailers = Scraper.fetch_trailers()
# return results
- print trailers
return trailers
def _getnfo( path ):
@@ -135,7 +126,7 @@ def _set_trailer_info( trailer ):
release_date, # release date
studio, # studio
genre, # genre
- _L_( 32605 ), # writer
+ "Movie Trailer", # writer
director, # director 32613
)
return result
@@ -161,14 +152,14 @@ def _get_trailer_thumbnail( path ):
# if thumb does not exist return empty
if not exists( thumbnail ):
# set empty string
- thumbnail = None
+ thumbnail = ""
xbmc.log("%s - Thumbnail not found" % log_message, level=xbmc.LOGDEBUG )
- if not thumbnail == None:
+ if thumbnail:
xbmc.log("%s - Thumbnail found: %s" % ( log_message, thumbnail), level=xbmc.LOGDEBUG )
# return result
return thumbnail
-def _get_special_items( playlist, items, path, genre, title="", thumbnail=None, plot="",
+def _get_special_items( playlist, items, path, genre, title="", thumbnail="", plot="",
runtime="", mpaa="", release_date="0 0 0", studio="", writer="",
director="", index=-1, media_type="video"
):
@@ -188,10 +179,7 @@ def _get_special_items( playlist, items, path, genre, title="", thumbnail=None,
xbmc.log( "%s - _get_special_items() - Path: %s" % ( log_message, path ), level=xbmc.LOGDEBUG)
# initialize our lists
tmp_paths = dirEntries( path, media_type, "TRUE" )
- shuf = 0
- while shuf <6:
- shuffle( tmp_paths, random )
- shuf += 1
+ shuffle( tmp_paths )
# enumerate thru and add our videos/pictures
for count in range( items ):
try:
@@ -208,8 +196,8 @@ def _get_special_items( playlist, items, path, genre, title="", thumbnail=None,
runtime=runtime,
mpaa=mpaa,
release_date=release_date,
- studio=studio or _L_( 32604 ),
- genre=genre or _L_( 32605 ),
+ studio=studio or "Cinema Experience",
+ genre=genre or "Movie Trailer",
writer=writer,
director=director
)
@@ -225,11 +213,14 @@ def _get_special_items( playlist, items, path, genre, title="", thumbnail=None,
else:
traceback.print_exc()
-def _get_listitem( title="", url="", thumbnail=None, plot="", runtime="", mpaa="", release_date="0 0 0", studio=_L_( 32604 ), genre="", writer="", director=""):
+def _get_listitem( title="", url="", thumbnail="", plot="", runtime="", mpaa="", release_date="0 0 0", studio="Cinema Experience", genre="", writer="", director=""):
xbmc.log( "%s - _get_listitem() Started" % log_message, level=xbmc.LOGDEBUG)
# check for a valid thumbnail
- if not writer == _L_( 32605 ):
- thumbnail = _get_thumbnail( ( thumbnail, url, )[ thumbnail is None ] )
+ if not writer == "Movie Trailer":
+ thumbnail = _get_thumbnail( ( thumbnail, url, )[ thumbnail == "" ] )
+ else:
+ if not thumbnail:
+ thumbnail = "DefaultVideo.png"
# set the default icon
icon = "DefaultVideo.png"
# only need to add label, icon and thumbnail, setInfo() and addSortMethod() takes care of label2
@@ -260,46 +251,28 @@ def _get_thumbnail( url ):
# return result
return thumbnail
-def _wait_until_end(): # wait until the end of the playlist(for Trivia Intro)
- xbmc.log( "%s - Waiting Until End Of Video" % log_message, level=xbmc.LOGNOTICE)
- try:
- psize = xbmc.PlayList( xbmc.PLAYLIST_VIDEO ).size() - 1
- xbmc.log( "%s - Playlist Size: %s" % (log_message, ( psize + 1 ) ), level=xbmc.LOGDEBUG)
- while xbmc.PlayList( xbmc.PLAYLIST_VIDEO ).getposition() < psize:
- pass
- xbmc.log( "%s - Video TotalTime: %s" % ( log_message, xbmc.Player().getTotalTime() ), level=xbmc.LOGDEBUG)
- while xbmc.Player().getTime() < ( xbmc.Player().getTotalTime() - 0.5 ):
- pass
- xbmc.log( "%s - Video getTime: %s" % ( log_message, xbmc.Player().getTime() ), level=xbmc.LOGDEBUG)
- xbmc.sleep(500)
- except:
- xbmc.log( "%s - Video either stopped or skipped, Continuing on..." % log_message, level=xbmc.LOGDEBUG)
-
def build_music_playlist():
xbmc.log( "%s - Building Music Playlist" % log_message, level=xbmc.LOGNOTICE)
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "AudioPlaylist.Clear", "id": 1}')
music_playlist = xbmc.PlayList( xbmc.PLAYLIST_MUSIC )
track_location = []
# check to see if playlist or music file is selected
- if int( _S_( "trivia_music" ) ) == 1:
- if _S_( "trivia_music_file" ).endswith(".m3u"):
- xbmc.log( "%s - Music Playlist: %s" % ( log_message, _S_( "trivia_music_file" ) ), level=xbmc.LOGDEBUG)
- playlist_file = open( _S_( "trivia_music_file" ), 'rb')
+ if trivia_settings[ "trivia_music" ] == 1:
+ if trivia_settings[ "trivia_music_file" ].endswith(".m3u"):
+ xbmc.log( "%s - Music Playlist: %s" % ( log_message, trivia_settings[ "trivia_music_file" ] ), level=xbmc.LOGDEBUG)
+ playlist_file = open( trivia_settings[ "trivia_music_file" ], 'rb')
saved_playlist = playlist_file.readlines()
xbmc.log( "%s - Finished Reading Music Playlist" % log_message, level=xbmc.LOGDEBUG)
track_info, track_location = parse_playlist( saved_playlist, xbmc.getSupportedMedia('music') )
- elif os.path.splitext( _S_( "trivia_music_file" ) )[1] in xbmc.getSupportedMedia('music'):
+ elif os.path.splitext( trivia_settings[ "trivia_music_file" ] )[1] in xbmc.getSupportedMedia('music'):
for track in range(100):
- track_location.append( _S_( "trivia_music_file" ) )
+ track_location.append( trivia[ "trivia_music_file" ] )
# otherwise
else:
- if _S_( "trivia_music_folder" ):
+ if trivia_settings[ "trivia_music_folder" ]:
# search given folder and subfolders for files
- track_location = dirEntries( _S_( "trivia_music_folder" ), "music", "TRUE" )
+ track_location = dirEntries( trivia_settings[ "trivia_music_folder" ], "music", "TRUE" )
# shuffle playlist
- count = 0
- while count <6:
- shuffle( track_location, random )
- count+=1
+ shuffle( track_location )
for track in track_location:
music_playlist.add( track, )
View
1 resources/lib/music.py
@@ -8,7 +8,6 @@ def parse_playlist( playlist, supported ):
finds all Artist - Title and File path information from a m3u playlist
Returns a list for Artist - Title and one for File path
"""
- print "parsing m3u file"
track_info = []
track_location = []
for line in playlist:
View
28 resources/lib/new_trailer_downloader.py
@@ -16,8 +16,7 @@
_A_ = xbmcaddon.Addon( __scriptID__ )
# language method
_L_ = _A_.getLocalizedString
-# settings method
-_S_ = _A_.getSetting
+trailer_settings = sys.modules["__main__"].trailer_settings
from urllib import quote_plus
from random import shuffle, random
@@ -30,12 +29,12 @@
downloaded_trailers = []
-def downloader( mpaa, genre ):
+def downloader( mpaa, genre, equivalent_mpaa ):
movie = ""
trailer_list = []
xbmc.log( "%s - Starting Trailer Downloader" % logmessage, level=xbmc.LOGNOTICE )
genre = genre.replace( "_", " / " )
- trailer_list = _download_trailers( mpaa, genre, movie )
+ trailer_list = _download_trailers( equivalent_mpaa, mpaa, genre, movie )
save_download_list( trailer_list )
def save_download_list( download_trailers ):
@@ -71,13 +70,14 @@ def save_download_list( download_trailers ):
except:
xbmc.log( "%s - Error Trying to Remove List of Downloaded Trailers" % logmessage, level=xbmc.LOGNOTICE )
-def _download_trailers( mpaa, genre, movie ):
+def _download_trailers( equivalent_mpaa, mpaa, genre, movie ):
updated_trailers = []
- xbmc.log( "%s - Downloading Trailers: %s Trailers" % ( logmessage, ( 0, 1, 2, 3, 4, 5, 10, )[ int( _S_( "trailer_count" ) ) ] ), level=xbmc.LOGNOTICE )
+ xbmc.log( "%s - Downloading Trailers: %s Trailers" % ( logmessage, trailer_settings[ "trailer_count" ] ), level=xbmc.LOGNOTICE )
temp_destination = os.path.join( BASE_CURRENT_SOURCE_PATH, "temp_trailers" ).replace( "\\\\", "\\" )
if not xbmcvfs.exists( temp_destination ):
xbmcvfs.mkdir( temp_destination )
- trailers = _get_trailers( items=( 0, 1, 2, 3, 4, 5, 10, )[ int( _S_( "trailer_count" ) ) ],
+ trailers = _get_trailers( items=trailer_settings[ "trailer_count" ],
+ equivalent_mpaa=equivalent_mpaa,
mpaa=mpaa,
genre=genre,
movie=movie,
@@ -91,7 +91,7 @@ def _download_trailers( mpaa, genre, movie ):
xbmc.log( "%s - Attempting To Download Trailer: %s" % ( logmessage, trailer[ 1 ] ), level=xbmc.LOGNOTICE )
filename, ext = os.path.splitext( os.path.basename( (trailer[ 2 ].split("|")[0] ).replace( "?","" ) ) )
filename = filename + "-trailer" + ext
- file_path = os.path.join( _S_( "trailer_download_folder" ), filename ).replace( "\\\\", "\\" )
+ file_path = os.path.join( trailer_settings[ "trailer_download_folder" ], filename ).replace( "\\\\", "\\" )
# check to see if trailer is already downloaded
if os.path.isfile( file_path ):
success = True
@@ -118,9 +118,9 @@ def _download_trailers( mpaa, genre, movie ):
else:
xbmc.log( "%s - Failed to Download Trailer: %s" % ( logmessage, trailer[ 1 ] ), level=xbmc.LOGNOTICE )
updated_trailer=[]
- xbmcvfs.copy( os.path.join( temp_destination, filename ).replace( "\\\\", "\\"), os.path.join( _S_( "trailer_download_folder" ), filename ).replace( "\\\\", "\\" ) )
- xbmcvfs.copy( os.path.join( temp_destination, os.path.splitext( filename )[0] + ".tbn" ).replace( "\\\\", "\\"), os.path.join( _S_( "trailer_download_folder" ), os.path.splitext( filename )[0] + ".tbn" ).replace( "\\\\", "\\" ) )
- xbmcvfs.copy( os.path.join( temp_destination, os.path.splitext( filename )[0] + ".nfo" ).replace( "\\\\", "\\"), os.path.join( _S_( "trailer_download_folder" ), os.path.splitext( filename )[0] + ".nfo" ).replace( "\\\\", "\\" ) )
+ xbmcvfs.copy( os.path.join( temp_destination, filename ).replace( "\\\\", "\\"), os.path.join( trailer_settings[ "trailer_download_folder" ], filename ).replace( "\\\\", "\\" ) )
+ xbmcvfs.copy( os.path.join( temp_destination, os.path.splitext( filename )[0] + ".tbn" ).replace( "\\\\", "\\"), os.path.join( trailer_settings[ "trailer_download_folder" ], os.path.splitext( filename )[0] + ".tbn" ).replace( "\\\\", "\\" ) )
+ xbmcvfs.copy( os.path.join( temp_destination, os.path.splitext( filename )[0] + ".nfo" ).replace( "\\\\", "\\"), os.path.join( trailer_settings[ "trailer_download_folder" ], os.path.splitext( filename )[0] + ".nfo" ).replace( "\\\\", "\\" ) )
xbmcvfs.delete( os.path.join( temp_destination, filename ).replace( "\\\\", "\\") )
xbmcvfs.delete( os.path.join( temp_destination, os.path.splitext( filename )[0] + ".tbn" ).replace( "\\\\", "\\") )
xbmcvfs.delete( os.path.join( temp_destination, os.path.splitext( filename )[0] + ".nfo" ).replace( "\\\\", "\\") )
@@ -142,7 +142,7 @@ def _create_nfo_file( trailer, trailer_nfopath ):
'''
xbmc.log( "%s - Creating Trailer NFO file" % logmessage, level=xbmc.LOGNOTICE )
# set quality, we do this since not all resolutions have trailers
- quality = ( "Standard", "480p", "720p", "1080p" )[ int( _S_( "trailer_quality" ) ) ]
+ quality = trailer_settings[ "trailer_quality" ]
# set movie info
nfoSource = """<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<movieinfo id="%s">
@@ -183,9 +183,9 @@ def _save_nfo_file( nfoSource, trailer_nfopath ):
if __name__ == "__main__":
try:
if sys.argv[1]:
- mpaa, genre = sys.argv[1].replace( "mpaa=", "" ).replace( "genre=", "").split(";")
+ mpaa, genre = sys.argv[1].replace( "mpaa=", "" ).replace( "genre=", "").replace( "equivalent_mpaa=", "" ).split(";")
_genre = genre.replace( "_", " / " )
- downloader( mpaa, _genre )
+ downloader( mpaa, _genre, equivalent_mpaa )
else:
xbmc.log( "%s - No Arguments sent " % logmessage, level=xbmc.LOGNOTICE )
except:
View
39 resources/lib/pre_eden_code.py
@@ -5,7 +5,7 @@
log_sep = "-"*70
import xbmc, xbmcgui, xbmcaddon
-import traceback, os
+import traceback, os, sys
from urllib import quote_plus
from json_utils import find_movie_details, retrieve_json_dict
from utils import list_to_string
@@ -13,36 +13,11 @@
_A_ = xbmcaddon.Addon( __scriptID__ )
# language method
_L_ = _A_.getLocalizedString
-# settings method
-_S_ = _A_.getSetting
-def _build_playlist( movie_titles ):
- for movie in movie_titles:
- xbmc.log( "[script.cinema.experience] - Movie Title: %s" % movie, level=xbmc.LOGNOTICE )
- xbmc.executehttpapi( "SetResponseFormat()" )
- xbmc.executehttpapi( "SetResponseFormat(OpenField,)" )
- # select Movie path from movieview Limit 1
- sql = "SELECT movieview.idMovie, movieview.c00, movieview.strPath, movieview.strFileName, movieview.c08, movieview.c14 FROM movieview WHERE c00 LIKE '%s' LIMIT 1" % ( movie.replace( "'", "''", ), )
- xbmc.log( "[script.cinema.experience] - SQL: %s" % ( sql, ), level=xbmc.LOGDEBUG )
- # query database for info dummy is needed as there are two </field> formatters
- try:
- movie_id, movie_title, movie_path, movie_filename, thumb, genre, dummy = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql ), ).split( "</field>" )
- movie_id = int( movie_id )
- except:
- traceback.print_exc()
- xbmc.log( "[script.cinema.experience] - Unable to match movie", level=xbmc.LOGERROR )
- movie_id = 0
- movie_title = movie_path = movie_filename = thumb = genre = dummy = ""
- movie_full_path = os.path.join(movie_path, movie_filename).replace("\\\\" , "\\")
- xbmc.log( "[script.cinema.experience] - Movie Title: %s" % movie_title, level=xbmc.LOGNOTICE )
- xbmc.log( "[script.cinema.experience] - Movie Path: %s" % movie_path, level=xbmc.LOGNOTICE )
- xbmc.log( "[script.cinema.experience] - Movie Filename: %s" % movie_filename, level=xbmc.LOGNOTICE )
- xbmc.log( "[script.cinema.experience] - Full Movie Path: %s" % movie_full_path, level=xbmc.LOGNOTICE )
- if not movie_id == 0:
- json_command = '{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 1, "item": {"movieid": %d} }, "id": 1}' % movie_id
- json_response = xbmc.executeJSONRPC(json_command)
- xbmc.log( "[script.cinema.experience] - JSONRPC Response: \n%s" % movie_title, level=xbmc.LOGDEBUG )
- xbmc.sleep( 50 )
+trivia_settings = sys.modules["__main__"].trivia_settings
+trailer_settings = sys.modules["__main__"].trailer_settings
+feature_settings = sys.modules["__main__"].feature_settings
+video_settings = sys.modules["__main__"].video_settings
def _store_playlist():
p_list = []
@@ -122,8 +97,8 @@ def _get_queued_video_info( feature = 0 ):
xbmc.log( "%s - Genre: %s" % ( log_message, genre, ), level=xbmc.LOGDEBUG )
xbmc.log( "%s - MPAA: %s" % ( log_message, mpaa, ), level=xbmc.LOGDEBUG )
xbmc.log( "%s - Audio: %s" % ( log_message, audio, ), level=xbmc.LOGDEBUG )
- if _S_( "audio_videos_folder" ):
- xbmc.log( "%s - Folder: %s" % ( log_message, ( xbmc.translatePath( _S_( "audio_videos_folder" ) ) + { "dca": "DTS", "ac3": "Dolby", "dtsma": "DTSHD-MA", "dtshd_ma": "DTSHD-MA", "a_truehd": "Dolby TrueHD", "truehd": "Dolby TrueHD" }.get( audio, "Other" ) + xbmc.translatePath( _S_( "audio_videos_folder" ) )[ -1 ], ) ), level=xbmc.LOGDEBUG )
+ if video_settings[ "audio_videos_folder" ]:
+ xbmc.log( "%s - Folder: %s" % ( log_message, ( video_settings[ "audio_videos_folder" ] + { "dts": "DTS", "dca": "DTS", "ac3": "Dolby", "dtsma": "DTSHD-MA", "dtshd_ma": "DTSHD-MA", "a_truehd": "Dolby TrueHD", "truehd": "Dolby TrueHD" }.get( audio, "Other" ) + video_settings[ "audio_videos_folder" ][ -1 ], ) ), level=xbmc.LOGDEBUG )
xbmc.log( "%s %s" % ( log_message, log_sep ), level=xbmc.LOGDEBUG )
# return results
return mpaa, audio, genre, path, equivalent_mpaa
View
20 resources/lib/scrapers/amt_current/scraper.py
@@ -26,6 +26,7 @@ class _urlopener( urllib.FancyURLopener ):
# set for user agent
urllib._urlopener = _urlopener()
+BASE_CURRENT_SOURCE_PATH = sys.modules[ "__main__" ].BASE_CURRENT_SOURCE_PATH
class _Parser:
"""
@@ -56,10 +57,7 @@ def _parse_source( self, xmlSource ):
# gather all video records <movieinfo>
movies = re.findall( "<movieinfo id=\"(.+?)\">(.*?)</movieinfo>", xmlSource )
# randomize the trailers and create our play list
- while count <6:
- shuffle( movies, random )
- count += 1
- count = 0
+ shuffle( movies )
# enumerate thru the movies list and gather info
for id, movie in movies:
# user preference to skip watch trailers
@@ -135,11 +133,9 @@ class Main:
print "Apple Movie Trailers Newest trailers scraper"
# base url
BASE_CURRENT_URL = "http://www.apple.com/trailers/home/xml/newest%s.xml"
- # base paths
- BASE_CURRENT_SOURCE_PATH = os.path.join( xbmc.translatePath( "special://profile/addon_data" ), os.path.basename( _A_.getAddonInfo('path') ) )
-
- def __init__( self, mpaa=None, genre=None, settings=None, movie=None ):
- self.mpaa = mpaa
+
+ def __init__( self, equivalent_mpaa=None, mpaa=None, genre=None, settings=None, movie=None ):
+ self.mpaa = equivalent_mpaa
self.genre = genre
self.settings = settings
@@ -147,8 +143,8 @@ def fetch_trailers( self ):
# initialize trailers list
trailers = []
# fetch source
- path = os.path.join( self.BASE_CURRENT_SOURCE_PATH, ( "newest.xml", "newest_480p.xml", "newest_720p.xml", "newest_720p.xml", )[ self.settings[ "trailer_quality" ] ] )
- url = self.BASE_CURRENT_URL % ( ( "", "_480p", "_720p", "_720p", )[ self.settings[ "trailer_quality" ] ], )
+ path = os.path.join( BASE_CURRENT_SOURCE_PATH, "newest%s.xml" % self.settings[ "trailer_quality_url" ] )
+ url = self.BASE_CURRENT_URL % ( self.settings[ "trailer_quality_url" ], )
xmlSource = self._get_xml_source( path, url )
# parse source and add our items
if ( xmlSource ):
@@ -207,7 +203,7 @@ def _save_xml_source( self, xmlSource, base_path ):
def _parse_xml_source( self, xmlSource ):
# base path to watched file
- base_path = os.path.join( self.BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] + "_watched.txt" )
+ base_path = os.path.join( BASE_CURRENT_SOURCE_PATH, self.settings[ "trailer_scraper" ] + "_watched.txt" )
# get watched file
try:
watched = eval( self._get_xml_source( base_path ) )
View
36 resources/lib/scrapers/amt_database/scraper.py
@@ -4,14 +4,12 @@
Apple Movie Trailers script database scraper
"""
-import sys
-import os
-import xbmcaddon
-import xbmc
+import sys, os, datetime, traceback
+import xbmcaddon, xbmc
from random import shuffle
from urllib import quote_plus
-import datetime
+
try:
from sqlite3 import dbapi2 as sqlite
except:
@@ -24,26 +22,30 @@
__useragent__ = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27"
#__useragent__ = "QuickTime/7.2 (qtver=7.2;os=Windows NT 5.1Service Pack 3)"
-
+trailer_settings = sys.modules[ "__main__" ].trailer_settings
+BASE_CURRENT_SOURCE_PATH = sys.modules[ "__main__" ].BASE_CURRENT_SOURCE_PATH
class Main:
print "Apple Movie Trailers script database scraper"
- BASE_DATA_PATH = os.path.join( xbmc.translatePath( "special://masterprofile/addon_data" ), "script.apple.movie.trailers" )
+ BASE_DATA_PATH = os.path.join( BASE_CURRENT_SOURCE_PATH, "script.apple.movie.trailers" )
- def __init__( self, mpaa=None, genre=None, settings=None, movie=None ):
- self.mpaa = mpaa
+ def __init__( self, equivalent_mpaa=None, mpaa=None, genre=None, settings=None, movie=None ):
+ self.mpaa = equivalent_mpaa
self.genre = genre
self.settings = settings
def clear_watched( self ):
- # make db connection
- records = Records( amt_db_path=self.settings[ "trailer_amt_db_file" ] )
- # clear watched sql
- sql ="UPDATE movies SET times_watched=0, last_watched=''"
- # update the record with our new values
- ok = records.update( sql )
- # close the database
- records.close()
+ try:
+ # make db connection
+ records = Records( amt_db_path=self.settings[ "trailer_amt_db_file" ] )
+ # clear watched sql
+ sql ="UPDATE movies SET times_watched=0, last_watched=''"
+ # update the record with our new values
+ ok = records.update( sql )
+ # close the database
+ records.close()
+ except:
+ traceback.print_exc()
def fetch_trailers( self ):
try:
View
10 resources/lib/scrapers/local/scraper.py
@@ -15,7 +15,9 @@
logmessage = "[ " + __scriptID__ + " ] - [ " + __modname__ + " ]"
_A_ = xbmcaddon.Addon( __scriptID__ )
_L_ = _A_.getLocalizedString
-BASE_RESOURCE_PATH = xbmc.translatePath( os.path.join( _A_.getAddonInfo('path'), 'resources' ) )
+trailer_settings = sys.modules[ "__main__" ].trailer_settings
+BASE_RESOURCE_PATH = sys.modules[ "__main__" ].BASE_CURRENT_SOURCE_PATH
+
sys.path.append( os.path.join( BASE_RESOURCE_PATH, "lib" ) )
from folder import dirEntries
from ce_playlist import _set_trailer_info
@@ -23,10 +25,10 @@
class Main:
xbmc.log("%s - Local Folder Trailer Scraper Started" % logmessage, level=xbmc.LOGNOTICE )
# base paths
- BASE_CURRENT_SOURCE_PATH = os.path.join( xbmc.translatePath( "special://profile/addon_data/" ), os.path.basename( _A_.getAddonInfo('path') ) )
+ BASE_CURRENT_SOURCE_PATH = BASE_RESOURCE_PATH
- def __init__( self, mpaa=None, genre=None, settings=None, movie=None ):
- self.mpaa = mpaa
+ def __init__( self, equivalent_mpaa=None, mpaa=None, genre=None, settings=None, movie=None ):
+ self.mpaa = equivalent_mpaa
self.genre = genre.replace( "Sci-Fi", "Science Fiction" ).replace( "Action", "Action and ADV" ).replace( "Adventure", "ACT and Adventure" ).replace( "ACT", "Action" ).replace( "ADV", "Adventure" ).split( " / " )
self.settings = settings
self.movie = movie
View
140 resources/lib/scrapers/xbmc_library/scraper.py
@@ -14,12 +14,16 @@
from random import shuffle
from urllib import quote_plus
import datetime, traceback
+if sys.version_info < (2, 7):
+ import simplejson
+else:
+ import json as simplejson
logmessage = "[ " + __scriptID__ + " ] - [ " + __modname__ + " ]"
_A_ = xbmcaddon.Addon('script.cinema.experience')
_L_ = _A_.getLocalizedString
-
-BASE_RESOURCE_PATH = xbmc.translatePath( os.path.join( _A_.getAddonInfo('path'), 'resources' ) )
+trailer_settings = sys.modules[ "__main__" ].trailer_settings
+BASE_RESOURCE_PATH = sys.modules[ "__main__" ].BASE_CURRENT_SOURCE_PATH
sys.path.append( os.path.join( BASE_RESOURCE_PATH, "lib" ) )
from ce_playlist import _get_thumbnail, _get_trailer_thumbnail
unwatched_movie_only = True
@@ -28,14 +32,19 @@
class Main:
xbmc.log( "%s - XBMC Movie Library Trailer Scraper" % logmessage, level=xbmc.LOGNOTICE )
- BASE_CURRENT_SOURCE_PATH = os.path.join( xbmc.translatePath( "special://profile/addon_data" ), os.path.basename( _A_.getAddonInfo('path') ) )
-
+ BASE_CURRENT_SOURCE_PATH = BASE_RESOURCE_PATH
- def __init__( self, mpaa=None, genre=None, settings=None, movie=None ):
- self.mpaa = mpaa
- self.genre = genre.split( " / " )
- self.movie = movie
+ def __init__( self, equivalent_mpaa=None, mpaa=None, genre=None, settings=None, movie=None ):
self.settings = settings
+ if settings['trailer_limit_mpaa']:
+ self.mpaa = "Rated %s" % mpaa
+ else:
+ self.mpaa = ""
+ if settings['trailer_limit_genre'] and settings['trailer_rating'] == '--':
+ self.genre = ""
+ else:
+ self.genre = genre.split( " / " )[ 0 ]
+ self.movie = movie
# initialize our trailer list
self.trailers = []
@@ -43,79 +52,54 @@ def fetch_trailers( self ):
# get watched list
self._get_watched()
count = 0
- sqlquery = """SELECT movieview.c00, movieview.c19, movieview.c12, movieview.c14, playCount from movieview WHERE NOT c19="" ORDER BY RANDOM()"""
- xbmc.executehttpapi( "SetResponseFormat()" )
- xbmc.executehttpapi( "SetResponseFormat(CloseRecord;</record>;OpenField,)" )
- xbmc.log( "%s - SQL: %s" % ( logmessage, sqlquery, ), level=xbmc.LOGDEBUG )
- try:
- sqlresult = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sqlquery ), )
- #xbmc.log( "%s - sqlresult: %s" % sqlresult, level=xbmc.LOGDEBUG )
- sqlrecords = sqlresult.split("</record>")
- trailer_list = sqlrecords[ 0:len( sqlrecords ) -1 ]
- for trailer in trailer_list:
- title, trailer_path, trailer_ratingsql, trailer_genresql, movie_playcount, dummy = trailer.split("</field>")
- # shorten MPAA/BBFC ratings
- if trailer_ratingsql == "":
- trailer_ratingsql = "NR"
- elif trailer_ratingsql.startswith("Rated"):
- trailer_ratingsql = trailer_ratingsql.split( " " )[ 1 - ( len( trailer_ratingsql.split( " " ) ) == 1 ) ]
- trailer_ratingsql = ( trailer_ratingsql, "NR", )[ trailer_ratingsql not in ( "G", "PG", "PG-13", "R", "NC-17", "Unrated", ) ]
- elif trailer_ratingsql.startswith("UK"):
- trailer_ratingsql = trailer_ratingsql.split( ":" )[ 1 - ( len( trailer_ratingsql.split( ":" ) ) == 1 ) ]
- trailer_ratingsql = ( trailer_ratingsql, "NR", )[ trailer_ratingsql not in ( "12", "12A", "PG", "15", "18", "R18", "MA", "U", ) ]
- else:
- trailer_ratingsql = ( trailer_ratingsql, "NR", )[ trailer_ratingsql not in ( "12", "12A", "PG", "15", "18", "R18", "MA", "U", ) ]
- if trailer_ratingsql not in ( "G", "PG", "PG-13", "R", "NC-17", "Unrated", "NR" ):
- if trailer_ratingsql in ("12", "12A",):
- trailer_ratingsql = "PG-13"
- elif trailer_ratingsql == "15":
- trailer_ratingsql = "R"
- elif trailer_ratingsql == "U":
- trailer_ratingsql = "G"
- elif trailer_ratingsql in ("18", "R18", "MA",):
- trailer_ratingsql = "NC-17"
+ if self.settings[ "trailer_unwatched_movie_only" ]:
+ jsonquery = '''{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "sort": { "order": "ascending", "method": "title", "ignorearticle": true }, "properties" : ["trailer", "mpaa", "genre", "thumbnail", "plot"], "filter": { "and": [ { "field": "playcount", "operator": "is", "value": "0" }, { "field": "mpaarating", "operator": "contains", "value": "%s" }, { "field": "genre", "operator": "contains", "value": "%s" }, { "field": "hastrailer", "operator": "true", "value": "true" } ] } }, "id": 1}''' % ( self.mpaa, self.genre )
+ else:
+ jsonquery = '''{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "sort": { "order": "ascending", "method": "title", "ignorearticle": true }, "properties" : ["trailer", "mpaa", "genre", "thumbnail", "plot"], "filter": { "and": [ { "field": "mpaarating", "operator": "contains", "value": "%s" }, { "field": "genre", "operator": "contains", "value": "%s" }, { "field": "hastrailer", "operator": "true", "value": "true" } ] } }, "id": 1}''' % ( self.mpaa, self.genre )
+ jsonresponse = xbmc.executeJSONRPC( jsonquery )
+ data = simplejson.loads( jsonresponse )
+ if data.has_key('result'):
+ if data['result'].has_key('movies'):
+ trailers = data['result']['movies']
+ shuffle( trailers )
+ for trailer in trailers:
+ trailer_rating = trailer['mpaa']
+ # shorten MPAA/BBFC ratings
+ if trailer_rating == "":
+ trailer_rating = "NR"
+ elif trailer_rating.startswith("Rated"):
+ trailer_rating = trailer_rating.split( " " )[ 1 - ( len( trailer_rating.split( " " ) ) == 1 ) ]
+ trailer_rating = ( trailer_rating, "NR", )[ trailer_rating not in ( "G", "PG", "PG-13", "R", "NC-17", "Unrated", ) ]
+ elif trailer_rating.startswith("UK"):
+ trailer_rating = trailer_rating.split( ":" )[ 1 - ( len( trailer_rating.split( ":" ) ) == 1 ) ]
+ trailer_rating = ( trailer_rating, "NR", )[ trailer_rating not in ( "12", "12A", "PG", "15", "18", "R18", "MA", "U", ) ]
else:
- trailer_ratingsql = trailer_ratingsql
- # add trailer to our final list
- if self.settings[ "trailer_unwatched_movie_only" ] == "true" and not movie_playcount:
- #if unwatched_movie_only and not movie_playcount:
- xbmc.log("%s - Movie watched - Skipping Trailer" % logmessage, level=xbmc.LOGDEBUG )
- continue
- if self.settings[ "trailer_unwatched_only" ] and xbmc.getCacheThumbName( trailer_path ) in self.watched:
- continue
- trailer_genre = trailer_genresql.split(" / ")
- if self.settings[ "trailer_limit_genre" ] and ( not list(set(trailer_genre) & set(self.genre) ) ):
- xbmc.log("%s - Genre Not Matched - Skipping Trailer" % logmessage, level=xbmc.LOGDEBUG )
- continue
- if self.settings[ "trailer_limit_mpaa" ] and ( not trailer_ratingsql or not trailer_ratingsql == self.mpaa ):
- xbmc.log("%s - MPAA Not Matched - Skipping Trailer" % logmessage, level=xbmc.LOGDEBUG )
- continue
- trailer_info = ( xbmc.getCacheThumbName( trailer_path ), # id
- title, # title
- trailer_path, # trailer
- _get_trailer_thumbnail( trailer_path ), # thumb
- '', # plot
- '', # runtime
- trailer_ratingsql, # mpaa
- '', # release date
- '', # studio
- trailer_genresql, # genre
- _L_( 32605 ), # writer
- '', # director 32613
- )
- self.trailers += [ trailer_info ]
- # add id to watched file TODO: maybe don't add if not user preference
- self.watched += [ xbmc.getCacheThumbName( trailer_path ) ]
- # increment counter
- count += 1
- # if we have enough exit
- if count == self.settings[ "trailer_count" ]:
- break
+ trailer_rating = ( trailer_rating, "NR", )[ trailer_rating not in ( "12", "12A", "PG", "15", "18", "R18", "MA", "U", ) ]
+ # add trailer to our final list
+ if not trailer['trailer'].startswith( 'plugin://' ):
+ trailer_info = ( xbmc.getCacheThumbName( trailer['trailer'] ), # id
+ trailer['label'], # title