From 4e85b65318ef0f94c68ba82262f3ce93feb7570f Mon Sep 17 00:00:00 2001 From: croneter Date: Thu, 15 Mar 2018 10:25:51 +0100 Subject: [PATCH] Direct paths: correctly clean up after context menu play --- resources/lib/kodidb_functions.py | 8 ++++++++ resources/lib/playback.py | 5 ++++- resources/lib/player.py | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index 7c430b9e..b14a94ff 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -204,6 +204,14 @@ class KodiDBMethods(object): self.cursor.execute(query, (file_id, path_id, filename, date_added)) return file_id + def clean_file_table(self): + """ + Hack: using Direct Paths, Kodi adds all addon paths to the files table + 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('DELETE FROM files where dateAdded IS NULL') + def remove_file(self, file_id): """ Removes the entry for file_id from the files table. Will also delete diff --git a/resources/lib/playback.py b/resources/lib/playback.py index dd233d95..044a753e 100644 --- a/resources/lib/playback.py +++ b/resources/lib/playback.py @@ -164,7 +164,10 @@ def _ensure_resolve(abort=False): will be destroyed. """ if RESOLVE: - state.PKC_CAUSED_STOP = True + LOG.debug('Passing dummy path to Kodi') + if not state.CONTEXT_MENU_PLAY: + # Because playback won't start with context menu play + state.PKC_CAUSED_STOP = True result = Playback_Successful() result.listitem = PKC_ListItem(path='PKC_Dummy_Path_Which_Fails') pickle_me(result) diff --git a/resources/lib/player.py b/resources/lib/player.py index c954a090..3aaa02af 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -53,6 +53,9 @@ def playback_cleanup(): def _record_playstate(status): + with kodidb.GetKodiDB('video') as kodi_db: + # Hack - remove any obsolete file entries Kodi made + kodi_db.clean_file_table() if not status['plex_id']: LOG.debug('No Plex id found to record playstate for status %s', status) return