From 8f8ccd1daf7d4101c9b0905f68f06c8ac794bd13 Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 3 Feb 2019 17:20:36 +0100 Subject: [PATCH] Fix music items getting deleted on startup --- resources/lib/itemtypes/music.py | 9 +++------ resources/lib/kodi_db/music.py | 9 +++++++++ resources/lib/library_sync/full_sync.py | 5 +++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/resources/lib/itemtypes/music.py b/resources/lib/itemtypes/music.py index 20dc516c..f54fac45 100644 --- a/resources/lib/itemtypes/music.py +++ b/resources/lib/itemtypes/music.py @@ -52,12 +52,9 @@ class MusicMixin(object): db_item['kodi_type'], userdata['UserRating']) if plex_type == v.PLEX_TYPE_SONG: - self.kodidb.set_resume(db_item['kodi_fileid'], - userdata['Resume'], - userdata['Runtime'], - userdata['PlayCount'], - userdata['LastPlayedDate'], - plex_type) + self.kodidb.set_playcount(userdata['PlayCount'], + userdata['LastPlayedDate'], + db_item['kodi_id'],) return True def remove(self, plex_id, plex_type=None): diff --git a/resources/lib/kodi_db/music.py b/resources/lib/kodi_db/music.py index 793b7a25..37f5c4a9 100644 --- a/resources/lib/kodi_db/music.py +++ b/resources/lib/kodi_db/music.py @@ -459,6 +459,15 @@ class KodiMusicDB(common.KodiDBBase): WHERE idSong = ? ''', (args)) + @common.catch_operationalerrors + def set_playcount(self, *args): + self.cursor.execute(''' + UPDATE song + SET iTimesPlayed = ?, + lastplayed = ? + WHERE idSong = ? + ''', (args)) + @common.catch_operationalerrors def update_song_17(self, *args): self.cursor.execute(''' diff --git a/resources/lib/library_sync/full_sync.py b/resources/lib/library_sync/full_sync.py index ccda2b7e..3010eebb 100644 --- a/resources/lib/library_sync/full_sync.py +++ b/resources/lib/library_sync/full_sync.py @@ -323,6 +323,11 @@ class FullSync(common.fullsync_mixin): if self.successful: # Set timestamp for next sync - neglecting playstates! utils.settings('lastfullsync', value=str(int(self.current_sync))) + # In order to not delete all your songs again + if app.SYNC.enable_music: + kinds.extend([ + (v.PLEX_TYPE_SONG, v.PLEX_TYPE_ARTIST, itemtypes.Song, True), + ]) # SYNC PLAYSTATE of ALL items (otherwise we won't pick up on items that # were set to unwatched). Also mark all items on the PMS to be able # to delete the ones still in Kodi