Fix resume and runtime
This commit is contained in:
parent
5c3605ddd1
commit
a134259cb5
3 changed files with 48 additions and 16 deletions
|
@ -1258,6 +1258,38 @@ class PlexAPI():
|
||||||
self.logMsg("Error retrieving metadata for %s" % url, 1)
|
self.logMsg("Error retrieving metadata for %s" % url, 1)
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
|
def GetPlexPlaylist(self, key):
|
||||||
|
"""
|
||||||
|
Returns raw API metadata XML dump.
|
||||||
|
|
||||||
|
Can be called with either Plex key '/library/metadata/xxxx'metadata
|
||||||
|
OR with the digits 'xxxx' only.
|
||||||
|
"""
|
||||||
|
xml = ''
|
||||||
|
key = str(key)
|
||||||
|
url = "{server}/playQueues"
|
||||||
|
if '/library/metadata/' in key:
|
||||||
|
# Cut of the slash!
|
||||||
|
item = key[1:]
|
||||||
|
else:
|
||||||
|
item = "library/metadata/" + key
|
||||||
|
arguments = {
|
||||||
|
'checkFiles': 1, # No idea
|
||||||
|
'includeExtras': 1, # Trailers and Extras => Extras
|
||||||
|
'includeRelated': 1, # Similar movies => Video -> Related
|
||||||
|
'includeRelatedCount': 5,
|
||||||
|
'includeOnDeck': 1,
|
||||||
|
'includeChapters': 1,
|
||||||
|
'includePopularLeaves': 1,
|
||||||
|
'includeConcerts': 1
|
||||||
|
}
|
||||||
|
url = url + '?' + urlencode(arguments)
|
||||||
|
headerOptions = {'Accept': 'application/xml'}
|
||||||
|
xml = self.doUtils.downloadUrl(url, headerOptions=headerOptions)
|
||||||
|
if not xml:
|
||||||
|
self.logMsg("Error retrieving metadata for %s" % url, 1)
|
||||||
|
return xml
|
||||||
|
|
||||||
|
|
||||||
class API():
|
class API():
|
||||||
|
|
||||||
|
@ -1304,7 +1336,6 @@ class API():
|
||||||
def getChecksum(self):
|
def getChecksum(self):
|
||||||
"""
|
"""
|
||||||
Returns a string, not int!
|
Returns a string, not int!
|
||||||
Maybe get rid of viewOffset = (resume point)?!?
|
|
||||||
"""
|
"""
|
||||||
item = self.item
|
item = self.item
|
||||||
# Include a letter to prohibit saving as an int!
|
# Include a letter to prohibit saving as an int!
|
||||||
|
@ -1321,7 +1352,7 @@ class API():
|
||||||
item.get('lastViewedAt', ""),
|
item.get('lastViewedAt', ""),
|
||||||
item.get('viewOffset', "")
|
item.get('viewOffset', "")
|
||||||
)
|
)
|
||||||
return str(checksum)
|
return checksum
|
||||||
|
|
||||||
def getKey(self):
|
def getKey(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1385,10 +1416,10 @@ class API():
|
||||||
lastPlayedDate = None
|
lastPlayedDate = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resume = int(item['viewOffset'])
|
resume = float(item['viewOffset']) * 1.0/1000.0
|
||||||
|
resume = round(resume, 6)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
resume = 0
|
resume = 0.0
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'Favorite': favorite,
|
'Favorite': favorite,
|
||||||
'PlayCount': playcount,
|
'PlayCount': playcount,
|
||||||
|
@ -1595,24 +1626,26 @@ class API():
|
||||||
"""
|
"""
|
||||||
Resume point of time and runtime/totaltime. Rounded to 6th decimal.
|
Resume point of time and runtime/totaltime. Rounded to 6th decimal.
|
||||||
|
|
||||||
Assumption: time for both resume and runtime is measured in
|
Time from Plex server is measured in milliseconds.
|
||||||
milliseconds on the Plex side and in seconds on the Kodi side.
|
Kodi: on the Plex side and in seconds on the Kodi side.
|
||||||
"""
|
"""
|
||||||
item = self.item
|
item = self.item
|
||||||
|
time_factor = 1.0 / 1000.0 # millisecond -> seconds
|
||||||
# xml
|
# xml
|
||||||
try:
|
try:
|
||||||
item = item[0].attrib
|
item = item[0].attrib
|
||||||
# json
|
# json
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
time_factor = 1/1000
|
runtime = float(item['duration'])
|
||||||
runtime = int(item['duration']) * time_factor
|
|
||||||
try:
|
try:
|
||||||
resume = int(item['viewOffset']) * time_factor
|
resume = float(item['viewOffset'])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
resume = 0
|
resume = 0.0
|
||||||
resume = round(float(resume), 6)
|
runtime = runtime * time_factor
|
||||||
runtime = round(float(runtime), 6)
|
resume = resume * time_factor
|
||||||
|
resume = round(resume, 6)
|
||||||
|
runtime = round(runtime, 6)
|
||||||
return resume, runtime
|
return resume, runtime
|
||||||
|
|
||||||
def getMpaa(self):
|
def getMpaa(self):
|
||||||
|
|
|
@ -457,8 +457,7 @@ class Movies(Items):
|
||||||
# kodi_db.addTags(movieid, tags, "movie")
|
# kodi_db.addTags(movieid, tags, "movie")
|
||||||
# Process playstates
|
# Process playstates
|
||||||
# resume = API.adjustResume(userdata['Resume'])
|
# resume = API.adjustResume(userdata['Resume'])
|
||||||
total = round(float(runtime), 6)
|
kodi_db.addPlaystate(fileid, resume, runtime, playcount, dateplayed)
|
||||||
kodi_db.addPlaystate(fileid, resume, total, playcount, dateplayed)
|
|
||||||
|
|
||||||
def add_updateBoxset(self, boxset):
|
def add_updateBoxset(self, boxset):
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ class PlaybackUtils():
|
||||||
# Remove the original item from playlist
|
# Remove the original item from playlist
|
||||||
self.pl.removefromPlaylist(startPos+1)
|
self.pl.removefromPlaylist(startPos+1)
|
||||||
# Readd the original item to playlist - via jsonrpc so we have full metadata
|
# Readd the original item to playlist - via jsonrpc so we have full metadata
|
||||||
self.pl.insertintoPlaylist(currentPosition+1, dbid, item['Type'].lower())
|
self.pl.insertintoPlaylist(currentPosition+1, dbid, item[0].attrib['type'].lower())
|
||||||
currentPosition += 1
|
currentPosition += 1
|
||||||
|
|
||||||
############### -- CHECK FOR INTROS ################
|
############### -- CHECK FOR INTROS ################
|
||||||
|
|
Loading…
Reference in a new issue