PlexKodiConnect/default.py

183 lines
6.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
###############################################################################
import logging
import os
import sys
import urlparse
2015-05-03 17:39:12 +02:00
import xbmc
import xbmcaddon
import xbmcgui
import xbmcplugin
_addon = xbmcaddon.Addon(id='plugin.video.plexkodiconnect')
try:
2016-08-29 19:12:46 +02:00
_addon_path = _addon.getAddonInfo('path').decode('utf-8')
except TypeError:
2016-08-29 19:12:46 +02:00
_addon_path = _addon.getAddonInfo('path').decode()
try:
2016-08-29 19:12:46 +02:00
_base_resource = xbmc.translatePath(os.path.join(
_addon_path,
'resources',
'lib')).decode('utf-8')
except TypeError:
2016-08-29 19:12:46 +02:00
_base_resource = xbmc.translatePath(os.path.join(
_addon_path,
'resources',
'lib')).decode()
2016-08-29 19:12:46 +02:00
sys.path.append(_base_resource)
###############################################################################
import entrypoint
import utils
###############################################################################
import loghandler
loghandler.config()
2016-08-29 19:12:46 +02:00
log = logging.getLogger("PLEX.default")
2016-08-29 19:12:46 +02:00
###############################################################################
2016-06-19 16:24:34 -05:00
class Main():
# MAIN ENTRY POINT
2016-06-19 16:24:34 -05:00
#@utils.profiling()
def __init__(self):
# Parse parameters
2016-08-29 19:12:46 +02:00
log.warn("Full sys.argv received: %s" % sys.argv)
base_url = sys.argv[0]
params = urlparse.parse_qs(sys.argv[2][1:])
try:
mode = params['mode'][0]
2016-01-22 16:32:36 +01:00
itemid = params.get('id', '')
if itemid:
try:
itemid = itemid[0]
except:
pass
except:
params = {}
mode = ""
modes = {
'reset': utils.reset,
'resetauth': entrypoint.resetAuth,
'play': entrypoint.doPlayback,
'passwords': utils.passwordsXML,
'channels': entrypoint.BrowseChannels,
'channelsfolder': entrypoint.BrowseChannels,
'browsecontent': entrypoint.BrowseContent,
2016-01-22 11:10:42 +01:00
'getsubfolders': entrypoint.GetSubFolders,
'nextup': entrypoint.getNextUpEpisodes,
'inprogressepisodes': entrypoint.getInProgressEpisodes,
'recentepisodes': entrypoint.getRecentEpisodes,
'refreshplaylist': entrypoint.refreshPlaylist,
2016-01-25 10:36:24 +01:00
'companion': entrypoint.plexCompanion,
'switchuser': entrypoint.switchPlexUser,
2016-03-04 13:34:30 +01:00
'deviceid': entrypoint.resetDeviceId,
2016-03-14 17:47:05 +01:00
'delete': entrypoint.deleteItem,
2016-03-15 13:09:51 +01:00
'browseplex': entrypoint.BrowsePlexContent,
'ondeck': entrypoint.getOnDeck,
2016-04-17 13:36:41 +02:00
'chooseServer': entrypoint.chooseServer,
2016-05-29 16:52:00 +02:00
'watchlater': entrypoint.watchlater,
'enterPMS': entrypoint.enterPMS,
'togglePlexTV': entrypoint.togglePlexTV,
'playwatchlater': entrypoint.playWatchLater
}
2016-03-04 22:00:24 +01:00
if "/extrafanart" in sys.argv[0]:
2016-05-31 08:06:42 +02:00
plexpath = sys.argv[2][1:]
plexid = params.get('id', [""])[0]
entrypoint.getExtraFanArt(plexid, plexpath)
2016-08-29 19:12:46 +02:00
entrypoint.getVideoFiles(plexid, plexpath)
2016-06-19 16:24:34 -05:00
return
if mode == 'fanart':
log.info('User requested fanarttv refresh')
utils.window('plex_runLibScan', value='fanart')
# Called by e.g. 3rd party plugin video extras
if ("/Extras" in sys.argv[0] or "/VideoFiles" in sys.argv[0] or
"/Extras" in sys.argv[2]):
plexId = params.get('id', [None])[0]
entrypoint.getVideoFiles(plexId, params)
if modes.get(mode):
# Simple functions
if mode == "play":
dbid = params.get('dbid')
2016-02-03 13:01:13 +01:00
# modes[mode](itemid, dbid)
modes[mode](itemid, dbid)
2016-03-15 14:19:56 +01:00
elif mode in ("nextup", "inprogressepisodes"):
limit = int(params['limit'][0])
modes[mode](itemid, limit)
2016-06-19 16:24:34 -05:00
elif mode in ("channels","getsubfolders"):
modes[mode](itemid)
elif mode == "browsecontent":
2016-06-19 16:24:34 -05:00
modes[mode](itemid, params.get('type',[""])[0], params.get('folderid',[""])[0])
2016-03-14 17:47:05 +01:00
elif mode == 'browseplex':
modes[mode](
itemid,
params.get('type', [""])[0],
params.get('folderid', [""])[0])
2016-03-15 14:19:56 +01:00
elif mode in ('ondeck', 'recentepisodes'):
2016-03-15 13:09:51 +01:00
modes[mode](
itemid,
params.get('type', [""])[0],
params.get('tagname', [""])[0],
2016-03-15 14:19:56 +01:00
int(params.get('limit', [""])[0]))
2016-03-15 13:09:51 +01:00
elif mode == "channelsfolder":
folderid = params['folderid'][0]
modes[mode](itemid, folderid)
elif mode == "companion":
2016-01-29 20:07:21 +01:00
modes[mode](itemid, params=sys.argv[2])
elif mode == 'playwatchlater':
modes[mode](params.get('id')[0], params.get('viewOffset')[0])
else:
modes[mode]()
else:
# Other functions
if mode == "settings":
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.plexkodiconnect)')
elif mode in ("manualsync", "repair"):
2016-05-31 08:06:42 +02:00
if utils.window('plex_online') != "true":
# Server is not online, do not run the sync
xbmcgui.Dialog().ok(
"PlexKodiConnect",
"Unable to run the sync, the add-on is not connected "
"to a Plex server.")
2016-08-29 19:12:46 +02:00
log.error("Not connected to a PMS.")
else:
2016-04-07 11:57:34 +02:00
if mode == 'repair':
utils.window('plex_runLibScan', value="repair")
log.info("Requesting repair lib sync")
2016-04-07 11:57:34 +02:00
elif mode == 'manualsync':
log.info("Requesting full library scan")
2016-04-07 11:57:34 +02:00
utils.window('plex_runLibScan', value="full")
elif mode == "texturecache":
utils.window('plex_runLibScan', value='del_textures')
else:
entrypoint.doMainListing()
# Prevent Kodi from hanging in an infinite loop waiting for more
xbmcplugin.endOfDirectory(int(sys.argv[1]))
2016-06-19 16:24:34 -05:00
if __name__ == "__main__":
2016-08-29 19:12:46 +02:00
log.info('plugin.video.plexkodiconnect started')
2016-06-19 16:24:34 -05:00
Main()
2016-08-29 19:12:46 +02:00
log.info('plugin.video.plexkodiconnect stopped')