Merge branch 'hotfixes' of https://github.com/croneter/PlexKodiConnect into hotfixes

This commit is contained in:
croneter 2017-09-13 15:32:49 +02:00
commit 02ba51bc15
7 changed files with 68 additions and 64 deletions

View file

@ -1,52 +1,41 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################### ###############################################################################
from os import path as os_path
from sys import path as sys_path
import logging from xbmcaddon import Addon
import os from xbmc import translatePath, sleep, log, LOGERROR
import sys from xbmcgui import Window
import xbmc _addon = Addon(id='plugin.video.plexkodiconnect')
import xbmcaddon
###############################################################################
_addon = xbmcaddon.Addon(id='plugin.video.plexkodiconnect')
try: try:
_addon_path = _addon.getAddonInfo('path').decode('utf-8') _addon_path = _addon.getAddonInfo('path').decode('utf-8')
except TypeError: except TypeError:
_addon_path = _addon.getAddonInfo('path').decode() _addon_path = _addon.getAddonInfo('path').decode()
try: try:
_base_resource = xbmc.translatePath(os.path.join( _base_resource = translatePath(os_path.join(
_addon_path, _addon_path,
'resources', 'resources',
'lib')).decode('utf-8') 'lib')).decode('utf-8')
except TypeError: except TypeError:
_base_resource = xbmc.translatePath(os.path.join( _base_resource = translatePath(os_path.join(
_addon_path, _addon_path,
'resources', 'resources',
'lib')).decode() 'lib')).decode()
sys.path.append(_base_resource) sys_path.append(_base_resource)
############################################################################### from pickler import unpickle_me, pickl_window
import loghandler
from context_entry import ContextMenu
###############################################################################
loghandler.config()
log = logging.getLogger("PLEX.contextmenu")
############################################################################### ###############################################################################
if __name__ == "__main__": if __name__ == "__main__":
win = Window(10000)
try: while win.getProperty('plex_command'):
# Start the context menu sleep(20)
ContextMenu() win.setProperty('plex_command', 'CONTEXT_menu')
except Exception as error: while not pickl_window('plex_result'):
log.error(error) sleep(50)
import traceback result = unpickle_me()
log.error("Traceback:\n%s" % traceback.format_exc()) if result is None:
raise log('PLEX.%s: Error encountered, aborting' % __name__, level=LOGERROR)

View file

@ -32,9 +32,9 @@ sys_path.append(_base_resource)
############################################################################### ###############################################################################
import entrypoint import entrypoint
from utils import window, pickl_window, reset, passwordsXML, language as lang,\ from utils import window, reset, passwordsXML, language as lang, dialog, \
dialog, plex_command plex_command
from pickler import unpickle_me from pickler import unpickle_me, pickl_window
from PKC_listitem import convert_PKC_to_listitem from PKC_listitem import convert_PKC_to_listitem
import variables as v import variables as v

View file

@ -62,6 +62,8 @@ class Monitor_Window(Thread):
value.replace('PLEX_USERNAME-', '') or None value.replace('PLEX_USERNAME-', '') or None
elif value.startswith('RUN_LIB_SCAN-'): elif value.startswith('RUN_LIB_SCAN-'):
state.RUN_LIB_SCAN = value.replace('RUN_LIB_SCAN-', '') state.RUN_LIB_SCAN = value.replace('RUN_LIB_SCAN-', '')
elif value == 'CONTEXT_menu':
queue.put('dummy?mode=context_menu')
else: else:
raise NotImplementedError('%s not implemented' % value) raise NotImplementedError('%s not implemented' % value)
else: else:

View file

