From 2c6f7512997c0a4cd918ae5295187b30cac87018 Mon Sep 17 00:00:00 2001 From: Piotr Smolinski Date: Mon, 24 Oct 2016 23:37:29 +0200 Subject: [PATCH] Propagated the pathid/fileid change I moved the pathid/fileid resolution outside of create/update section that it is shared by both flows. Then I added the idFile change to the UPDATE statement and replaced emby_db.updateReference with emby_db.createReference. The latter one is UPSERT type update, therefore also safe here. --- resources/lib/itemtypes.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index 65490717..588b8574 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -424,6 +424,11 @@ class Movies(Items): # c23 - pathid # This information is used later by file browser. + # add/retrieve pathid and fileid + # if the path or file already exists, the calls return current value + pathid = self.kodi_db.addPath(path) + fileid = self.kodi_db.addFile(filename, pathid) + # UPDATE THE MOVIE ##### if update_item: log.info("UPDATE movie itemid: %s - Title: %s" @@ -436,37 +441,36 @@ class Movies(Items): "SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?," "c06 = ?, c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?," "c14 = ?, c15 = ?, c16 = ?, c18 = ?, c19 = ?, c21 = ?," - "c22 = ?, c23 = ?, premiered = ?", + "c22 = ?, c23 = ?, idFile=?, premiered = ?", "WHERE idMovie = ?" )) kodicursor.execute(query, (title, plot, shortplot, tagline, votecount, rating, writer, year, imdb, sorttitle, runtime, mpaa, genre, director, title, studio, trailer, country, - playurl, pathid, year, movieid)) + playurl, pathid, fileid, year, movieid)) else: query = ' '.join(( "UPDATE movie", "SET c00 = ?, c01 = ?, c02 = ?, c03 = ?, c04 = ?, c05 = ?," "c06 = ?, c07 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ?," "c14 = ?, c15 = ?, c16 = ?, c18 = ?, c19 = ?, c21 = ?," - "c22 = ?, c23 = ?", + "c22 = ?, c23 = ?, idFile=?", "WHERE idMovie = ?" )) kodicursor.execute(query, (title, plot, shortplot, tagline, votecount, rating, writer, year, imdb, sorttitle, runtime, mpaa, genre, director, title, studio, trailer, country, - playurl, pathid, movieid)) + playurl, pathid, fileid, movieid)) # Update the checksum in emby table - emby_db.updateReference(itemid, checksum) + # emby_db.updateReference(itemid, checksum) + # Add reference is idempotent; the call here updates also fileid and pathid when item + # is moved or renamed + emby_db.addReference(itemid, movieid, "Movie", "movie", fileid, pathid, None, checksum, viewid) ##### OR ADD THE MOVIE ##### else: log.info("ADD movie itemid: %s - Title: %s" % (itemid, title)) - # Add path - pathid = self.kodi_db.addPath(path) - # Add the file - fileid = self.kodi_db.addFile(filename, pathid) # Create the movie entry query = (