Fix correctly recording ended (not stopped!) video
This commit is contained in:
parent
4e85b65318
commit
8e1b77fcfe
1 changed files with 18 additions and 12 deletions
|
@ -22,9 +22,11 @@ LOG = getLogger("PLEX." + __name__)
|
|||
|
||||
|
||||
@LOCKER.lockthis
|
||||
def playback_cleanup():
|
||||
def playback_cleanup(ended=False):
|
||||
"""
|
||||
PKC cleanup after playback ends/is stopped
|
||||
PKC cleanup after playback ends/is stopped. Pass ended=True if Kodi
|
||||
completely finished playing an item (because we will get and use wrong
|
||||
timing data otherwise)
|
||||
"""
|
||||
LOG.debug('playback_cleanup called')
|
||||
# We might have saved a transient token from a user flinging media via
|
||||
|
@ -44,7 +46,7 @@ def playback_cleanup():
|
|||
# Bookmarks might not be pickup up correctly, so let's do them
|
||||
# manually. Applies to addon paths, but direct paths might have
|
||||
# started playback via PMS
|
||||
_record_playstate(status)
|
||||
_record_playstate(status, ended)
|
||||
# Reset the player's status
|
||||
status = copy.deepcopy(state.PLAYSTATE)
|
||||
# As all playback has halted, reset the players that have been active
|
||||
|
@ -52,7 +54,7 @@ def playback_cleanup():
|
|||
LOG.debug('Finished PKC playback cleanup')
|
||||
|
||||
|
||||
def _record_playstate(status):
|
||||
def _record_playstate(status, ended):
|
||||
with kodidb.GetKodiDB('video') as kodi_db:
|
||||
# Hack - remove any obsolete file entries Kodi made
|
||||
kodi_db.clean_file_table()
|
||||
|
@ -65,8 +67,12 @@ def _record_playstate(status):
|
|||
# Item not (yet) in Kodi library
|
||||
LOG.debug('No playstate update due to Plex id not found: %s', status)
|
||||
return
|
||||
time = float(kodi_time_to_millis(status['time'])) / 1000
|
||||
totaltime = float(kodi_time_to_millis(status['totaltime'])) / 1000
|
||||
if ended:
|
||||
progress = 0.99
|
||||
time = v.IGNORE_SECONDS_AT_START + 1
|
||||
else:
|
||||
time = float(kodi_time_to_millis(status['time'])) / 1000
|
||||
try:
|
||||
progress = time / totaltime
|
||||
except ZeroDivisionError:
|
||||
|
@ -143,4 +149,4 @@ class PKC_Player(Player):
|
|||
Will be called when playback ends due to the media file being finished
|
||||
"""
|
||||
LOG.debug("ONPLAYBACK_ENDED")
|
||||
playback_cleanup()
|
||||
playback_cleanup(ended=True)
|
||||
|
|
Loading…
Reference in a new issue