Optimize context menu
This commit is contained in:
parent
9e2ff58bc7
commit
4df5851bc0
4 changed files with 34 additions and 57 deletions
|
@ -1,41 +1,36 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
from os import path as os_path
|
from sys import listitem
|
||||||
from sys import path as sys_path
|
from urllib import urlencode
|
||||||
|
|
||||||
from xbmcaddon import Addon
|
from xbmc import getCondVisibility, sleep
|
||||||
from xbmc import translatePath, sleep, log, LOGERROR
|
|
||||||
from xbmcgui import Window
|
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__":
|
if __name__ == "__main__":
|
||||||
WINDOW = Window(10000)
|
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'):
|
while WINDOW.getProperty('plex_command'):
|
||||||
sleep(20)
|
sleep(20)
|
||||||
WINDOW.setProperty('plex_command', 'CONTEXT_menu')
|
WINDOW.setProperty('plex_command', 'CONTEXT_menu?%s' % urlencode(ARGS))
|
||||||
while not pickl_window('plex_result'):
|
|
||||||
sleep(50)
|
|
||||||
RESULT = unpickle_me()
|
|
||||||
if RESULT is None:
|
|
||||||
log('PLEX.%s: Error encountered, aborting' % __name__, level=LOGERROR)
|
|
||||||
|
|
|
@ -54,8 +54,9 @@ 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':
|
elif value.startswith('CONTEXT_menu?'):
|
||||||
queue.put('dummy?mode=context_menu')
|
queue.put('dummy?mode=context_menu&%s'
|
||||||
|
% value.replace('CONTEXT_menu?', ''))
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError('%s not implemented' % value)
|
raise NotImplementedError('%s not implemented' % value)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -38,12 +38,12 @@ class ContextMenu(object):
|
||||||
"""
|
"""
|
||||||
_selected_option = None
|
_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
|
Simply instantiate with ContextMenu() - no need to call any methods
|
||||||
"""
|
"""
|
||||||
self.kodi_id = getInfoLabel('ListItem.DBID').decode('utf-8')
|
self.kodi_id = kodi_id
|
||||||
self.kodi_type = self._get_kodi_type()
|
self.kodi_type = kodi_type
|
||||||
self.plex_id = self._get_plex_id(self.kodi_id, self.kodi_type)
|
self.plex_id = self._get_plex_id(self.kodi_id, self.kodi_type)
|
||||||
if self.kodi_type:
|
if self.kodi_type:
|
||||||
self.plex_type = v.PLEX_TYPE_FROM_KODI_TYPE[self.kodi_type]
|
self.plex_type = v.PLEX_TYPE_FROM_KODI_TYPE[self.kodi_type]
|
||||||
|
@ -61,23 +61,6 @@ class ContextMenu(object):
|
||||||
sleep(500)
|
sleep(500)
|
||||||
executebuiltin('Container.Refresh')
|
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
|
@staticmethod
|
||||||
def _get_plex_id(kodi_id, kodi_type):
|
def _get_plex_id(kodi_id, kodi_type):
|
||||||
plex_id = getInfoLabel('ListItem.Property(plexid)') or None
|
plex_id = getInfoLabel('ListItem.Property(plexid)') or None
|
||||||
|
|
|
@ -32,11 +32,9 @@ class Playback_Starter(Thread):
|
||||||
elif mode == 'plex_node':
|
elif mode == 'plex_node':
|
||||||
playback.process_indirect(params['key'], params['offset'])
|
playback.process_indirect(params['key'], params['offset'])
|
||||||
elif mode == 'context_menu':
|
elif mode == 'context_menu':
|
||||||
ContextMenu()
|
ContextMenu(kodi_id=params['kodi_id'],
|
||||||
result = Playback_Successful()
|
kodi_type=params['kodi_type'])
|
||||||
# Let default.py know!
|
|
||||||
pickle_me(result)
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
queue = state.COMMAND_PIPELINE_QUEUE
|
queue = state.COMMAND_PIPELINE_QUEUE
|
||||||
LOG.info("----===## Starting Playback_Starter ##===----")
|
LOG.info("----===## Starting Playback_Starter ##===----")
|
||||||
|
|
Loading…
Reference in a new issue