Fixes to listitem setup
This commit is contained in:
parent
6f5f73ae86
commit
f2dd8617f3
2 changed files with 83 additions and 33 deletions
|
@ -37,6 +37,7 @@ import xml.etree.ElementTree as etree
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
from urllib import urlencode, quote_plus, unquote
|
from urllib import urlencode, quote_plus, unquote
|
||||||
|
import requests
|
||||||
|
|
||||||
import xbmcaddon
|
import xbmcaddon
|
||||||
import xbmcgui
|
import xbmcgui
|
||||||
|
@ -46,7 +47,7 @@ import xbmcvfs
|
||||||
import clientinfo
|
import clientinfo
|
||||||
import utils
|
import utils
|
||||||
import downloadutils
|
import downloadutils
|
||||||
import requests
|
import embydb_functions as embydb
|
||||||
from PlexFunctions import PlexToKodiTimefactor, PMSHttpsEnabled
|
from PlexFunctions import PlexToKodiTimefactor, PMSHttpsEnabled
|
||||||
|
|
||||||
|
|
||||||
|
@ -2145,13 +2146,31 @@ class API():
|
||||||
|
|
||||||
Returns XBMC listitem for this PMS library item
|
Returns XBMC listitem for this PMS library item
|
||||||
"""
|
"""
|
||||||
people = self.getPeople()
|
|
||||||
userdata = self.getUserData()
|
|
||||||
title, sorttitle = self.getTitle()
|
title, sorttitle = self.getTitle()
|
||||||
|
|
||||||
if listItem is None:
|
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 = {
|
metadata = {
|
||||||
'genre': self.joinList(self.getGenres()),
|
'genre': self.joinList(self.getGenres()),
|
||||||
'year': self.getYear(),
|
'year': self.getYear(),
|
||||||
|
@ -2160,7 +2179,6 @@ class API():
|
||||||
'cast': people['Cast'],
|
'cast': people['Cast'],
|
||||||
'director': self.joinList(people.get('Director')),
|
'director': self.joinList(people.get('Director')),
|
||||||
'plot': self.getPlot(),
|
'plot': self.getPlot(),
|
||||||
'title': title,
|
|
||||||
'sorttitle': sorttitle,
|
'sorttitle': sorttitle,
|
||||||
'duration': userdata['Runtime'],
|
'duration': userdata['Runtime'],
|
||||||
'studio': self.joinList(self.getStudios()),
|
'studio': self.joinList(self.getStudios()),
|
||||||
|
@ -2172,24 +2190,38 @@ class API():
|
||||||
'mpaa': self.getMpaa(),
|
'mpaa': self.getMpaa(),
|
||||||
'aired': self.getPremiereDate()
|
'aired': self.getPremiereDate()
|
||||||
}
|
}
|
||||||
try:
|
|
||||||
PercentPlayed = userdata['Resume'] / userdata['Runtime'] * 100.0
|
if userdata['Resume'] > 0:
|
||||||
except ZeroDivisionError:
|
listItem.setProperty('resumetime', str(userdata['Resume']))
|
||||||
PercentPlayed = 0.0
|
if userdata['Runtime'] > 0:
|
||||||
if PercentPlayed > 0:
|
listItem.setProperty('totaltime', str(userdata['Runtime']))
|
||||||
metadata['PercentPlayed'] = PercentPlayed
|
|
||||||
|
|
||||||
if self.getType() == "episode":
|
if self.getType() == "episode":
|
||||||
# Only for tv shows
|
# Only for tv shows
|
||||||
key, show, season, episode = self.getEpisodeDetails()
|
key, show, season, episode = self.getEpisodeDetails()
|
||||||
metadata['episode'] = episode
|
metadata['episode'] = int(episode)
|
||||||
metadata['season'] = season
|
metadata['season'] = int(season)
|
||||||
metadata['tvshowtitle'] = show
|
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')
|
artwork = self.getAllArtwork()
|
||||||
listItem.setProperty('IsFolder', 'false')
|
if artwork.get('Primary'):
|
||||||
listItem.setProperty('embyid', self.getRatingKey())
|
listItem.setThumbnailImage(artwork.get('Primary'))
|
||||||
listItem.setLabel(title)
|
elif self.getType() == "movie":
|
||||||
|
listItem.setThumbnailImage('DefaultMovies.png')
|
||||||
|
elif self.getType() == "episode":
|
||||||
|
listItem.setThumbnailImage('DefaultTVShows.png')
|
||||||
|
|
||||||
|
# Very resource intensive
|
||||||
listItem.setInfo('video', infoLabels=metadata)
|
listItem.setInfo('video', infoLabels=metadata)
|
||||||
return listItem
|
return listItem
|
||||||
|
|
||||||
|
|
|
@ -1031,6 +1031,7 @@ def createListItem(item):
|
||||||
li.setIconImage('DefaultTVShows.png')
|
li.setIconImage('DefaultTVShows.png')
|
||||||
li.setProperty('dbid', str(item['episodeid']))
|
li.setProperty('dbid', str(item['episodeid']))
|
||||||
li.setProperty('fanart_image', item['art'].get('tvshow.fanart',''))
|
li.setProperty('fanart_image', item['art'].get('tvshow.fanart',''))
|
||||||
|
li.setLabel(title)
|
||||||
for key, value in item['streamdetails'].iteritems():
|
for key, value in item['streamdetails'].iteritems():
|
||||||
for stream in value:
|
for stream in value:
|
||||||
li.addStreamInfo(key, stream)
|
li.addStreamInfo(key, stream)
|
||||||
|
@ -1491,6 +1492,12 @@ def getOnDeck(viewid, mediatype, tagname, limit):
|
||||||
if counter >= 300:
|
if counter >= 300:
|
||||||
break
|
break
|
||||||
xbmc.sleep(100)
|
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(
|
xml = downloadutils.DownloadUtils().downloadUrl(
|
||||||
'{server}/library/sections/%s/onDeck' % viewid)
|
'{server}/library/sections/%s/onDeck' % viewid)
|
||||||
if xml in (None, 401):
|
if xml in (None, 401):
|
||||||
|
@ -1499,22 +1506,33 @@ def getOnDeck(viewid, mediatype, tagname, limit):
|
||||||
params = {
|
params = {
|
||||||
'mode': "play"
|
'mode': "play"
|
||||||
}
|
}
|
||||||
with embydb.GetEmbyDB() as emby_db:
|
counter = 0
|
||||||
for item in xml:
|
for item in xml:
|
||||||
|
counter += 1
|
||||||
|
if counter > 1:
|
||||||
|
break
|
||||||
API = PlexAPI.API(item)
|
API = PlexAPI.API(item)
|
||||||
listitem = API.CreateListItemFromPlexItem()
|
listitem = API.CreateListItemFromPlexItem()
|
||||||
API.AddStreamInfo(listitem)
|
|
||||||
pbutils.PlaybackUtils(item).setArtwork(listitem)
|
pbutils.PlaybackUtils(item).setArtwork(listitem)
|
||||||
|
API.AddStreamInfo(listitem)
|
||||||
plexID = API.getRatingKey()
|
plexID = API.getRatingKey()
|
||||||
|
with embydb.GetEmbyDB() as emby_db:
|
||||||
try:
|
try:
|
||||||
dbid = emby_db.getItem_byId(plexID)[0]
|
dbid = emby_db.getItem_byId(plexID)[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
dbid = None
|
dbid = None
|
||||||
params['id'] = plexID
|
params['id'] = plexID
|
||||||
params['dbid'] = dbid
|
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(
|
xbmcplugin.addDirectoryItem(
|
||||||
handle=int(sys.argv[1]),
|
handle=int(sys.argv[1]),
|
||||||
url="%s?%s" % (url, urllib.urlencode(params)),
|
url=path,
|
||||||
listitem=listitem)
|
listitem=listitem)
|
||||||
return xbmcplugin.endOfDirectory(
|
return xbmcplugin.endOfDirectory(
|
||||||
handle=int(sys.argv[1]),
|
handle=int(sys.argv[1]),
|
||||||
|
@ -1610,7 +1628,7 @@ def getOnDeck(viewid, mediatype, tagname, limit):
|
||||||
continue
|
continue
|
||||||
for episode in episodes:
|
for episode in episodes:
|
||||||
# There will always be only 1 episode ('limit=1')
|
# There will always be only 1 episode ('limit=1')
|
||||||
li = createListItem(episode)
|
listitem = createListItem(episode)
|
||||||
# Fix some skin shortcomings
|
# Fix some skin shortcomings
|
||||||
title = episode.get('title', '')
|
title = episode.get('title', '')
|
||||||
if utils.settings('OnDeckTvAppendSeason') == 'true':
|
if utils.settings('OnDeckTvAppendSeason') == 'true':
|
||||||
|
@ -1623,11 +1641,11 @@ def getOnDeck(viewid, mediatype, tagname, limit):
|
||||||
show = episode.get('showtitle')
|
show = episode.get('showtitle')
|
||||||
if show:
|
if show:
|
||||||
title = show + ' - ' + title
|
title = show + ' - ' + title
|
||||||
li.setLabel(title)
|
listitem.setLabel(title)
|
||||||
xbmcplugin.addDirectoryItem(
|
xbmcplugin.addDirectoryItem(
|
||||||
handle=int(sys.argv[1]),
|
handle=int(sys.argv[1]),
|
||||||
url=episode['file'],
|
url=episode['file'],
|
||||||
listitem=li,
|
listitem=listitem,
|
||||||
isFolder=False)
|
isFolder=False)
|
||||||
|
|
||||||
count += 1
|
count += 1
|
||||||
|
|
Loading…
Reference in a new issue