Access Plex Hubs. Listing will be different depending on Kodi section!

This commit is contained in:
croneter 2018-07-27 16:01:05 +02:00
parent 04725a8aca
commit 5968e845d2
4 changed files with 62 additions and 12 deletions

View file

@ -139,6 +139,9 @@ class Main():
elif mode == 'playlists':
entrypoint.playlists(params.get('type'))
elif mode == 'hub':
entrypoint.hub(params.get('type'))
else:
entrypoint.show_main_menu(content_type=params.get('content_type'))

View file

@ -152,7 +152,9 @@ def show_main_menu(content_type=None):
'homevideos',
'musicvideos') and content_type == 'video':
directory_item(label, path)
# Plex Hub
directory_item('Plex Hub',
'plugin://%s?mode=hub&type=%s' % (v.ADDON_ID, content_type))
# Plex Watch later
if content_type not in ('image', 'audio'):
directory_item(utils.lang(39211),
@ -707,6 +709,31 @@ def playlists(plex_playlist_type):
cacheToDisc=utils.settings('enableTextureCache') == 'true')
def hub(content_type):
"""
Plus hub endpoint pms:port/hubs. Need to separate Kodi types with
content_type:
audio, video, image
"""
xml = PF.get_plex_hub()
try:
xml.attrib
except AttributeError:
LOG.error('Could not get Plex hub listing')
return xbmcplugin.endOfDirectory(int(argv[1]), False)
for entry in xml:
api = API(entry)
if content_type == 'video' and api.plex_type() in v.PLEX_VIDEOTYPES:
__build_folder(entry)
elif content_type == 'audio' and api.plex_type() in v.PLEX_AUDIOTYPES:
__build_folder(entry)
elif content_type == 'image' and api.plex_type() == v.PLEX_TYPE_PHOTO:
__build_folder(entry)
xbmcplugin.endOfDirectory(
handle=int(argv[1]),
cacheToDisc=utils.settings('enableTextureCache') == 'true')
def watchlater():
"""
Listing for plex.tv Watch Later section (if signed in to plex.tv)
@ -768,8 +795,8 @@ def browse_plex(key=None, plex_section_id=None):
else:
xml = PF.GetPlexSectionResults(plex_section_id)
try:
xml[0].attrib
except (ValueError, AttributeError, IndexError, TypeError):
xml.attrib
except AttributeError:
LOG.error('Could not browse to key %s, section %s',
key, plex_section_id)
return xbmcplugin.endOfDirectory(int(argv[1]), False)
@ -866,17 +893,22 @@ def browse_plex(key=None, plex_section_id=None):
def __build_folder(xml_element, plex_section_id=None):
url = "plugin://%s/" % v.ADDON_ID
key = xml_element.attrib.get('fastKey', xml_element.attrib.get('key'))
key = xml_element.get('fastKey', xml_element.get('key'))
if not key.startswith('/'):
key = '/library/sections/%s/%s' % (plex_section_id, key)
params = {
'mode': "browseplex",
'key': key,
'id': plex_section_id
}
listitem = ListItem(xml_element.attrib.get('title'))
listitem.setArt({'thumb': xml_element.attrib.get('thumb'),
'poster': xml_element.attrib.get('art')})
if plex_section_id:
params['id'] = plex_section_id
listitem = ListItem(xml_element.get('title'))
thumb = xml_element.get('thumb') or \
'special://home/addons/%s/icon.png' % v.ADDON_ID
art = xml_element.get('art') or \
'special://home/addons/%s/fanart.jpg' % v.ADDON_ID
listitem.setThumbnailImage(thumb)
listitem.setArt({'fanart': art, 'landscape': art})
xbmcplugin.addDirectoryItem(handle=int(argv[1]),
url="%s?%s" % (url, urlencode(params)),
isFolder=True,

View file

@ -611,6 +611,10 @@ def GetPlexOnDeck(viewId):
return DownloadChunks("{server}/library/sections/%s/onDeck?" % viewId)
def get_plex_hub():
return DU().downloadUrl('{server}/hubs')
def get_plex_sections():
"""
Returns all Plex sections (libraries) of the PMS as an etree xml

View file

@ -146,6 +146,7 @@ PLEX_TYPE_VIDEO = 'video'
PLEX_TYPE_MOVIE = 'movie'
PLEX_TYPE_CLIP = 'clip' # e.g. trailers
PLEX_TYPE_SET = 'collection' # sets/collections
PLEX_TYPE_MIXED = 'mixed'
PLEX_TYPE_EPISODE = 'episode'
PLEX_TYPE_SEASON = 'season'
@ -198,15 +199,19 @@ KODI_VIDEOTYPES = (
KODI_TYPE_SHOW,
KODI_TYPE_SEASON,
KODI_TYPE_EPISODE,
KODI_TYPE_SET
KODI_TYPE_SET,
KODI_TYPE_CLIP
)
PLEX_VIDEOTYPES = (
PLEX_TYPE_VIDEO,
PLEX_TYPE_MOVIE,
PLEX_TYPE_CLIP,
PLEX_TYPE_EPISODE,
PLEX_TYPE_SHOW,
PLEX_TYPE_SEASON,
PLEX_TYPE_SHOW
PLEX_TYPE_EPISODE,
PLEX_TYPE_SET,
PLEX_TYPE_CLIP,
PLEX_TYPE_MIXED, # MIXED SEEMS TO ALWAYS REFER TO VIDEO!
)
KODI_AUDIOTYPES = (
@ -215,6 +220,12 @@ KODI_AUDIOTYPES = (
KODI_TYPE_ARTIST,
)
PLEX_AUDIOTYPES = (
PLEX_TYPE_SONG,
PLEX_TYPE_ALBUM,
PLEX_TYPE_ARTIST,
)
# Translation tables
ADDON_TYPE = {