2015-07-22 14:53:59 +10:00
|
|
|
# -*- coding: utf-8 -*-
|
2020-12-19 03:10:20 +11:00
|
|
|
from builtins import object
|
2016-07-24 18:59:48 +10:00
|
|
|
import logging
|
2018-06-22 03:24:37 +10:00
|
|
|
from sys import argv
|
2020-12-19 03:10:20 +11:00
|
|
|
from urllib.parse 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
|
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
|
|
|
|
|
|
|
|
2020-12-19 03:10:20 +11:00
|
|
|
class Main(object):
|
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
|
2019-03-30 20:32:56 +11:00
|
|
|
params = dict(parse_qsl(argv[2][1:]))
|
2020-12-20 06:43:08 +11:00
|
|
|
arguments = argv[2]
|
|
|
|
path = argv[0]
|
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 == 'browseplex':
|
2017-03-09 02:21:00 +11:00
|
|
|
entrypoint.browse_plex(key=params.get('key'),
|
2019-01-09 04:00:54 +11:00
|
|
|
plex_type=params.get('plex_type'),
|
|
|
|
section_id=params.get('section_id'),
|
|
|
|
synched=params.get('synched') != 'false',
|
2020-02-03 00:09:10 +11:00
|
|
|
prompt=params.get('prompt'),
|
|
|
|
query=params.get('query'))
|
2017-03-08 20:39:05 +11:00
|
|
|
|
2019-07-07 05:20:23 +10:00
|
|
|
elif mode == 'show_section':
|
|
|
|
entrypoint.show_section(params.get('section_index'))
|
|
|
|
|
2017-03-08 20:39:05 +11:00
|
|
|
elif mode == 'watchlater':
|
|
|
|
entrypoint.watchlater()
|
|
|
|
|
|
|
|
elif mode == 'channels':
|
2019-01-09 04:00:54 +11:00
|
|
|
entrypoint.browse_plex(key='/channels/all')
|
2017-03-08 20:39:05 +11:00
|
|
|
|
2019-10-31 22:51:21 +11:00
|
|
|
elif mode == 'search':
|
|
|
|
# "Search"
|
|
|
|
entrypoint.browse_plex(key='/hubs/search',
|
|
|
|
args={'includeCollections': 1,
|
|
|
|
'includeExternalMedia': 1},
|
2020-02-03 00:09:10 +11:00
|
|
|
prompt=utils.lang(137),
|
|
|
|
query=params.get('query'))
|
2019-10-31 22:51:21 +11:00
|
|
|
|
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':
|
2019-01-09 04:00:54 +11:00
|
|
|
LOG.info('Request to manually enter new PMS address')
|
|
|
|
transfer.plex_command('enter_new_pms_address')
|
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':
|
2019-01-09 04:00:54 +11:00
|
|
|
LOG.info('Toggle of Plex.tv sign-in requested')
|
|
|
|
transfer.plex_command('toggle_plex_tv_sign_in')
|
2017-03-08 20:39:05 +11:00
|
|
|
|
|
|
|
elif mode == 'passwords':
|
2019-01-29 00:26:42 +11:00
|
|
|
from resources.lib.windows import direct_path_sources
|
|
|
|
direct_path_sources.start()
|
2017-03-08 20:39:05 +11:00
|
|
|
|
|
|
|
elif mode == 'switchuser':
|
2019-01-09 04:00:54 +11:00
|
|
|
LOG.info('Plex home user switch requested')
|
|
|
|
transfer.plex_command('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':
|
2019-01-09 04:00:54 +11:00
|
|
|
LOG.info("Choosing PMS server requested, starting")
|
|
|
|
transfer.plex_command('choose_pms_server')
|
2017-03-08 20:39:05 +11:00
|
|
|
|
2017-03-08 21:02:25 +11:00
|
|
|
elif mode == 'deviceid':
|
2021-11-03 17:43:44 +11:00
|
|
|
LOG.info('New PKC UUID / unique device id requested')
|
|
|
|
transfer.plex_command('generate_new_uuid')
|
2017-03-08 20:39:05 +11:00
|
|
|
|
|
|
|
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':
|
2019-01-09 04:00:54 +11:00
|
|
|
entrypoint.hub(params.get('content_type'))
|
2018-07-28 00:01:05 +10:00
|
|
|
|
2019-02-08 06:15:49 +11:00
|
|
|
elif mode == 'select-libraries':
|
|
|
|
LOG.info('User requested to select Plex libraries')
|
|
|
|
transfer.plex_command('select-libraries')
|
|
|
|
|
2019-04-14 22:20:03 +10:00
|
|
|
elif mode == 'refreshplaylist':
|
|
|
|
LOG.info('User requested to refresh Kodi playlists and nodes')
|
|
|
|
transfer.plex_command('refreshplaylist')
|
|
|
|
|
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
|
|
|
|
"""
|
2021-12-06 00:27:52 +11:00
|
|
|
request = '%s&handle=%s' % (argv[2], int(argv[1]))
|
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)
|
2021-12-06 00:27:52 +11:00
|
|
|
if int(argv[1]) == -1:
|
2018-04-16 02:13:48 +10:00
|
|
|
# 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
|
2019-05-30 22:24:18 +10:00
|
|
|
result = transfer.wait_for_transfer(source='main')
|
|
|
|
if result is True:
|
2021-12-06 00:27:52 +11:00
|
|
|
xbmcplugin.setResolvedUrl(int(argv[1]), False, xbmcgui.ListItem())
|
2019-05-30 22:24:18 +10:00
|
|
|
# Tell main thread that we're done
|
|
|
|
transfer.send(True, target='main')
|
2019-01-26 18:43:51 +11:00
|
|
|
else:
|
|
|
|
# Received a xbmcgui.ListItem()
|
2021-12-06 00:27:52 +11:00
|
|
|
xbmcplugin.setResolvedUrl(int(argv[1]), True, result)
|
2017-03-08 20:39:05 +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)
|