Fix resume when using an external player

This commit is contained in:
croneter 2019-11-02 15:58:22 +01:00 committed by croneter
parent bae4178c5b
commit b6d6482c4a
2 changed files with 38 additions and 11 deletions

View file

@ -35,7 +35,8 @@ class PlayState(object):
'volume': 100, 'volume': 100,
'muted': False, 'muted': False,
'playmethod': None, 'playmethod': None,
'playcount': None 'playcount': None,
'external_player': False # bool - xbmc.Player().isExternalPlayer()
} }
def __init__(self): def __init__(self):

View file

@ -349,6 +349,11 @@ class KodiMonitor(xbmc.Monitor):
status['plex_type'] = plex_type status['plex_type'] = plex_type
status['playmethod'] = item.playmethod status['playmethod'] = item.playmethod
status['playcount'] = item.playcount status['playcount'] = item.playcount
try:
status['external_player'] = app.APP.player.isExternalPlayer() == 1
except AttributeError:
# Kodi version < 17
pass
LOG.debug('Set the player state: %s', status) LOG.debug('Set the player state: %s', status)
if not app.SYNC.direct_paths: if not app.SYNC.direct_paths:
_notify_upnext(item) _notify_upnext(item)
@ -403,17 +408,22 @@ def _record_playstate(status, ended):
LOG.debug('No playstate update due to Plex id not found: %s', status) LOG.debug('No playstate update due to Plex id not found: %s', status)
return return
totaltime = float(timing.kodi_time_to_millis(status['totaltime'])) / 1000 totaltime = float(timing.kodi_time_to_millis(status['totaltime'])) / 1000
if ended: if status['external_player']:
progress = 0.99 _external_player_correct_plex_watch_count(db_item)
time = v.IGNORE_SECONDS_AT_START + 1 progress = 0.0
time = 0.0
else: else:
time = float(timing.kodi_time_to_millis(status['time'])) / 1000 if ended:
try: progress = 0.99
progress = time / totaltime time = v.IGNORE_SECONDS_AT_START + 1
except ZeroDivisionError: else:
progress = 0.0 time = float(timing.kodi_time_to_millis(status['time'])) / 1000
LOG.debug('Playback progress %s (%s of %s seconds)', try:
progress, time, totaltime) progress = time / totaltime
except ZeroDivisionError:
progress = 0.0
LOG.debug('Playback progress %s (%s of %s seconds)',
progress, time, totaltime)
playcount = status['playcount'] playcount = status['playcount']
last_played = timing.kodi_now() last_played = timing.kodi_now()
if playcount is None: if playcount is None:
@ -455,6 +465,22 @@ def _record_playstate(status, ended):
backgroundthread.BGThreader.addTasksToFront([task]) backgroundthread.BGThreader.addTasksToFront([task])
def _external_player_correct_plex_watch_count(db_item):
"""
Kodi won't safe playstate at all for external players
There's currently no way to get a resumpoint if an external player is
in use We are just checking whether we should mark video as
completely watched or completely unwatched (according to
playcountminimumtime set in playercorefactory.xml)
See https://kodi.wiki/view/External_players
"""
with kodi_db.KodiVideoDB() as kodidb:
playcount = kodidb.get_playcount(db_item['kodi_fileid'])
LOG.debug('External player detected. Playcount: %s', playcount)
PF.scrobble(db_item['plex_id'], 'watched' if playcount else 'unwatched')
def _clean_file_table(): def _clean_file_table():
""" """
If we associate a playing video e.g. pointing to plugin://... to an existing If we associate a playing video e.g. pointing to plugin://... to an existing