Direct paths: fix replaying item where playback was started via PMS

This commit is contained in:
croneter 2018-04-08 15:38:13 +02:00
parent 30abe0f2fb
commit 7a4997da7a
2 changed files with 32 additions and 9 deletions

View file

@ -5,6 +5,8 @@ from logging import getLogger
from ntpath import dirname
from sqlite3 import IntegrityError
import xbmc
import artwork
from utils import kodi_sql, try_decode, unix_timestamp, unix_date_to_kodi
import variables as v
@ -210,18 +212,33 @@ class KodiDBMethods(object):
but without a dateAdded entry. This method cleans up all file entries
without a dateAdded entry - to be called after playback has ended.
"""
self.cursor.execute('SELECT idFile FROM files WHERE dateAdded IS NULL')
query = '''
SELECT idFile FROM files
WHERE dateAdded IS NULL
AND strFilename LIKE \'plugin://plugin.video.plexkodiconnect%\'
'''
i = 0
while i < 100:
self.cursor.execute(query)
files = self.cursor.fetchall()
self.cursor.execute('DELETE FROM files where dateAdded IS NULL')
for file in files:
if files:
break
# Make sure Kodi recorded "false" playstate FIRST before
# cleaning it
i += 1
xbmc.sleep(100)
for item in files:
LOG.debug('Cleaning file id: %s', item[0])
self.cursor.execute('DELETE FROM files WHERE idFile = ?',
(item[0],))
self.cursor.execute('DELETE FROM bookmark WHERE idFile = ?',
(file[0],))
(item[0],))
self.cursor.execute('DELETE FROM settings WHERE idFile = ?',
(file[0],))
(item[0],))
self.cursor.execute('DELETE FROM streamdetails WHERE idFile = ?',
(file[0],))
(item[0],))
self.cursor.execute('DELETE FROM stacktimes WHERE idFile = ?',
(file[0],))
(item[0],))
def show_id_from_path(self, path):
"""

View file

@ -28,7 +28,8 @@ def playback_cleanup(ended=False):
completely finished playing an item (because we will get and use wrong
timing data otherwise)
"""
LOG.debug('playback_cleanup called')
LOG.debug('playback_cleanup called. Active players: %s',
state.ACTIVE_PLAYERS)
# We might have saved a transient token from a user flinging media via
# Companion (if we could not use the playqueue to store the token)
state.PLEX_TRANSIENT_TOKEN = None
@ -106,6 +107,11 @@ def _record_playstate(status, ended):
xbmc.getCondVisibility('Window.IsVisible(Home.xml)')):
LOG.debug('Refreshing skin to update widgets')
xbmc.executebuiltin('ReloadSkin()')
if (state.DIRECT_PATHS and
status['playmethod'] in ('DirectStream', 'Transcode')):
LOG.debug('Start cleaning Kodi files table')
with kodidb.GetKodiDB('video') as kodi_db:
kodi_db.clean_file_table()
class PKC_Player(xbmc.Player):