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
|
|
|
###############################################################################
|
2018-06-22 03:24:37 +10:00
|
|
|
from __future__ import absolute_import, division, unicode_literals
|
2016-07-24 18:59:48 +10:00
|
|
|
import logging
|
2018-06-22 03:24:37 +10:00
|
|
|
from sys import argv
|
2017-01-03 00:07:24 +11:00
|
|
|
from urlparse import parse_qsl
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2019-01-26 18:43:51 +11:00
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
import xbmcplugin
|
|
|
|
|
|
|
|
from resources.lib import entrypoint, utils, transfer, variables as v, loghandler
|
2018-08-06 15:51:59 +10:00
|
|
|
from resources.lib.tools import unicode_paths
|
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
|
|
|
loghandler.config()
|
2019-01-26 18:43:51 +11: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-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):
|
2019-01-26 18:43:51 +11:00
|
|
|
LOG.debug('Full sys.argv received: %s', argv)
|
2015-07-28 02:48:00 +10:00
|
|
|
# Parse parameters
|
2018-06-24 03:15:24 +10:00
|
|
|
path = unicode_paths.decode(argv[0])
|
|
|
|
arguments = unicode_paths.decode(argv[2])
|
|
|
|
params = dict(parse_qsl(arguments[1:]))
|
2017-03-08 20:58:08 +11:00
|
|
|
mode = params.get('mode', '')
|
|
|
|
itemid = params.get('id', '')
|
2017-01-03 00:07:24 +11:00
|
|
|
|
|
|
|
if mode == 'play':
|
2017-03-08 20:39:05 +11:00
|
|
|
self.play()
|
|
|
|
|
2017-03-14 07:39:07 +11:00
|
|
|
elif mode == 'plex_node':
|
|
|
|
self.play()
|
|
|
|
|
2017-03-08 20:39:05 +11:00
|
|
|
elif mode == 'ondeck':
|
2018-06-15 22:11:17 +10:00
|
|
|
entrypoint.on_deck_episodes(itemid,
|
|
|
|
params.get('tagname'),
|
|
|
|
int(params.get('limit')))
|
2017-03-08 20:39:05 +11:00
|
|
|
|
|
|
|
elif mode == 'recentepisodes':
|
2018-06-15 22:01:09 +10:00
|
|
|
entrypoint.recent_episodes(params.get('type'),
|
2018-06-15 22:00:12 +10:00
|
|
|
params.get('tagname'),
|
|
|
|
int(params.get('limit')))
|
2017-03-08 20:39:05 +11:00
|
|
|
|
|
|
|
elif mode == 'nextup':
|
2018-06-15 21:57:33 +10:00
|
|
|
entrypoint.next_up_episodes(params['tagname'],
|
|
|
|
int(params['limit']))
|
2017-03-08 20:39:05 +11:00
|
|
|
|
2017-03-08 21:02:25 +11:00
|
|
|
elif mode == 'inprogressepisodes':
|
2018-06-15 21:58:39 +10:00
|
|
|
entrypoint.in_progress_episodes(params['tagname'],
|
|
|
|
int(params['limit']))
|
2017-03-08 20:39:05 +11:00
|
|
|
|
|
|
|
elif mode == 'browseplex':
|
2017-03-09 02:21:00 +11:00
|
|
|
entrypoint.browse_plex(key=params.get('key'),
|
|
|
|
plex_section_id=params.get('id'))
|
2017-03-08 20:39:05 +11:00
|
|
|
|
|
|
|
elif mode == 'watchlater':
|
|
|
|
entrypoint.watchlater()
|
|
|
|
|
|
|
|
elif mode == 'channels':
|
|
|
|
entrypoint.channels()
|
|
|
|
|
2018-08-04 23:11:21 +10:00
|
|
|
elif mode == 'route_to_extras':
|
|
|
|
# Hack so we can store this path in the Kodi DB
|
|
|
|
handle = ('plugin://%s?mode=extras&plex_id=%s'
|
|
|
|
% (v.ADDON_ID, params.get('plex_id')))
|
2019-01-26 18:43:51 +11:00
|
|
|
if xbmcgui.getCurrentWindowId() == 10025:
|
2018-08-04 23:11:21 +10:00
|
|
|
# Video Window
|
2019-01-26 18:43:51 +11:00
|
|
|
xbmc.executebuiltin('Container.Update(\"%s\")' % handle)
|
2018-08-04 23:11:21 +10:00
|
|
|
else:
|
2019-01-26 18:43:51 +11:00
|
|
|
xbmc.executebuiltin('ActivateWindow(videos, \"%s\")' % handle)
|
2018-08-04 23:11:21 +10:00
|
|
|
|
2018-05-05 03:03:27 +10:00
|
|
|
elif mode == 'extras':
|
|
|
|
entrypoint.extras(plex_id=params.get('plex_id'))
|
|
|
|
|
2017-03-08 21:02:25 +11:00
|
|
|
elif mode == 'settings':
|
2019-01-26 18:43:51 +11:00
|
|
|
xbmc.executebuiltin('Addon.OpenSettings(%s)' % v.ADDON_ID)
|
2017-03-08 20:39:05 +11:00
|
|
|
|
2017-03-08 21:02:25 +11:00
|
|
|
elif mode == 'enterPMS':
|
2018-06-15 22:13:46 +10:00
|
|
|
entrypoint.create_new_pms()
|
2017-03-08 20:39:05 +11:00
|
|
|
|
|
|
|
elif mode == 'reset':
|
2019-01-26 18:43:51 +11:00
|
|
|
transfer.plex_command('RESET-PKC')
|
2017-03-08 20:39:05 +11:00
|
|
|
|
|
|
|
elif mode == 'togglePlexTV':
|
2018-06-15 21:44:46 +10:00
|
|
|
entrypoint.toggle_plex_tv_sign_in()
|
2017-03-08 20:39:05 +11:00
|
|
|
|
|
|
|
elif mode == 'passwords':
|
2018-06-22 03:24:37 +10:00
|
|
|
utils.passwords_xml()
|
2017-03-08 20:39:05 +11:00
|
|
|
|
|
|
|
elif mode == 'switchuser':
|
2018-06-15 21:50:04 +10:00
|
|
|
entrypoint.switch_plex_user()
|
2017-03-08 20:39:05 +11:00
|
|
|
|
2017-03-08 21:02:25 +11:00
|
|
|
elif mode in ('manualsync', 'repair'):
|
2018-11-26 03:03:19 +11:00
|
|
|
if mode == 'repair':
|
2019-01-26 18:43:51 +11:00
|
|
|
LOG.info('Requesting repair lib sync')
|
|
|
|
transfer.plex_command('repair-scan')
|
2018-11-26 03:03:19 +11:00
|
|
|
elif mode == 'manualsync':
|
2019-01-26 18:43:51 +11:00
|
|
|
LOG.info('Requesting full library scan')
|
|
|
|
transfer.plex_command('full-scan')
|
2017-03-08 20:39:05 +11:00
|
|
|
|
2017-03-08 21:02:25 +11:00
|
|
|
elif mode == 'texturecache':
|
2019-01-26 18:43:51 +11:00
|
|
|
LOG.info('Requesting texture caching of all textures')
|
|
|
|
transfer.plex_command('textures-scan')
|
2017-03-08 20:39:05 +11:00
|
|
|
|
2017-03-08 21:02:25 +11:00
|
|
|
elif mode == 'chooseServer':
|
2018-06-15 21:44:46 +10:00
|
|
|
entrypoint.choose_pms_server()
|
2017-03-08 20:39:05 +11:00
|
|
|
|
2017-03-08 21:02:25 +11:00
|
|
|
elif mode == 'deviceid':
|
2017-03-08 20:39:05 +11:00
|
|
|
self.deviceid()
|
|
|
|
|
|
|
|
elif mode == 'fanart':
|
2019-01-26 18:43:51 +11:00
|
|
|
LOG.info('User requested fanarttv refresh')
|
|
|
|
transfer.plex_command('fanart-scan')
|
2017-03-08 20:39:05 +11:00
|
|
|
|
2018-06-24 03:15:24 +10:00
|
|
|
elif '/extrafanart' in path:
|
|
|
|
plexpath = arguments[1:]
|
2017-03-08 20:58:08 +11:00
|
|
|
plexid = itemid
|
2018-06-15 22:05:48 +10:00
|
|
|
entrypoint.extra_fanart(plexid, plexpath)
|
|
|
|
entrypoint.get_video_files(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
|
2018-06-24 03:15:24 +10:00
|
|
|
elif ('/Extras' in path or '/VideoFiles' in path or
|
|
|
|
'/Extras' in arguments):
|
2017-03-08 20:58:08 +11:00
|
|
|
plexId = itemid or None
|
2018-06-15 22:05:48 +10:00
|
|
|
entrypoint.get_video_files(plexId, params)
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2018-07-17 21:48:09 +10:00
|
|
|
elif mode == 'playlists':
|
2018-07-30 21:20:40 +10:00
|
|
|
entrypoint.playlists(params.get('content_type'))
|
2018-07-17 21:48:09 +10:00
|
|
|
|
2018-07-28 00:01:05 +10:00
|
|
|
elif mode == 'hub':
|
|
|
|
entrypoint.hub(params.get('type'))
|
|
|
|
|
2015-12-25 06:51:47 +11:00
|
|
|
else:
|
2018-06-15 21:49:18 +10:00
|
|
|
entrypoint.show_main_menu(content_type=params.get('content_type'))
|
2017-03-08 20:39:05 +11:00
|
|
|
|
2017-08-22 02:53:38 +10:00
|
|
|
@staticmethod
|
|
|
|
def play():
|
2017-03-14 07:39:07 +11:00
|
|
|
"""
|
|
|
|
Start up playback_starter in main Python thread
|
|
|
|
"""
|
2018-04-16 02:13:48 +10:00
|
|
|
request = '%s&handle=%s' % (argv[2], HANDLE)
|
2017-03-08 21:02:25 +11:00
|
|
|
# Put the request into the 'queue'
|
2019-01-26 18:43:51 +11:00
|
|
|
transfer.plex_command('PLAY-%s' % request)
|
2018-04-16 02:13:48 +10:00
|
|
|
if HANDLE == -1:
|
|
|
|
# Handle -1 received, not waiting for main thread
|
|
|
|
return
|
2019-01-26 18:43:51 +11:00
|
|
|
# Wait for the result from the main PKC thread
|
|
|
|
result = transfer.wait_for_transfer()
|
2017-03-08 20:39:05 +11:00
|
|
|
if result is None:
|
2019-01-26 18:43:51 +11:00
|
|
|
LOG.error('Error encountered, aborting')
|
2018-06-22 03:24:37 +10:00
|
|
|
utils.dialog('notification',
|
|
|
|
heading='{plex}',
|
|
|
|
message=utils.lang(30128),
|
|
|
|
icon='{error}',
|
|
|
|
time=3000)
|
2019-01-26 18:43:51 +11:00
|
|
|
xbmcplugin.setResolvedUrl(HANDLE, False, xbmcgui.ListItem())
|
|
|
|
elif result is True:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
# Received a xbmcgui.ListItem()
|
|
|
|
xbmcplugin.setResolvedUrl(HANDLE, True, result)
|
2017-03-08 20:39:05 +11:00
|
|
|
|
2017-08-22 02:53:38 +10:00
|
|
|
@staticmethod
|
|
|
|
def deviceid():
|
2019-01-26 18:43:51 +11:00
|
|
|
window = xbmcgui.Window(10000)
|
|
|
|
deviceId_old = window.getProperty('plex_client_Id')
|
2018-07-04 16:05:24 +10:00
|
|
|
from resources.lib import clientinfo
|
2017-03-08 20:39:05 +11:00
|
|
|
try:
|
2018-07-04 16:05:24 +10:00
|
|
|
deviceId = clientinfo.getDeviceId(reset=True)
|
2017-03-08 20:39:05 +11:00
|
|
|
except Exception as e:
|
2019-01-26 18:43:51 +11:00
|
|
|
LOG.error('Failed to generate a new device Id: %s' % e)
|
2018-09-19 00:26:40 +10:00
|
|
|
utils.messageDialog(utils.lang(29999), utils.lang(33032))
|
2017-03-08 20:39:05 +11:00
|
|
|
else:
|
2019-01-26 18:43:51 +11:00
|
|
|
LOG.info('Successfully removed old device ID: %s New deviceId:'
|
2017-03-08 21:02:25 +11:00
|
|
|
'%s' % (deviceId_old, deviceId))
|
|
|
|
# 'Kodi will now restart to apply the changes'
|
2018-09-19 00:26:40 +10:00
|
|
|
utils.messageDialog(utils.lang(29999), utils.lang(33033))
|
2019-01-26 18:43:51 +11:00
|
|
|
xbmc.executebuiltin('RestartApp')
|
2015-12-25 06:51:47 +11:00
|
|
|
|
2017-08-22 02:53:38 +10:00
|
|
|
|
2017-03-08 21:02:25 +11:00
|
|
|
if __name__ == '__main__':
|
2019-01-26 18:43:51 +11:00
|
|
|
LOG.info('%s started' % v.ADDON_ID)
|
2019-01-14 03:30:47 +11:00
|
|
|
try:
|
|
|
|
v.database_paths()
|
|
|
|
except RuntimeError as err:
|
|
|
|
# Database does not exists
|
2019-01-26 18:43:51 +11:00
|
|
|
LOG.error('The current Kodi version is incompatible')
|
|
|
|
LOG.error('Error: %s', err)
|
2019-01-14 03:30:47 +11:00
|
|
|
else:
|
|
|
|
Main()
|
2019-01-26 18:43:51 +11:00
|
|
|
LOG.info('%s stopped' % v.ADDON_ID)
|