diff --git a/contextmenu.py b/contextmenu.py index 138ad83a..c763e586 100644 --- a/contextmenu.py +++ b/contextmenu.py @@ -1,41 +1,36 @@ # -*- coding: utf-8 -*- - ############################################################################### -from os import path as os_path -from sys import path as sys_path +from sys import listitem +from urllib import urlencode -from xbmcaddon import Addon -from xbmc import translatePath, sleep, log, LOGERROR +from xbmc import getCondVisibility, sleep from xbmcgui import Window -_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 = translatePath(os_path.join( - _ADDON_PATH, - 'resources', - 'lib')).decode('utf-8') -except TypeError: - _BASE_RESOURCE = translatePath(os_path.join( - _ADDON_PATH, - 'resources', - 'lib')).decode() -sys_path.append(_BASE_RESOURCE) - -from pickler import unpickle_me, pickl_window - ############################################################################### + +def _get_kodi_type(): + kodi_type = listitem.getVideoInfoTag().getMediaType().decode('utf-8') + if not kodi_type: + if getCondVisibility('Container.Content(albums)'): + kodi_type = "album" + elif getCondVisibility('Container.Content(artists)'): + kodi_type = "artist" + elif getCondVisibility('Container.Content(songs)'): + kodi_type = "song" + elif getCondVisibility('Container.Content(pictures)'): + kodi_type = "picture" + return kodi_type + + if __name__ == "__main__": WINDOW = Window(10000) + KODI_ID = listitem.getVideoInfoTag().getDbId() + KODI_TYPE = _get_kodi_type() + ARGS = { + 'kodi_id': KODI_ID, + 'kodi_type': KODI_TYPE + } while WINDOW.getProperty('plex_command'): sleep(20) - WINDOW.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) + WINDOW.setProperty('plex_command', 'CONTEXT_menu?%s' % urlencode(ARGS)) diff --git a/resources/lib/command_pipeline.py b/resources/lib/command_pipeline.py index 0702313f..64bda2e4 100644 --- a/resources/lib/command_pipeline.py +++ b/resources/lib/command_pipeline.py @@ -54,8 +54,9 @@ 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') + elif value.startswith('CONTEXT_menu?'): + queue.put('dummy?mode=context_menu&%s' + % value.replace('CONTEXT_menu?', '')) else: raise NotImplementedError('%s not implemented' % value) else: diff --git a/resources/lib/context_entry.py b/resources/lib/context_entry.py index 0b1a7e25..96ea0777 100644 --- a/resources/lib/context_entry.py +++ b/resources/lib/context_entry.py @@ -38,12 +38,12 @@ class ContextMenu(object): """ _selected_option = None - def __init__(self): + def __init__(self, kodi_id=None, kodi_type=None): """ Simply instantiate with ContextMenu() - no need to call any methods """ - self.kodi_id = getInfoLabel('ListItem.DBID').decode('utf-8') - self.kodi_type = self._get_kodi_type() + self.kodi_id = kodi_id + self.kodi_type = kodi_type self.plex_id = self._get_plex_id(self.kodi_id, self.kodi_type) if self.kodi_type: self.plex_type = v.PLEX_TYPE_FROM_KODI_TYPE[self.kodi_type] @@ -61,23 +61,6 @@ class ContextMenu(object): sleep(500) executebuiltin('Container.Refresh') - @staticmethod - def _get_kodi_type(): - kodi_type = getInfoLabel('ListItem.DBTYPE').decode('utf-8') - if not kodi_type: - if getCondVisibility('Container.Content(albums)'): - kodi_type = v.KODI_TYPE_ALBUM - elif getCondVisibility('Container.Content(artists)'): - kodi_type = v.KODI_TYPE_ARTIST - elif getCondVisibility('Container.Content(songs)'): - kodi_type = v.KODI_TYPE_SONG - elif getCondVisibility('Container.Content(pictures)'): - kodi_type = v.KODI_TYPE_PHOTO - else: - LOG.info("kodi_type is unknown") - kodi_type = None - return kodi_type - @staticmethod def _get_plex_id(kodi_id, kodi_type): plex_id = getInfoLabel('ListItem.Property(plexid)') or None diff --git a/resources/lib/playback_starter.py b/resources/lib/playback_starter.py index dcc7a59f..ccdca94e 100644 --- a/resources/lib/playback_starter.py +++ b/resources/lib/playback_starter.py @@ -32,11 +32,9 @@ class Playback_Starter(Thread): elif mode == 'plex_node': playback.process_indirect(params['key'], params['offset']) elif mode == 'context_menu': - ContextMenu() - result = Playback_Successful() - # Let default.py know! - pickle_me(result) - + ContextMenu(kodi_id=params['kodi_id'], + kodi_type=params['kodi_type']) + def run(self): queue = state.COMMAND_PIPELINE_QUEUE LOG.info("----===## Starting Playback_Starter ##===----")