PlexKodiConnect/default.py

144 lines
5 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
#################################################################################################
import os
import sys
import urlparse
2015-05-04 01:39:12 +10:00
import xbmc
import xbmcaddon
#################################################################################################
addon_ = xbmcaddon.Addon(id='plugin.video.plexkodiconnect')
addon_path = addon_.getAddonInfo('path').decode('utf-8')
base_resource = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8')
sys.path.append(base_resource)
#################################################################################################
import entrypoint
import utils
#################################################################################################
enableProfiling = False
class Main:
# MAIN ENTRY POINT
def __init__(self):
# Parse parameters
xbmc.log("Full sys.argv received: %s" % sys.argv)
base_url = sys.argv[0]
params = urlparse.parse_qs(sys.argv[2][1:])
xbmc.log("Parameter string: %s" % sys.argv[2])
try:
mode = params['mode'][0]
2016-01-23 02:32:36 +11:00
itemid = params.get('id', '')
if itemid:
try:
itemid = itemid[0]
except:
pass
except:
params = {}
mode = ""
modes = {
'reset': utils.reset,
'resetauth': entrypoint.resetAuth,
2016-01-08 00:27:10 +11:00
'extrafanart': entrypoint.getExtraFanArt,
'play': entrypoint.doPlayback,
'passwords': utils.passwordsXML,
'adduser': entrypoint.addUser,
'thememedia': entrypoint.getThemeMedia,
'channels': entrypoint.BrowseChannels,
'channelsfolder': entrypoint.BrowseChannels,
'browsecontent': entrypoint.BrowseContent,
2016-01-22 21:10:42 +11:00
'getsubfolders': entrypoint.GetSubFolders,
'nextup': entrypoint.getNextUpEpisodes,
'inprogressepisodes': entrypoint.getInProgressEpisodes,
'recentepisodes': entrypoint.getRecentEpisodes,
'refreshplaylist': entrypoint.refreshPlaylist,
'companion': entrypoint.plexCompanion
}
2016-01-07 09:22:10 +11:00
if "extrafanart" in sys.argv[0]:
entrypoint.getExtraFanArt()
if modes.get(mode):
# Simple functions
if mode == "play":
dbid = params.get('dbid')
modes[mode](itemid, dbid)
elif mode in ("nextup", "inprogressepisodes", "recentepisodes"):
limit = int(params['limit'][0])
modes[mode](itemid, limit)
2016-01-22 21:10:42 +11:00
elif mode in ["channels","getsubfolders"]:
modes[mode](itemid)
elif mode == "browsecontent":
2016-01-22 21:10:42 +11:00
modes[mode]( itemid, params.get('type',[""])[0], params.get('folderid',[""])[0] )
elif mode == "channelsfolder":
folderid = params['folderid'][0]
modes[mode](itemid, folderid)
elif mode == "companion":
resume = params.get('resume', '')
modes[mode](itemid, resume=resume)
else:
modes[mode]()
else:
# Other functions
if mode == "settings":
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.plexkodiconnect)')
2016-01-13 03:23:55 +11:00
if mode == "switchuser":
xbmc.log('Requesting user switch')
utils.window('emby_serverStatus', value="401")
elif mode in ("manualsync", "repair"):
if utils.window('emby_dbScan') != "true":
import librarysync
lib = librarysync.LibrarySync()
if mode == "manualsync":
lib.fullSync(manualrun=True)
else:
lib.fullSync(repair=True)
else:
utils.logMsg("EMBY", "Database scan is already running.", 1)
elif mode == "texturecache":
import artwork
artwork.Artwork().FullTextureCacheSync()
else:
entrypoint.doMainListing()
if ( __name__ == "__main__" ):
xbmc.log('plugin.video.plexkodiconnect started')
if enableProfiling:
import cProfile
import pstats
import random
from time import gmtime, strftime
addonid = addon_.getAddonInfo('id').decode( 'utf-8' )
datapath = os.path.join( xbmc.translatePath( "special://profile/" ).decode( 'utf-8' ), "addon_data", addonid )
filename = os.path.join( datapath, strftime( "%Y%m%d%H%M%S",gmtime() ) + "-" + str( random.randrange(0,100000) ) + ".log" )
cProfile.run( 'Main()', filename )
stream = open( filename + ".txt", 'w')
p = pstats.Stats( filename, stream = stream )
p.sort_stats( "cumulative" )
p.print_stats()
2015-05-05 08:24:41 +10:00
else:
Main()
2015-05-04 01:39:12 +10:00
xbmc.log('plugin.video.plexkodiconnect stopped')