2015-07-22 14:53:59 +10:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-04-09 23:46:51 +10:00
|
|
|
###############################################################################
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-07-24 18:59:48 +10:00
|
|
|
import logging
|
2017-01-03 00:07:24 +11:00
|
|
|
from os import path as os_path
|
|
|
|
from sys import path as sys_path, argv
|
|
|
|
from urlparse import parse_qsl
|
2015-05-04 01:39:12 +10:00
|
|
|
|
2017-01-03 00:07:24 +11:00
|
|
|
from xbmc import translatePath, sleep, executebuiltin
|
|
|
|
from xbmcaddon import Addon
|
|
|
|
from xbmcgui import ListItem, Dialog
|
|
|
|
from xbmcplugin import setResolvedUrl
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2017-01-03 00:07:24 +11:00
|
|
|
_addon = Addon(id='plugin.video.plexkodiconnect')
|
2016-05-07 21:25:51 +10:00
|
|
|
try:
|
2016-08-30 03:12:46 +10:00
|
|
|
_addon_path = _addon.getAddonInfo('path').decode('utf-8')
|
2016-05-07 21:25:51 +10:00
|
|
|
except TypeError:
|
2016-08-30 03:12:46 +10:00
|
|
|
_addon_path = _addon.getAddonInfo('path').decode()
|
2016-05-07 21:25:51 +10:00
|
|
|
try:
|
2017-01-03 00:07:24 +11:00
|
|
|
_base_resource = translatePath(os_path.join(
|
2016-08-30 03:12:46 +10:00
|
|
|
_addon_path,
|
2016-05-07 21:25:51 +10:00
|
|
|
'resources',
|
|
|
|
'lib')).decode('utf-8')
|
|
|
|
except TypeError:
|
2017-01-03 00:07:24 +11:00
|
|
|
_base_resource = translatePath(os_path.join(
|
2016-08-30 03:12:46 +10:00
|
|
|
_addon_path,
|
2016-05-07 21:25:51 +10:00
|
|
|
'resources',
|
|
|
|
'lib')).decode()
|
2017-01-03 00:07:24 +11:00
|
|
|
sys_path.append(_base_resource)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-04-09 23:46:51 +10:00
|
|
|
###############################################################################
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
import entrypoint
|
2017-01-25 02:04:42 +11:00
|
|
|
from utils import window, pickl_window, reset, passwordsXML, language as lang
|
2017-01-03 00:07:24 +11:00
|
|
|
from pickler import unpickle_me
|
|
|
|
from PKC_listitem import convert_PKC_to_listitem
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-04-09 23:46:51 +10:00
|
|
|
###############################################################################
|
2015-05-05 21:27:45 +10:00
|
|
|
|
2016-07-24 18:59:48 +10:00
|
|
|
import loghandler
|
|
|
|
|
|
|
|
loghandler.config()
|
2016-08-30 03:12:46 +10:00
|
|
|
log = logging.getLogger("PLEX.default")
|
2015-07-28 02:48:00 +10:00
|
|
|
|
2016-08-30 03:12:46 +10:00
|
|
|
###############################################################################
|
2015-07-28 02:48:00 +10:00
|
|
|
|
2017-01-03 00:07:24 +11:00
|
|
|
ARGV = argv
|
|
|
|
HANDLE = int(argv[1])
|
|
|
|
|
2015-07-28 02:48:00 +10:00
|
|
|
|
2016-06-20 07:24:34 +10:00
|
|
|
class Main():
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2015-07-28 02:48:00 +10:00
|
|
|
# MAIN ENTRY POINT
|
2017-01-03 00:07:24 +11:00
|
|
|
# @utils.profiling()
|
2015-07-28 02:48:00 +10:00
|
|
|
def __init__(self):
|
2017-01-03 00:07:24 +11:00
|
|
|
log.debug("Full sys.argv received: %s" % ARGV)
|
2015-07-28 02:48:00 +10:00
|
|
|
# Parse parameters
|
2017-01-03 00:07:24 +11:00
|
|
|
params = dict(parse_qsl(ARGV[2][1:]))
|
2015-07-28 02:48:00 +10:00
|
|
|
try:
|
2017-01-03 00:07:24 +11:00
|
|
|
mode = params['mode']
|
2016-01-23 02:32:36 +11:00
|
|
|
itemid = params.get('id', '')
|
2015-07-28 02:48:00 +10:00
|
|
|
except:
|
|
|
|
mode = ""
|
2017-01-03 00:07:24 +11:00
|
|
|
itemid = ''
|
|
|
|
|
|
|
|
if mode == 'play':
|
|
|
|
# Put the request into the "queue"
|
|
|
|
while window('plex_play_new_item'):
|
|
|
|
sleep(20)
|
|
|
|
window('plex_play_new_item',
|
|
|
|
value='%s%s' % (mode, ARGV[2]))
|
|
|
|
# Wait for the result
|
|
|
|
while not pickl_window('plex_result'):
|
|
|
|
sleep(20)
|
|
|
|
result = unpickle_me()
|
|
|
|
if result is None:
|
|
|
|
log.error('Error encountered, aborting')
|
|
|
|
setResolvedUrl(HANDLE, False, ListItem())
|
|
|
|
elif result.listitem:
|
|
|
|
listitem = convert_PKC_to_listitem(result.listitem)
|
|
|
|
setResolvedUrl(HANDLE, True, listitem)
|
|
|
|
return
|
2015-12-25 06:51:47 +11:00
|
|
|
|
|
|
|
modes = {
|
2017-01-03 00:07:24 +11:00
|
|
|
'reset': reset,
|
2015-12-25 06:51:47 +11:00
|
|
|
'resetauth': entrypoint.resetAuth,
|
2017-01-03 00:07:24 +11:00
|
|
|
'passwords': passwordsXML,
|
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-03-01 20:10:11 +11:00
|
|
|
'switchuser': entrypoint.switchPlexUser,
|
2016-03-04 23:34:30 +11:00
|
|
|
'deviceid': entrypoint.resetDeviceId,
|
2016-03-15 23:09:51 +11:00
|
|
|
'browseplex': entrypoint.BrowsePlexContent,
|
2016-03-24 22:34:39 +11:00
|
|
|
'ondeck': entrypoint.getOnDeck,
|
2016-04-17 21:36:41 +10:00
|
|
|
'chooseServer': entrypoint.chooseServer,
|
2016-05-30 00:52:00 +10:00
|
|
|
'watchlater': entrypoint.watchlater,
|
|
|
|
'enterPMS': entrypoint.enterPMS,
|
2016-06-20 02:30:21 +10:00
|
|
|
'togglePlexTV': entrypoint.togglePlexTV,
|
2017-01-03 01:41:38 +11:00
|
|
|
'Plex_Node': entrypoint.Plex_Node
|
2015-12-25 06:51:47 +11:00
|
|
|
}
|
2016-04-09 23:46:51 +10:00
|
|
|
|
2017-01-03 00:07:24 +11:00
|
|
|
if "/extrafanart" in ARGV[0]:
|
|
|
|
plexpath = ARGV[2][1:]
|
2017-01-16 04:16:39 +11:00
|
|
|
plexid = params.get('id')
|
2016-05-31 16:06:42 +10:00
|
|
|
entrypoint.getExtraFanArt(plexid, plexpath)
|
2016-08-30 03:12:46 +10:00
|
|
|
entrypoint.getVideoFiles(plexid, plexpath)
|
2016-06-20 07:24:34 +10:00
|
|
|
return
|
2016-04-09 23:46:51 +10:00
|
|
|
|
2016-09-11 20:15:26 +10:00
|
|
|
if mode == 'fanart':
|
|
|
|
log.info('User requested fanarttv refresh')
|
2017-01-03 00:07:24 +11:00
|
|
|
window('plex_runLibScan', value='fanart')
|
2016-09-11 20:15:26 +10:00
|
|
|
|
2016-04-09 23:46:51 +10:00
|
|
|
# Called by e.g. 3rd party plugin video extras
|
2017-01-03 00:07:24 +11:00
|
|
|
if ("/Extras" in ARGV[0] or "/VideoFiles" in ARGV[0] or
|
|
|
|
"/Extras" in ARGV[2]):
|
2017-01-03 01:41:38 +11:00
|
|
|
plexId = params.get('id', None)
|
2016-04-09 23:46:51 +10:00
|
|
|
entrypoint.getVideoFiles(plexId, params)
|
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)
|
|
|
|
|
2016-03-16 00:19:56 +11:00
|
|
|
elif mode in ("nextup", "inprogressepisodes"):
|
2017-01-03 01:41:38 +11:00
|
|
|
limit = int(params['limit'])
|
2015-12-25 06:51:47 +11:00
|
|
|
modes[mode](itemid, limit)
|
2015-07-28 02:48:00 +10:00
|
|
|
|
2016-06-20 07:24:34 +10: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":
|
2017-01-16 04:16:39 +11:00
|
|
|
modes[mode](itemid, params.get('type'), params.get('folderid'))
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-03-15 03:47:05 +11:00
|
|
|
elif mode == 'browseplex':
|
|
|
|
modes[mode](
|
|
|
|
itemid,
|
2017-01-16 04:16:39 +11:00
|
|
|
params.get('type'),
|
|
|
|
params.get('folderid'))
|
2016-03-15 03:47:05 +11:00
|
|
|
|
2016-03-16 00:19:56 +11:00
|
|
|
elif mode in ('ondeck', 'recentepisodes'):
|
2016-03-15 23:09:51 +11:00
|
|
|
modes[mode](
|
|
|
|
itemid,
|
2017-01-16 04:16:39 +11:00
|
|
|
params.get('type'),
|
|
|
|
params.get('tagname'),
|
|
|
|
int(params.get('limit')))
|
2016-03-15 23:09:51 +11:00
|
|
|
|
2015-12-25 06:51:47 +11:00
|
|
|
elif mode == "channelsfolder":
|
2017-01-03 01:41:38 +11:00
|
|
|
folderid = params['folderid']
|
2015-12-25 06:51:47 +11:00
|
|
|
modes[mode](itemid, folderid)
|
2016-01-23 01:37:20 +11:00
|
|
|
elif mode == "companion":
|
2017-01-03 00:07:24 +11:00
|
|
|
modes[mode](itemid, params=ARGV[2])
|
2017-01-03 01:41:38 +11:00
|
|
|
elif mode == 'Plex_Node':
|
2017-01-03 02:42:07 +11:00
|
|
|
modes[mode](params.get('id'),
|
|
|
|
params.get('viewOffset'),
|
|
|
|
params.get('plex_type'))
|
2015-12-25 06:51:47 +11:00
|
|
|
else:
|
|
|
|
modes[mode]()
|
|
|
|
else:
|
|
|
|
# Other functions
|
|
|
|
if mode == "settings":
|
2017-01-03 00:07:24 +11:00
|
|
|
executebuiltin('Addon.OpenSettings(plugin.video.plexkodiconnect)')
|
2016-05-16 00:02:19 +10:00
|
|
|
elif mode in ("manualsync", "repair"):
|
2017-01-03 00:07:24 +11:00
|
|
|
if window('plex_online') != "true":
|
2016-02-10 18:07:52 +11:00
|
|
|
# Server is not online, do not run the sync
|
2017-01-03 00:07:24 +11:00
|
|
|
Dialog().ok(
|
2017-01-25 02:04:42 +11:00
|
|
|
lang(29999),
|
2016-05-16 00:02:19 +10:00
|
|
|
"Unable to run the sync, the add-on is not connected "
|
|
|
|
"to a Plex server.")
|
2016-08-30 03:12:46 +10:00
|
|
|
log.error("Not connected to a PMS.")
|
2015-12-25 06:51:47 +11:00
|
|
|
else:
|
2016-04-07 19:57:34 +10:00
|
|
|
if mode == 'repair':
|
2017-01-03 00:07:24 +11:00
|
|
|
window('plex_runLibScan', value="repair")
|
2016-09-17 23:17:01 +10:00
|
|
|
log.info("Requesting repair lib sync")
|
2016-04-07 19:57:34 +10:00
|
|
|
elif mode == 'manualsync':
|
2016-09-17 23:17:01 +10:00
|
|
|
log.info("Requesting full library scan")
|
2017-01-03 00:07:24 +11:00
|
|
|
window('plex_runLibScan', value="full")
|
2015-12-25 06:51:47 +11:00
|
|
|
elif mode == "texturecache":
|
2017-01-03 00:07:24 +11:00
|
|
|
window('plex_runLibScan', value='del_textures')
|
2015-12-25 06:51:47 +11:00
|
|
|
else:
|
|
|
|
entrypoint.doMainListing()
|
|
|
|
|
2016-06-20 07:24:34 +10:00
|
|
|
if __name__ == "__main__":
|
2016-08-30 03:12:46 +10:00
|
|
|
log.info('plugin.video.plexkodiconnect started')
|
2016-06-20 07:24:34 +10:00
|
|
|
Main()
|
2016-08-30 03:12:46 +10:00
|
|
|
log.info('plugin.video.plexkodiconnect stopped')
|