Fixes to listitem setup

This commit is contained in:
tomkat83 2016-04-19 11:18:55 +02:00
parent 6f5f73ae86
commit f2dd8617f3
2 changed files with 83 additions and 33 deletions

View file

@ -37,6 +37,7 @@ import xml.etree.ElementTree as etree
import re
import json
from urllib import urlencode, quote_plus, unquote
import requests
import xbmcaddon
import xbmcgui
@ -46,7 +47,7 @@ import xbmcvfs
import clientinfo
import utils
import downloadutils
import requests
import embydb_functions as embydb
from PlexFunctions import PlexToKodiTimefactor, PMSHttpsEnabled
@ -2145,13 +2146,31 @@ 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()
listItem = xbmcgui.ListItem(title)
else:
listItem.setLabel(title)
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(),
@ -2160,7 +2179,6 @@ 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()),
@ -2172,24 +2190,38 @@ class API():
'mpaa': self.getMpaa(),
'aired': self.getPremiereDate()
}
try:
PercentPlayed = userdata['Resume'] / userdata['Runtime'] * 100.0
except ZeroDivisionError:
PercentPlayed = 0.0
if PercentPlayed > 0:
metadata['PercentPlayed'] = PercentPlayed
if userdata['Resume'] > 0:
listItem.setProperty('resumetime', str(userdata['Resume']))
if userdata['Runtime'] > 0:
listItem.setProperty('totaltime', str(userdata['Runtime']))
if self.getType() == "episode":
# Only for tv shows
key, show, season, episode = self.getEpisodeDetails()
metadata['episode'] = episode
metadata['season'] = season
metadata['episode'] = int(episode)
metadata['season'] = int(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')
listItem.setProperty('IsPlayable', 'true')
listItem.setProperty('IsFolder', 'false')
listItem.setProperty('embyid', self.getRatingKey())
listItem.setLabel(title)
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.setInfo('video', infoLabels=metadata)
return listItem

View file

@ -1031,6 +1031,7 @@ 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)
@ -1491,6 +1492,12 @@ 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):
@ -1499,23 +1506,34 @@ def getOnDeck(viewid, mediatype, tagname, limit):
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()
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:
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)
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)
return xbmcplugin.endOfDirectory(
handle=int(sys.argv[1]),
cacheToDisc=True if utils.settings('enableTextureCache') == 'true'
@ -1610,7 +1628,7 @@ def getOnDeck(viewid, mediatype, tagname, limit):
continue
for episode in episodes:
# There will always be only 1 episode ('limit=1')
li = createListItem(episode)
listitem = createListItem(episode)
# Fix some skin shortcomings
title = episode.get('title', '')
if utils.settings('OnDeckTvAppendSeason') == 'true':
@ -1623,11 +1641,11 @@ def getOnDeck(viewid, mediatype, tagname, limit):
show = episode.get('showtitle')
if show:
title = show + ' - ' + title
li.setLabel(title)
listitem.setLabel(title)
xbmcplugin.addDirectoryItem(
handle=int(sys.argv[1]),
url=episode['file'],
listitem=li,
listitem=listitem,
isFolder=False)
count += 1