Improvements to resume points

- Plex sometimes tells time in milliseconds instead of seconds
- Fixes #49
This commit is contained in:
tomkat83 2016-06-05 18:39:26 +02:00
parent 7402d076b0
commit fcf6948735
4 changed files with 14 additions and 7 deletions

View file

@ -262,8 +262,7 @@ class Items(object):
# If the playback was stopped, check whether we need to increment the
# playcount. PMS won't tell us the playcount via websockets
if item['state'] in ('stopped', 'ended'):
complete = float(item['viewOffset']) / float(item['duration'])
complete = complete * 100
complete = float(item['viewOffset']) / float(item['duration'])*100
self.logMsg('Item %s stopped with completion rate %s percent.'
'Mark item played at %s percent.'
% (item['ratingKey'],

View file

@ -1522,13 +1522,19 @@ class LibrarySync(Thread):
userdata = API.getUserData()
currSess['duration'] = userdata['Runtime']
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
items.append({
'ratingKey': ratingKey,
'kodi_id': kodiInfo[0],
'file_id': kodiInfo[1],
'kodi_type': kodiInfo[4],
'viewOffset': item.get('viewOffset'),
'viewOffset': resume,
'state': state,
'duration': currSess['duration'],
'viewCount': currSess['viewCount'],

View file

@ -117,6 +117,7 @@ class Player(xbmc.Player):
try:
seekTime = self.xbmcplayer.getTime()
except RuntimeError:
self.logMsg('Could not get current seektime from xbmc player', -1)
seekTime = 0
# Get playback volume
@ -246,7 +247,7 @@ class Player(xbmc.Player):
'playQueueVersion': playQueueVersion,
'playQueueID': playQueueID,
'playQueueItemID': playQueueItemID,
'runtime': runtime * 1000,
'runtime': runtime,
'item_id': itemId,
'refresh_id': refresh_id,
'currentfile': currentFile,
@ -513,7 +514,7 @@ class Player(xbmc.Player):
markPlayedAt = float(settings('markPlayed')) / 100
self.logMsg("Percent complete: %s Mark played at: %s"
% (percentComplete, markPlayedAt), 1)
if currentPosition >= markPlayedAt:
if percentComplete >= markPlayedAt:
# Tell Kodi that we've finished watching (Plex knows)
if (data['fileid'] is not None and
data['itemType'] in ('movie', 'episode')):
@ -586,5 +587,6 @@ class Player(xbmc.Player):
'time': int(data['currentPosition']),
'duration': int(data.get('runtime', 0))
}
self.logMsg('Informing PMS about our state: %s' % args, 2)
self.doUtils("{server}/:/timeline?" + urlencode(args),
action_type="GET")

View file

@ -174,8 +174,8 @@ class SubscriptionManager:
+ serv.get('port', '32400') + "/:/timeline"
self.doUtils(url, parameters=params)
# 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"
% params['state'], 2)
self.logMsg("sent server notification with parameters: %s"
% params, 2)
def controllable(self):
return "volume,shuffle,repeat,audioStream,videoStream,subtitleStream,skipPrevious,skipNext,seekTo,stepBack,stepForward,stop,playPause"