From 49a5f274e682f47de7861652f534666426308324 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Mon, 18 Apr 2016 11:23:05 +0200 Subject: [PATCH] New settings option: default Plex On Deck TV Shows --- resources/language/English/strings.xml | 1 + resources/language/German/strings.xml | 1 + resources/lib/downloadutils.py | 18 ++++++----- resources/lib/entrypoint.py | 41 +++++++++++++++++++++++++- resources/settings.xml | 1 + 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index ba964ae4..e74761ba 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -401,6 +401,7 @@ Searching for Plex Server Used by Sync and when attempting to Direct Play Customize Paths + Extend Plex TV Series "On Deck" view to all shows Log-out Plex Home User diff --git a/resources/language/German/strings.xml b/resources/language/German/strings.xml index 599716e5..c594a66a 100644 --- a/resources/language/German/strings.xml +++ b/resources/language/German/strings.xml @@ -339,6 +339,7 @@ Suche Plex Server Verwendet für Synchronisierung sowie beim Versuch, Direct Play zu nutzen Pfade ändern + Standard Plex Ansicht "Aktuell" auf alle TV Shows erweitern diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 9bbe26e6..402395a2 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -322,10 +322,14 @@ class DownloadUtils(): # And now deal with the consequences of the exceptions if authenticate is True: # Make the addon aware of status - window('countError', - value=str(int(window('countError')) + 1)) - if int(window('countError')) >= self.connectionAttempts: - self.logMsg('Failed to connect to %s too many times. Declare ' - 'PMS dead' % url, -1) - window('emby_online', value="false") - return False + try: + window('countError', + value=str(int(window('countError')) + 1)) + if int(window('countError')) >= self.connectionAttempts: + self.logMsg('Failed to connect to %s too many times. ' + 'Declare PMS dead' % url, -1) + window('emby_online', value="false") + except: + # 'countError' not yet set + pass + return None diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index 840598a5..b7c2d9d3 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -1481,9 +1481,48 @@ def getOnDeck(viewid, mediatype, tagname, limit): tagname: Name of the Plex library, e.g. "My Movies" limit: Max. number of items to retrieve, e.g. 50 """ + xbmcplugin.setContent(int(sys.argv[1]), 'episodes') + if utils.settings('OnDeckTVextended') == 'false': + # Chances are that this view is used on Kodi startup + # Wait till we've connected to a PMS. At most 30s + counter = 0 + while utils.window('plex_authenticated') != 'true': + counter += 1 + if counter >= 300: + break + xbmc.sleep(100) + xml = downloadutils.DownloadUtils().downloadUrl( + '{server}/library/sections/%s/onDeck' % viewid) + if xml in (None, 401): + return xbmcplugin.endOfDirectory(int(sys.argv[1])) + url = "plugin://plugin.video.plexkodiconnect.tvshows/" + params = { + 'mode': "play" + } + with embydb.GetEmbyDB() as emby_db: + for item in xml: + API = PlexAPI.API(item) + listitem = API.CreateListItemFromPlexItem() + API.AddStreamInfo(listitem) + pbutils.PlaybackUtils(item).setArtwork(listitem) + plexID = API.getRatingKey() + try: + dbid = emby_db.getItem_byId(plexID)[0] + except TypeError: + dbid = None + params['id'] = plexID + params['dbid'] = dbid + xbmcplugin.addDirectoryItem( + handle=int(sys.argv[1]), + url="%s?%s" % (url, urllib.urlencode(params)), + listitem=listitem) + return xbmcplugin.endOfDirectory( + handle=int(sys.argv[1]), + cacheToDisc=True if utils.settings('enableTextureCache') == 'true' + else False) + # if the addon is called with nextup parameter, # we return the nextepisodes list of the given tagname - xbmcplugin.setContent(int(sys.argv[1]), 'episodes') # First we get a list of all the TV shows - filtered by tag query = { 'jsonrpc': "2.0", diff --git a/resources/settings.xml b/resources/settings.xml index 964fca42..8e8d35ae 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -128,6 +128,7 @@ +