From 7a4997da7a02f881268dafc7304f5b8604924f04 Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 8 Apr 2018 15:38:13 +0200 Subject: [PATCH] Direct paths: fix replaying item where playback was started via PMS --- resources/lib/kodidb_functions.py | 33 +++++++++++++++++++++++-------- resources/lib/player.py | 8 +++++++- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index 7560458a..1af60834 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -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') - files = self.cursor.fetchall() - self.cursor.execute('DELETE FROM files where dateAdded IS NULL') - for file in files: + 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() + 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): """ diff --git a/resources/lib/player.py b/resources/lib/player.py index 1cea6808..22ab3568 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -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):