@ -2,8 +2,6 @@
############################################################################### ###############################################################################
import logging import logging
import xbmc import xbmc
from utils import tryEncode
############################################################################### ###############################################################################
LEVELS = { LEVELS = {
logging.ERROR: xbmc.LOGERROR, logging.ERROR: xbmc.LOGERROR,
@ -14,6 +12,22 @@ LEVELS = {
############################################################################### ###############################################################################
def tryEncode(uniString, encoding='utf-8'):
"""
Will try to encode uniString (in unicode) to encoding. This possibly
fails with e.g. Android TV's Python, which does not accept arguments for
string.encode()
"""
if isinstance(uniString, str):
# already encoded
return uniString
try:
uniString = uniString.encode(encoding, "ignore")
except TypeError:
uniString = uniString.encode()
return uniString
def config(): def config():
logger = logging.getLogger('PLEX') logger = logging.getLogger('PLEX')
logger.addHandler(LogHandler()) logger.addHandler(LogHandler())

View file

@ -1,13 +1,26 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################### ###############################################################################
import logging from cPickle import dumps, loads
import cPickle as Pickle
from utils import pickl_window from xbmcgui import Window
from xbmc import log, LOGDEBUG
###############################################################################
WINDOW = Window(10000)
PREFIX = 'PLEX.%s: ' % __name__
############################################################################### ###############################################################################
log = logging.getLogger("PLEX."+__name__)
###############################################################################
def pickl_window(property, value=None, clear=False):
"""
Get or set window property - thread safe! For use with Pickle
Property and value must be string
"""
if clear:
WINDOW.clearProperty(property)
elif value is not None:
WINDOW.setProperty(property, value)
else:
return WINDOW.getProperty(property)
def pickle_me(obj, window_var='plex_result'): def pickle_me(obj, window_var='plex_result'):
@ -19,9 +32,9 @@ def pickle_me(obj, window_var='plex_result'):
obj can be pretty much any Python object. However, classes and obj can be pretty much any Python object. However, classes and
functions won't work. See the Pickle documentation functions won't work. See the Pickle documentation
""" """
log.debug('Start pickling: %s' % obj) log('%sStart pickling: %s' % (PREFIX, obj), level=LOGDEBUG)
pickl_window(window_var, value=Pickle.dumps(obj)) pickl_window(window_var, value=dumps(obj))
log.debug('Successfully pickled') log('%sSuccessfully pickled' % PREFIX, level=LOGDEBUG)
def unpickle_me(window_var='plex_result'): def unpickle_me(window_var='plex_result'):
@ -31,9 +44,9 @@ def unpickle_me(window_var='plex_result'):
""" """
result = pickl_window(window_var) result = pickl_window(window_var)
pickl_window(window_var, clear=True) pickl_window(window_var, clear=True)
log.debug('Start unpickling') log('%sStart unpickling' % PREFIX, level=LOGDEBUG)
obj = Pickle.loads(result) obj = loads(result)
log.debug('Successfully unpickled: %s' % obj) log('%sSuccessfully unpickled: %s' % (PREFIX, obj), level=LOGDEBUG)
return obj return obj

View file

@ -17,6 +17,7 @@ import variables as v
from downloadutils import DownloadUtils from downloadutils import DownloadUtils
from PKC_listitem import convert_PKC_to_listitem from PKC_listitem import convert_PKC_to_listitem
import plexdb_functions as plexdb import plexdb_functions as plexdb
from context_entry import ContextMenu
import state import state
############################################################################### ###############################################################################
@ -142,6 +143,9 @@ class Playback_Starter(Thread):
params.get('view_offset'), params.get('view_offset'),
directplay=True if params.get('play_directly') else False, directplay=True if params.get('play_directly') else False,
node=False if params.get('node') == 'false' else True) node=False if params.get('node') == 'false' else True)
elif mode == 'context_menu':
ContextMenu()
result = Playback_Successful()
except: except:
log.error('Error encountered for mode %s, params %s' log.error('Error encountered for mode %s, params %s'
% (mode, params)) % (mode, params))

View file

@ -59,24 +59,6 @@ def window(property, value=None, clear=False, windowid=10000):
return tryDecode(win.getProperty(property)) return tryDecode(win.getProperty(property))
def pickl_window(property, value=None, clear=False, windowid=10000):
"""
Get or set window property - thread safe! For use with Pickle
Property and value must be string
"""
if windowid != 10000:
win = xbmcgui.Window(windowid)
else:
win = WINDOW
if clear:
win.clearProperty(property)
elif value is not None:
win.setProperty(property, value)
else:
return win.getProperty(property)
def plex_command(key, value): def plex_command(key, value):
""" """
Used to funnel states between different Python instances. NOT really thread Used to funnel states between different Python instances. NOT really thread