Improvements to resume points
- Plex sometimes tells time in milliseconds instead of seconds - Fixes #49
This commit is contained in:
parent
7402d076b0
commit
fcf6948735
4 changed files with 14 additions and 7 deletions
|
@ -262,8 +262,7 @@ class Items(object):
|
||||||
# If the playback was stopped, check whether we need to increment the
|
# If the playback was stopped, check whether we need to increment the
|
||||||
# playcount. PMS won't tell us the playcount via websockets
|
# playcount. PMS won't tell us the playcount via websockets
|
||||||
if item['state'] in ('stopped', 'ended'):
|
if item['state'] in ('stopped', 'ended'):
|
||||||
complete = float(item['viewOffset']) / float(item['duration'])
|
complete = float(item['viewOffset']) / float(item['duration'])*100
|
||||||
complete = complete * 100
|
|
||||||
self.logMsg('Item %s stopped with completion rate %s percent.'
|
self.logMsg('Item %s stopped with completion rate %s percent.'
|
||||||
'Mark item played at %s percent.'
|
'Mark item played at %s percent.'
|
||||||
% (item['ratingKey'],
|
% (item['ratingKey'],
|
||||||
|
|
|
@ -1522,13 +1522,19 @@ class LibrarySync(Thread):
|
||||||
userdata = API.getUserData()
|
userdata = API.getUserData()
|
||||||
currSess['duration'] = userdata['Runtime']
|
currSess['duration'] = userdata['Runtime']
|
||||||
currSess['viewCount'] = userdata['PlayCount']
|
currSess['viewCount'] = userdata['PlayCount']
|
||||||
|
# Sometimes, Plex tells us resume points in milliseconds and
|
||||||
|
# not in seconds - thank you very much!
|
||||||
|
if item.get('viewOffset') > currSess['duration']:
|
||||||
|
resume = item.get('viewOffset') / 1000
|
||||||
|
else:
|
||||||
|
resume = item.get('viewOffset')
|
||||||
# Append to list that we need to process
|
# Append to list that we need to process
|
||||||
items.append({
|
items.append({
|
||||||
'ratingKey': ratingKey,
|
'ratingKey': ratingKey,
|
||||||
'kodi_id': kodiInfo[0],
|
'kodi_id': kodiInfo[0],
|
||||||
'file_id': kodiInfo[1],
|
'file_id': kodiInfo[1],
|
||||||
'kodi_type': kodiInfo[4],
|
'kodi_type': kodiInfo[4],
|
||||||
'viewOffset': item.get('viewOffset'),
|
'viewOffset': resume,
|
||||||
'state': state,
|
'state': state,
|
||||||
'duration': currSess['duration'],
|
'duration': currSess['duration'],
|
||||||
'viewCount': currSess['viewCount'],
|
'viewCount': currSess['viewCount'],
|
||||||
|
|
|
@ -117,6 +117,7 @@ class Player(xbmc.Player):
|
||||||
try:
|
try:
|
||||||
seekTime = self.xbmcplayer.getTime()
|
seekTime = self.xbmcplayer.getTime()
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
|
self.logMsg('Could not get current seektime from xbmc player', -1)
|
||||||
seekTime = 0
|
seekTime = 0
|
||||||
|
|
||||||
# Get playback volume
|
# Get playback volume
|
||||||
|
@ -246,7 +247,7 @@ class Player(xbmc.Player):
|
||||||
'playQueueVersion': playQueueVersion,
|
'playQueueVersion': playQueueVersion,
|
||||||
'playQueueID': playQueueID,
|
'playQueueID': playQueueID,
|
||||||
'playQueueItemID': playQueueItemID,
|
'playQueueItemID': playQueueItemID,
|
||||||
'runtime': runtime * 1000,
|
'runtime': runtime,
|
||||||
'item_id': itemId,
|
'item_id': itemId,
|
||||||
'refresh_id': refresh_id,
|
'refresh_id': refresh_id,
|
||||||
'currentfile': currentFile,
|
'currentfile': currentFile,
|
||||||
|
@ -513,7 +514,7 @@ class Player(xbmc.Player):
|
||||||
markPlayedAt = float(settings('markPlayed')) / 100
|
markPlayedAt = float(settings('markPlayed')) / 100
|
||||||
self.logMsg("Percent complete: %s Mark played at: %s"
|
self.logMsg("Percent complete: %s Mark played at: %s"
|
||||||
% (percentComplete, markPlayedAt), 1)
|
% (percentComplete, markPlayedAt), 1)
|
||||||
if currentPosition >= markPlayedAt:
|
if percentComplete >= markPlayedAt:
|
||||||
# Tell Kodi that we've finished watching (Plex knows)
|
# Tell Kodi that we've finished watching (Plex knows)
|
||||||
if (data['fileid'] is not None and
|
if (data['fileid'] is not None and
|
||||||
data['itemType'] in ('movie', 'episode')):
|
data['itemType'] in ('movie', 'episode')):
|
||||||
|
@ -586,5 +587,6 @@ class Player(xbmc.Player):
|
||||||
'time': int(data['currentPosition']),
|
'time': int(data['currentPosition']),
|
||||||
'duration': int(data.get('runtime', 0))
|
'duration': int(data.get('runtime', 0))
|
||||||
}
|
}
|
||||||
|
self.logMsg('Informing PMS about our state: %s' % args, 2)
|
||||||
self.doUtils("{server}/:/timeline?" + urlencode(args),
|
self.doUtils("{server}/:/timeline?" + urlencode(args),
|
||||||
action_type="GET")
|
action_type="GET")
|
||||||
|
|
|
@ -174,8 +174,8 @@ class SubscriptionManager:
|
||||||
+ serv.get('port', '32400') + "/:/timeline"
|
+ serv.get('port', '32400') + "/:/timeline"
|
||||||
self.doUtils(url, parameters=params)
|
self.doUtils(url, parameters=params)
|
||||||
# requests.getwithparams(serv.get('server', 'localhost'), serv.get('port', 32400), "/:/timeline", params, getPlexHeaders(), serv.get('protocol', 'http'))
|
# requests.getwithparams(serv.get('server', 'localhost'), serv.get('port', 32400), "/:/timeline", params, getPlexHeaders(), serv.get('protocol', 'http'))
|
||||||
self.logMsg("sent server notification with state = %s"
|
self.logMsg("sent server notification with parameters: %s"
|
||||||
% params['state'], 2)
|
% params, 2)
|
||||||
|
|
||||||
def controllable(self):
|
def controllable(self):
|
||||||
return "volume,shuffle,repeat,audioStream,videoStream,subtitleStream,skipPrevious,skipNext,seekTo,stepBack,stepForward,stop,playPause"
|
return "volume,shuffle,repeat,audioStream,videoStream,subtitleStream,skipPrevious,skipNext,seekTo,stepBack,stepForward,stop,playPause"
|
||||||
|
|
Loading…
Reference in a new issue