Plex Channels!

This commit is contained in:
tomkat83 2017-03-07 16:37:36 +01:00
parent 31e51483e4
commit 47ea9f2968
2 changed files with 94 additions and 5 deletions

View file

@ -102,9 +102,11 @@ class Main():
'ondeck': entrypoint.getOnDeck,
'chooseServer': entrypoint.chooseServer,
'watchlater': entrypoint.watchlater,
'channels': entrypoint.channels,
'enterPMS': entrypoint.enterPMS,
'togglePlexTV': entrypoint.togglePlexTV,
'Plex_Node': entrypoint.Plex_Node
'Plex_Node': entrypoint.Plex_Node,
'browse_plex_folder': entrypoint.browse_plex_folder
}
if "/extrafanart" in argv[0]:
@ -134,10 +136,10 @@ class Main():
elif mode in ("nextup", "inprogressepisodes"):
limit = int(params['limit'])
modes[mode](params['tagname'], limit)
elif mode in ("channels","getsubfolders"):
elif mode in ("getsubfolders"):
modes[mode](itemid)
elif mode == "browsecontent":
modes[mode](itemid, params.get('type'), params.get('folderid'))
@ -162,6 +164,8 @@ class Main():
elif mode == 'Plex_Node':
modes[mode](params.get('id'),
params.get('viewOffset'))
elif mode == 'browse_plex_folder':
modes[mode](params.get('id'))
else:
modes[mode]()
else:

View file

@ -106,7 +106,10 @@ def Plex_Node(url, viewOffset, playdirectly=False, node=True):
log.info('Plex_Node called with url: %s, viewOffset: %s'
% (url, viewOffset))
# Plex redirect, e.g. watch later. Need to get actual URLs
xml = downloadutils.DownloadUtils().downloadUrl(url)
if url.startswith('http'):
xml = downloadutils.DownloadUtils().downloadUrl(url)
else:
xml = downloadutils.DownloadUtils().downloadUrl('{server}%s' % url)
try:
xml[0].attrib
except:
@ -194,6 +197,9 @@ def doMainListing():
# Plex Watch later
addDirectoryItem(lang(39211),
"plugin://plugin.video.plexkodiconnect/?mode=watchlater")
# Plex Channels
addDirectoryItem(lang(30173),
"plugin://plugin.video.plexkodiconnect/?mode=channels")
# Plex user switch
addDirectoryItem(lang(39200) + window('plex_username'),
"plugin://plugin.video.plexkodiconnect/"
@ -927,6 +933,85 @@ def watchlater():
cacheToDisc=settings('enableTextureCache') == 'true')
def channels():
"""
Listing for Plex Channels
"""
if window('plex_restricteduser') == 'true':
log.error('No Plex Channels - restricted user')
return xbmcplugin.endOfDirectory(HANDLE, False)
xml = downloadutils.DownloadUtils().downloadUrl('{server}/channels/all')
try:
xml[0].attrib
except (ValueError, AttributeError, IndexError):
log.error('Could not download Plex Channels')
return xbmcplugin.endOfDirectory(HANDLE, False)
log.info('Displaying Plex Channels')
xbmcplugin.setContent(HANDLE, 'files')
for item in xml:
__build_folder(item)
xbmcplugin.endOfDirectory(
handle=HANDLE,
cacheToDisc=settings('enableTextureCache') == 'true')
def browse_plex_folder(key):
"""
Lists the content of a Plex folder, e.g. channels
"""
xml = downloadutils.DownloadUtils().downloadUrl('{server}%s' % key)
try:
xml[0].attrib
except (ValueError, AttributeError, IndexError):
log.error('Could not browse to %s' % key)
return xbmcplugin.endOfDirectory(HANDLE, False)
xbmcplugin.setContent(HANDLE, 'files')
for item in xml:
if item.tag == 'Directory':
__build_folder(item)
else:
__build_item(item)
xbmcplugin.endOfDirectory(
handle=HANDLE,
cacheToDisc=settings('enableTextureCache') == 'true')
def __build_folder(xml_element):
url = "plugin://plugin.video.plexkodiconnect/"
params = {
'mode': "browse_plex_folder",
'id': xml_element.attrib.get('key')
}
listitem = ListItem(xml_element.attrib.get('title'))
listitem.setArt({'thumb': xml_element.attrib.get('thumb'),
'poster': xml_element.attrib.get('art')})
xbmcplugin.addDirectoryItem(
handle=HANDLE,
url="%s?%s" % (url, urlencode(params)),
isFolder=True,
listitem=listitem)
def __build_item(xml_element):
url = "plugin://plugin.video.plexkodiconnect/"
api = API(xml_element)
listitem = api.CreateListItemFromPlexItem()
api.AddStreamInfo(listitem)
api.set_listitem_artwork(listitem)
params = {
'mode': "Plex_Node",
'id': xml_element.attrib.get('key'),
'viewOffset': xml_element.attrib.get('viewOffset', '0'),
'plex_type': xml_element.attrib.get('type')
}
xbmcplugin.addDirectoryItem(
handle=HANDLE,
url="%s?%s" % (url, urlencode(params)),
listitem=listitem)
def enterPMS():
"""
Opens dialogs for the user the plug in the PMS details