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
|
2017-02-02 18:30:40 +11:00
|
|
|
from xbmcgui import ListItem
|
2017-01-03 00:07:24 +11:00
|
|
|
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-02-02 18:30:40 +11:00
|
|
|
from utils import window, pickl_window, reset, passwordsXML, language as lang,\
|
|
|
|
dialog
|
2017-01-03 00:07:24 +11:00
|
|
|
from pickler import unpickle_me
|
|
|
|
from PKC_listitem import convert_PKC_to_listitem
|
2017-03-08 20:39:05 +11:00
|
|
|
import variables as v
|
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
|
|
|
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-02-02 18:30:40 +11:00
|
|
|
log.debug("Full sys.argv received: %s" % argv)
|
2015-07-28 02:48:00 +10:00
|
|
|
# Parse parameters
|
2017-02-02 18:30:40 +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':
|
2017-03-08 20:39:05 +11:00
|
|
|
self.play()
|
|
|
|
|
|
|
|
elif mode == 'ondeck':
|
|
|
|
entrypoint.getOnDeck(itemid,
|
|
|
|
params.get('type'),
|
|
|
|
params.get('tagname'),
|
|
|
|
int(params.get('limit')))
|
|
|
|
|
|
|
|
elif mode == 'recentepisodes':
|
|
|
|
entrypoint.getRecentEpisodes(itemid,
|
|
|
|
params.get('type'),
|
|
|
|
params.get('tagname'),
|
|
|
|
int(params.get('limit')))
|
|
|
|
|
|
|
|
elif mode == 'nextup':
|
|
|
|
entrypoint.getNextUpEpisodes(params['tagname'],
|
|
|
|
int(params['limit']))
|
|
|
|
|
|
|
|
elif mode == "inprogressepisodes":
|
|
|
|
entrypoint.getInProgressEpisodes(params['tagname'],
|
|
|
|
int(params['limit']))
|
|
|
|
|
|
|
|
elif mode == 'Plex_Node':
|
|
|
|
entrypoint.Plex_Node(params.get('id'), params.get('viewOffset'))
|
|
|
|
|
|
|
|
elif mode == 'browse_plex_folder':
|
|
|
|
entrypoint.browse_plex_folder(params.get('id'))
|
|
|
|
|
|
|
|
elif mode == 'browseplex':
|
|
|
|
entrypoint.BrowsePlexContent(itemid,
|
|
|
|
params.get('type'),
|
|
|
|
params.get('folderid'))
|
|
|
|
|
|
|
|
elif mode == "getsubfolders":
|
|
|
|
entrypoint.GetSubFolders(itemid)
|
|
|
|
|
|
|
|
elif mode == 'watchlater':
|
|
|
|
entrypoint.watchlater()
|
|
|
|
|
|
|
|
elif mode == 'channels':
|
|
|
|
entrypoint.channels()
|
|
|
|
|
|
|
|
elif mode == "settings":
|
|
|
|
executebuiltin('Addon.OpenSettings(%s)' % v.ADDON_ID)
|
|
|
|
|
|
|
|
elif mode == "enterPMS":
|
|
|
|
entrypoint.enterPMS()
|
|
|
|
|
|
|
|
elif mode == 'reset':
|
|
|
|
reset()
|
|
|
|
|
|
|
|
elif mode == 'togglePlexTV':
|
|
|
|
entrypoint.togglePlexTV()
|
|
|
|
|
|
|
|
elif mode == 'resetauth':
|
|
|
|
entrypoint.resetAuth()
|
|
|
|
|
|
|
|
elif mode == 'passwords':
|
|
|
|
passwordsXML()
|
|
|
|
|
|
|
|
elif mode == 'switchuser':
|
|
|
|
entrypoint.switchPlexUser()
|
|
|
|
|
|
|
|
elif mode in ("manualsync", "repair"):
|
|
|
|
if window('plex_online') != "true":
|
|
|
|
# Server is not online, do not run the sync
|
|
|
|
dialog('ok',
|
|
|
|
heading=lang(29999),
|
|
|
|
message=lang(39205))
|
|
|
|
log.error("Not connected to a PMS.")
|
|
|
|
else:
|
|
|
|
if mode == 'repair':
|
|
|
|
window('plex_runLibScan', value="repair")
|
|
|
|
log.info("Requesting repair lib sync")
|
|
|
|
elif mode == 'manualsync':
|
|
|
|
log.info("Requesting full library scan")
|
|
|
|
window('plex_runLibScan', value="full")
|
|
|
|
|
|
|
|
elif mode == "texturecache":
|
|
|
|
window('plex_runLibScan', value='del_textures')
|
|
|
|
|
|
|
|
elif mode == "chooseServer":
|
|
|
|
entrypoint.chooseServer()
|
|
|
|
|
|
|
|
elif mode == "refreshplaylist":
|
|
|
|
log.info('Requesting playlist/nodes refresh')
|
|
|
|
window('plex_runLibScan', value="views")
|
|
|
|
|
|
|
|
elif mode == "deviceid":
|
|
|
|
self.deviceid()
|
|
|
|
|
|
|
|
elif mode == 'fanart':
|
|
|
|
log.info('User requested fanarttv refresh')
|
|
|
|
window('plex_runLibScan', value='fanart')
|
|
|
|
|
|
|
|
elif "/extrafanart" in argv[0]:
|
2017-02-02 18:30:40 +11:00
|
|
|
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-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-03-08 20:39:05 +11:00
|
|
|
elif ("/Extras" in argv[0] or "/VideoFiles" in argv[0] or
|
2017-02-02 18:30:40 +11:00
|
|
|
"/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
|
|
|
|
|
|
|
else:
|
2017-03-08 20:39:05 +11:00
|
|
|
entrypoint.doMainListing()
|
|
|
|
|
|
|
|
def play(self):
|
|
|
|
# Put the request into the "queue"
|
|
|
|
while window('plex_play_new_item'):
|
|
|
|
sleep(50)
|
|
|
|
window('plex_play_new_item',
|
|
|
|
value='%s%s' % ('play', argv[2]))
|
|
|
|
# Wait for the result
|
|
|
|
while not pickl_window('plex_result'):
|
|
|
|
sleep(50)
|
|
|
|
result = unpickle_me()
|
|
|
|
if result is None:
|
|
|
|
log.error('Error encountered, aborting')
|
|
|
|
dialog('notification',
|
|
|
|
heading='{plex}',
|
|
|
|
message=lang(30128),
|
|
|
|
icon='{error}',
|
|
|
|
time=3000)
|
|
|
|
setResolvedUrl(HANDLE, False, ListItem())
|
|
|
|
elif result.listitem:
|
|
|
|
listitem = convert_PKC_to_listitem(result.listitem)
|
|
|
|
setResolvedUrl(HANDLE, True, listitem)
|
|
|
|
|
|
|
|
def deviceid(self):
|
|
|
|
deviceId_old = window('plex_client_Id')
|
|
|
|
from clientinfo import getDeviceId
|
|
|
|
try:
|
|
|
|
deviceId = getDeviceId(reset=True)
|
|
|
|
except Exception as e:
|
|
|
|
log.error("Failed to generate a new device Id: %s" % e)
|
|
|
|
dialog('ok', lang(29999), lang(33032))
|
|
|
|
else:
|
|
|
|
log.info("Successfully removed old device ID: %s New deviceId:"
|
|
|
|
"%s" % (deviceId_old, deviceId))
|
|
|
|
# "Kodi will now restart to apply the changes"
|
|
|
|
dialog('ok', lang(29999), lang(33033))
|
|
|
|
executebuiltin('RestartApp')
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2016-06-20 07:24:34 +10:00
|
|
|
if __name__ == "__main__":
|
2017-03-08 20:39:05 +11:00
|
|
|
log.info('%s started' % v.ADDON_ID)
|
2016-06-20 07:24:34 +10:00
|
|
|
Main()
|
2017-03-08 20:39:05 +11:00
|
|
|
log.info('%s stopped' % v.ADDON_ID)
|