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

View file

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

View file

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

View file

@ -2,8 +2,6 @@
###############################################################################
import logging
import xbmc
from utils import tryEncode
###############################################################################
LEVELS = {
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():
logger = logging.getLogger('PLEX')
logger.addHandler(LogHandler())

View file

@ -1,13 +1,26 @@
# -*- coding: utf-8 -*-
###############################################################################
import logging
import cPickle as Pickle
from cPickle import dumps, loads
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'):
@ -19,9 +32,9 @@ def pickle_me(obj, window_var='plex_result'):
obj can be pretty much any Python object. However, classes and
functions won't work. See the Pickle documentation
"""
log.debug('Start pickling: %s' % obj)
pickl_window(window_var, value=Pickle.dumps(obj))
log.debug('Successfully pickled')
log('%sStart pickling: %s' % (PREFIX, obj), level=LOGDEBUG)
pickl_window(window_var, value=dumps(obj))
log('%sSuccessfully pickled' % PREFIX, level=LOGDEBUG)
def unpickle_me(window_var='plex_result'):
@ -31,9 +44,9 @@ def unpickle_me(window_var='plex_result'):
"""
result = pickl_window(window_var)
pickl_window(window_var, clear=True)
log.debug('Start unpickling')
obj = Pickle.loads(result)
log.debug('Successfully unpickled: %s' % obj)
log('%sStart unpickling' % PREFIX, level=LOGDEBUG)
obj = loads(result)
log('%sSuccessfully unpickled: %s' % (PREFIX, obj), level=LOGDEBUG)
return obj

View file

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

View file

@ -59,24 +59,6 @@ def window(property, value=None, clear=False, windowid=10000):
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):
"""
Used to funnel states between different Python instances. NOT really thread