Resume should finally work as expected

This commit is contained in:
tomkat83 2016-02-04 15:57:24 +01:00
parent 0f6494aa3e
commit e148090c3c
2 changed files with 58 additions and 14 deletions

View file

@ -38,6 +38,14 @@ def GetItemClassFromType(itemType):
return classes[itemType] return classes[itemType]
def GetKodiTypeFromPlex(plexItemType):
classes = {
'movie': 'video',
'episode': 'video',
}
return classes[plexItemType.lower()]
def GetPlexKeyNumber(plexKey): def GetPlexKeyNumber(plexKey):
""" """
Deconstructs e.g. '/library/metadata/xxxx' to the tuple Deconstructs e.g. '/library/metadata/xxxx' to the tuple

View file

@ -63,8 +63,14 @@ class PlaybackUtils():
# Run through the passed PMS playlist and construct self.playlist # Run through the passed PMS playlist and construct self.playlist
listitems = [] listitems = []
# Open DB
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
emby_db = embydb_functions.Embydb_Functions(embycursor)
for mediaItem in self.item: for mediaItem in self.item:
listitems += self.AddMediaItemToPlaylist(mediaItem) listitems += self.AddMediaItemToPlaylist(mediaItem, emby_db)
# Close DB
embyconn.close()
# Kick off playback # Kick off playback
if startPlayer: if startPlayer:
@ -81,7 +87,7 @@ class PlaybackUtils():
self.playlist.remove(filename) self.playlist.remove(filename)
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitems[0]) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitems[0])
def AddMediaItemToPlaylist(self, item): def AddMediaItemToPlaylist(self, item, emby_db):
""" """
Feed with ONE media item from PMS xml response Feed with ONE media item from PMS xml response
(on level with e.g. key=/library/metadata/220493 present) (on level with e.g. key=/library/metadata/220493 present)
@ -92,27 +98,44 @@ class PlaybackUtils():
""" """
self.API = PlexAPI.API(item) self.API = PlexAPI.API(item)
playutils = putils.PlayUtils(item) playutils = putils.PlayUtils(item)
pl = playlist.Playlist()
# Get playurls per part and process them # Get playurls per part and process them
listitems = [] listitems = []
for playurl in playutils.getPlayUrl(): for playurl in playutils.getPlayUrl():
# One new listitem per part # Add item via Kodi db, if found. Preserves metadata
listitem = xbmcgui.ListItem() emby_dbitem = emby_db.getItem_byId(self.API.getRatingKey())
if emby_dbitem:
self.logMsg('emby_dbitem found', 1)
kodi_id = emby_dbitem[0]
media_type = emby_dbitem[4]
pl.insertintoPlaylist(
self.currentPosition,
kodi_id,
media_type)
# Retrieve listitem that we just added by JSON
listitem = self.playlist[self.currentPosition]
# Also update the playurl below, otherwise we'll get a loop!
# E.g. Trailers
else:
self.logMsg('emby_dbitem not found. Plex ratingKey was %s'
% self.API.getRatingKey(), 1)
listitem = xbmcgui.ListItem()
# Set artwork
self.setProperties(playurl, listitem)
# Set metadata
self.setListItem(listitem)
self.playlist.add(
playurl, listitem, index=self.currentPosition)
# For transcoding only, ask for audio/subs pref # For transcoding only, ask for audio/subs pref
if utils.window('emby_%s.playmethod' % playurl) == "Transcode": if utils.window('emby_%s.playmethod' % playurl) == "Transcode":
playurl = playutils.audioSubsPref(playurl, listitem) playurl = playutils.audioSubsPref(playurl, listitem)
utils.window('emby_%s.playmethod' % playurl, value="Transcode") utils.window('emby_%s.playmethod' % playurl, value="Transcode")
# Update the playurl to the PMS xml response (hence no loop)
listitem.setPath(playurl) listitem.setPath(playurl)
# Set artwork
self.setProperties(playurl, listitem)
# Set metadata
self.setListItem(listitem)
self.playlist.add(
playurl, listitem, index=self.currentPosition)
listitems.append(listitem) listitems.append(listitem)
self.currentPosition += 1 self.currentPosition += 1
@ -192,19 +215,32 @@ class PlaybackUtils():
def setArtwork(self, listItem): def setArtwork(self, listItem):
# allartwork = artwork.getAllArtwork(item, parentInfo=True) # allartwork = artwork.getAllArtwork(item, parentInfo=True)
allartwork = self.API.getAllArtwork(parentInfo=True) allartwork = self.API.getAllArtwork(parentInfo=True)
self.logMsg('allartwork: %s' % allartwork, 2)
# Set artwork for listitem # arttypes = {
# 'poster': "Primary",
# 'tvshow.poster': "Primary",
# 'clearart': "Art",
# 'tvshow.clearart': "Art",
# 'clearlogo': "Logo",
# 'tvshow.clearlogo': "Logo",
# 'discart': "Disc",
# 'fanart_image': "Backdrop",
# 'landscape': "Thumb"
# }
arttypes = { arttypes = {
'poster': "Primary", 'poster': "Primary",
'tvshow.poster': "Primary", 'tvshow.poster': "Primary",
'clearart': "Art", 'clearart': "Art",
'tvshow.clearart': "Art", 'tvshow.clearart': "Art",
'clearart': "Primary",
'tvshow.clearart': "Primary",
'clearlogo': "Logo", 'clearlogo': "Logo",
'tvshow.clearlogo': "Logo", 'tvshow.clearlogo': "Logo",
'discart': "Disc", 'discart': "Disc",
'fanart_image': "Backdrop", 'fanart_image': "Backdrop",
'landscape': "Thumb" 'landscape': "Backdrop"
} }
for arttype in arttypes: for arttype in arttypes: