2015-07-22 14:53:59 +10:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2015-07-28 02:48:00 +10:00
|
|
|
import urlparse
|
2015-05-04 01:39:12 +10:00
|
|
|
|
2015-12-25 06:51:47 +11:00
|
|
|
import xbmc
|
|
|
|
import xbmcaddon
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
2015-12-27 21:49:14 +11:00
|
|
|
addon_ = xbmcaddon.Addon(id='plugin.video.plexkodiconnect')
|
2015-07-22 14:53:59 +10:00
|
|
|
addon_path = addon_.getAddonInfo('path').decode('utf-8')
|
2015-12-25 06:51:47 +11:00
|
|
|
base_resource = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8')
|
|
|
|
sys.path.append(base_resource)
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
import entrypoint
|
|
|
|
import utils
|
|
|
|
|
|
|
|
#################################################################################################
|
2015-05-05 21:27:45 +10:00
|
|
|
|
2015-07-28 02:48:00 +10:00
|
|
|
enableProfiling = False
|
|
|
|
|
|
|
|
class Main:
|
|
|
|
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2015-07-28 02:48:00 +10:00
|
|
|
# MAIN ENTRY POINT
|
|
|
|
def __init__(self):
|
|
|
|
# Parse parameters
|
2016-01-23 01:37:20 +11:00
|
|
|
xbmc.log("Full sys.argv received: %s" % sys.argv)
|
2015-07-28 02:48:00 +10:00
|
|
|
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', '')
|
2015-12-25 06:51:47 +11:00
|
|
|
if itemid:
|
2016-01-23 01:37:20 +11:00
|
|
|
try:
|
|
|
|
itemid = itemid[0]
|
|
|
|
except:
|
|
|
|
pass
|
2015-07-28 02:48:00 +10:00
|
|
|
except:
|
|
|
|
params = {}
|
|
|
|
mode = ""
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
modes = {
|
|
|
|
|
|
|
|
'reset': utils.reset,
|
|
|
|
'resetauth': entrypoint.resetAuth,
|
|
|
|
'play': entrypoint.doPlayback,
|
|
|
|
'passwords': utils.passwordsXML,
|
|
|
|
'adduser': entrypoint.addUser,
|
|
|
|
'thememedia': entrypoint.getThemeMedia,
|
|
|
|
'channels': entrypoint.BrowseChannels,
|
|
|
|
'channelsfolder': entrypoint.BrowseChannels,
|
2016-01-12 08:20:34 +11:00
|
|
|
'browsecontent': entrypoint.BrowseContent,
|
2016-01-22 21:10:42 +11:00
|
|
|
'getsubfolders': entrypoint.GetSubFolders,
|
2015-12-25 06:51:47 +11:00
|
|
|
'nextup': entrypoint.getNextUpEpisodes,
|
|
|
|
'inprogressepisodes': entrypoint.getInProgressEpisodes,
|
2015-12-26 20:42:13 +11:00
|
|
|
'recentepisodes': entrypoint.getRecentEpisodes,
|
2016-01-23 01:37:20 +11:00
|
|
|
'refreshplaylist': entrypoint.refreshPlaylist,
|
2016-01-25 20:36:24 +11:00
|
|
|
'companion': entrypoint.plexCompanion,
|
2016-03-01 20:10:11 +11:00
|
|
|
'switchuser': entrypoint.switchPlexUser,
|
2016-03-04 23:34:30 +11:00
|
|
|
'deviceid': entrypoint.resetDeviceId,
|
2016-03-10 18:12:20 +11:00
|
|
|
'reConnect': entrypoint.reConnect,
|
2016-03-10 10:05:35 +11:00
|
|
|
'delete': entrypoint.deleteItem
|
2015-12-25 06:51:47 +11:00
|
|
|
}
|
2016-01-07 09:22:10 +11:00
|
|
|
|
2016-03-05 08:00:24 +11:00
|
|
|
if "/extrafanart" in sys.argv[0]:
|
2016-03-05 00:03:15 +11:00
|
|
|
embypath = sys.argv[2][1:]
|
|
|
|
embyid = params.get('id',[""])[0]
|
|
|
|
entrypoint.getExtraFanArt(embyid,embypath)
|
2016-03-05 08:00:24 +11:00
|
|
|
|
|
|
|
if "/Extras" in sys.argv[0] or "/VideoFiles" in sys.argv[0]:
|
|
|
|
embypath = sys.argv[2][1:]
|
|
|
|
embyid = params.get('id',[""])[0]
|
|
|
|
entrypoint.getVideoFiles(embyid,embypath)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
if modes.get(mode):
|
|
|
|
# Simple functions
|
|
|
|
if mode == "play":
|
|
|
|
dbid = params.get('dbid')
|
2016-02-03 23:01:13 +11:00
|
|
|
# modes[mode](itemid, dbid)
|
2015-12-25 06:51:47 +11:00
|
|
|
modes[mode](itemid, dbid)
|
|
|
|
|
|
|
|
elif mode in ("nextup", "inprogressepisodes", "recentepisodes"):
|
|
|
|
limit = int(params['limit'][0])
|
|
|
|
modes[mode](itemid, limit)
|
2015-07-28 02:48:00 +10:00
|
|
|
|
2016-01-22 21:10:42 +11:00
|
|
|
elif mode in ["channels","getsubfolders"]:
|
2015-12-25 06:51:47 +11:00
|
|
|
modes[mode](itemid)
|
2016-01-12 08:20:34 +11:00
|
|
|
|
|
|
|
elif mode == "browsecontent":
|
2016-01-22 21:10:42 +11:00
|
|
|
modes[mode]( itemid, params.get('type',[""])[0], params.get('folderid',[""])[0] )
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
elif mode == "channelsfolder":
|
|
|
|
folderid = params['folderid'][0]
|
|
|
|
modes[mode](itemid, folderid)
|
2016-01-23 01:37:20 +11:00
|
|
|
elif mode == "companion":
|
2016-01-30 06:07:21 +11:00
|
|
|
modes[mode](itemid, params=sys.argv[2])
|
2015-12-25 06:51:47 +11:00
|
|
|
else:
|
|
|
|
modes[mode]()
|
|
|
|
else:
|
|
|
|
# Other functions
|
|
|
|
if mode == "settings":
|
2015-12-27 21:49:14 +11:00
|
|
|
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.plexkodiconnect)')
|
2015-12-25 06:51:47 +11:00
|
|
|
elif mode in ("manualsync", "repair"):
|
2016-02-10 18:07:52 +11:00
|
|
|
if utils.window('emby_online') != "true":
|
|
|
|
# Server is not online, do not run the sync
|
|
|
|
xbmcgui.Dialog().ok(heading="Emby for Kodi",
|
|
|
|
line1=("Unable to run the sync, the add-on is not "
|
|
|
|
"connected to the Emby server."))
|
|
|
|
utils.logMsg("EMBY", "Not connected to the emby server.", 1)
|
|
|
|
return
|
|
|
|
|
2015-12-27 05:53:24 +11:00
|
|
|
if utils.window('emby_dbScan') != "true":
|
|
|
|
import librarysync
|
|
|
|
lib = librarysync.LibrarySync()
|
|
|
|
if mode == "manualsync":
|
2016-03-09 11:51:23 +11:00
|
|
|
librarysync.ManualSync().sync(dialog=True)
|
2015-12-27 05:53:24 +11:00
|
|
|
else:
|
|
|
|
lib.fullSync(repair=True)
|
2015-12-25 06:51:47 +11:00
|
|
|
else:
|
2015-12-27 05:53:24 +11:00
|
|
|
utils.logMsg("EMBY", "Database scan is already running.", 1)
|
2015-12-26 20:42:13 +11:00
|
|
|
|
2015-12-25 06:51:47 +11:00
|
|
|
elif mode == "texturecache":
|
|
|
|
import artwork
|
|
|
|
artwork.Artwork().FullTextureCacheSync()
|
|
|
|
else:
|
|
|
|
entrypoint.doMainListing()
|
|
|
|
|
2015-07-28 02:48:00 +10:00
|
|
|
|
|
|
|
if ( __name__ == "__main__" ):
|
2015-12-27 21:49:14 +11:00
|
|
|
xbmc.log('plugin.video.plexkodiconnect started')
|
2015-07-28 02:48:00 +10:00
|
|
|
|
|
|
|
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
|
|
|
|
2015-07-28 02:48:00 +10:00
|
|
|
else:
|
|
|
|
Main()
|
2015-05-04 01:39:12 +10:00
|
|
|
|
2015-12-27 21:49:14 +11:00
|
|
|
xbmc.log('plugin.video.plexkodiconnect stopped')
|