From 133482001c81ceb40442236fe3b2f897e1290f8c Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Tue, 19 Apr 2016 15:20:03 +0200 Subject: [PATCH] Revert "Fixes to listitem setup" This reverts commit f2dd8617f3b861f04e4b6b61f5d5e620d04f364f. --- resources/lib/PlexAPI.py | 66 ++++++++++--------------------------- resources/lib/entrypoint.py | 50 +++++++++------------------- 2 files changed, 33 insertions(+), 83 deletions(-) diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index a9727f3d..f66a9953 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -37,7 +37,6 @@ import xml.etree.ElementTree as etree import re import json from urllib import urlencode, quote_plus, unquote -import requests import xbmcaddon import xbmcgui @@ -47,7 +46,7 @@ import xbmcvfs import clientinfo import utils import downloadutils -import embydb_functions as embydb +import requests from PlexFunctions import PlexToKodiTimefactor, PMSHttpsEnabled @@ -2146,31 +2145,13 @@ class API(): Returns XBMC listitem for this PMS library item """ + people = self.getPeople() + userdata = self.getUserData() title, sorttitle = self.getTitle() if listItem is None: - listItem = xbmcgui.ListItem(title) - else: - listItem.setLabel(title) + listItem = xbmcgui.ListItem() - listItem.setProperty('IsPlayable', 'true') - listItem.setProperty('IsFolder', 'false') - - typus = self.getType() - if typus == 'movie': - listItem.setProperty('DBTYPE', 'movie') - elif typus == 'episode': - listItem.setProperty('DBTYPE', 'episode') - - with embydb.GetEmbyDB() as emby_db: - try: - dbid = emby_db.getItem_byId(self.getRatingKey())[0] - listItem.setProperty('dbid', str(dbid)) - except TypeError: - pass - self.logMsg('ratingKey: %s, dbid: %s' % (self.getRatingKey(), str(dbid))) - people = self.getPeople() - userdata = self.getUserData() metadata = { 'genre': self.joinList(self.getGenres()), 'year': self.getYear(), @@ -2179,6 +2160,7 @@ class API(): 'cast': people['Cast'], 'director': self.joinList(people.get('Director')), 'plot': self.getPlot(), + 'title': title, 'sorttitle': sorttitle, 'duration': userdata['Runtime'], 'studio': self.joinList(self.getStudios()), @@ -2190,38 +2172,24 @@ class API(): 'mpaa': self.getMpaa(), 'aired': self.getPremiereDate() } - - if userdata['Resume'] > 0: - listItem.setProperty('resumetime', str(userdata['Resume'])) - if userdata['Runtime'] > 0: - listItem.setProperty('totaltime', str(userdata['Runtime'])) + try: + PercentPlayed = userdata['Resume'] / userdata['Runtime'] * 100.0 + except ZeroDivisionError: + PercentPlayed = 0.0 + if PercentPlayed > 0: + metadata['PercentPlayed'] = PercentPlayed if self.getType() == "episode": # Only for tv shows key, show, season, episode = self.getEpisodeDetails() - metadata['episode'] = int(episode) - metadata['season'] = int(season) + metadata['episode'] = episode + metadata['season'] = season metadata['tvshowtitle'] = show - try: - listItem.setProperty('episodeno', "s%.2de%.2d" - % (int(season), int(episode))) - except: - pass - listItem.setIconImage('DefaultTVShows.png') - elif self.getType() == "movie": - listItem.setIconImage('DefaultMovies.png') - elif self.getType() == "clip": - listItem.setIconImage('DefaultVideo.png') - artwork = self.getAllArtwork() - if artwork.get('Primary'): - listItem.setThumbnailImage(artwork.get('Primary')) - elif self.getType() == "movie": - listItem.setThumbnailImage('DefaultMovies.png') - elif self.getType() == "episode": - listItem.setThumbnailImage('DefaultTVShows.png') - - # Very resource intensive + listItem.setProperty('IsPlayable', 'true') + listItem.setProperty('IsFolder', 'false') + listItem.setProperty('embyid', self.getRatingKey()) + listItem.setLabel(title) listItem.setInfo('video', infoLabels=metadata) return listItem diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index cc7123ae..b7c2d9d3 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -1031,7 +1031,6 @@ def createListItem(item): li.setIconImage('DefaultTVShows.png') li.setProperty('dbid', str(item['episodeid'])) li.setProperty('fanart_image', item['art'].get('tvshow.fanart','')) - li.setLabel(title) for key, value in item['streamdetails'].iteritems(): for stream in value: li.addStreamInfo(key, stream) @@ -1492,12 +1491,6 @@ def getOnDeck(viewid, mediatype, tagname, limit): if counter >= 300: break xbmc.sleep(100) - # Wait till full lib sync done - while utils.window('emby_dbScan') == '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): @@ -1506,34 +1499,23 @@ def getOnDeck(viewid, mediatype, tagname, limit): params = { 'mode': "play" } - counter = 0 - for item in xml: - counter += 1 - if counter > 1: - break - API = PlexAPI.API(item) - listitem = API.CreateListItemFromPlexItem() - pbutils.PlaybackUtils(item).setArtwork(listitem) - API.AddStreamInfo(listitem) - plexID = API.getRatingKey() - with embydb.GetEmbyDB() as emby_db: + 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 - path = "%s?%s" % (url, urllib.urlencode(params)) - listitem.setProperty('path', path) - listitem.setProperty('file', path) - listitem.setProperty('FileNameAndPath', path) - props = ('dbid', 'DBTYPE', 'path',) - for thing in props: - utils.logMsg('%s: %s' % (thing, listitem.getProperty(thing)), 1) - xbmcplugin.addDirectoryItem( - handle=int(sys.argv[1]), - url=path, - listitem=listitem) + 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' @@ -1628,7 +1610,7 @@ def getOnDeck(viewid, mediatype, tagname, limit): continue for episode in episodes: # There will always be only 1 episode ('limit=1') - listitem = createListItem(episode) + li = createListItem(episode) # Fix some skin shortcomings title = episode.get('title', '') if utils.settings('OnDeckTvAppendSeason') == 'true': @@ -1641,11 +1623,11 @@ def getOnDeck(viewid, mediatype, tagname, limit): show = episode.get('showtitle') if show: title = show + ' - ' + title - listitem.setLabel(title) + li.setLabel(title) xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=episode['file'], - listitem=listitem, + listitem=li, isFolder=False) count += 1