From b61b8ae8942e1bed9e7205c291e436f31c501e19 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Sat, 9 Jan 2016 03:03:39 -0600 Subject: [PATCH] Failsafe incase view is named after existing tag After the initial sync already completed. --- resources/lib/kodidb_functions.py | 58 ++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index 687c485e..47713e25 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -852,26 +852,52 @@ class Kodidb_Functions(): if self.kodiversion in (15, 16): # Kodi Isengard, Jarvis - query = ' '.join(( + try: + query = ' '.join(( - "UPDATE tag_link", - "SET tag_id = ?", - "WHERE media_id = ?", - "AND media_type = ?", - "AND tag_id = ?" - )) - cursor.execute(query, (newtag, kodiid, mediatype, oldtag,)) + "UPDATE tag_link", + "SET tag_id = ?", + "WHERE media_id = ?", + "AND media_type = ?", + "AND tag_id = ?" + )) + cursor.execute(query, (newtag, kodiid, mediatype, oldtag,)) + except Exception as e: + # The new tag we are going to apply already exists for this item + # delete current tag instead + self.logMsg("Exception: %s" % e, 1) + query = ' '.join(( + + "DELETE FROM tag_link", + "WHERE media_id = ?", + "AND media_type = ?", + "AND tag_id = ?" + )) + cursor.execute(query, (kodiid, mediatype, oldtag,)) else: # Kodi Helix - query = ' '.join(( + try: + query = ' '.join(( - "UPDATE taglinks", - "SET idTag = ?", - "WHERE idMedia = ?", - "AND media_type = ?", - "AND idTag = ?" - )) - cursor.execute(query, (newtag, kodiid, mediatype, oldtag,)) + "UPDATE taglinks", + "SET idTag = ?", + "WHERE idMedia = ?", + "AND media_type = ?", + "AND idTag = ?" + )) + cursor.execute(query, (newtag, kodiid, mediatype, oldtag,)) + except Exception as e: + # The new tag we are going to apply already exists for this item + # delete current tag instead + self.logMsg("Exception: %s" % e, 1) + query = ' '.join(( + + "DELETE FROM taglinks", + "WHERE idMedia = ?", + "AND media_type = ?", + "AND idTag = ?" + )) + cursor.execute(query, (kodiid, mediatype, oldtag,)) def removeTag(self, kodiid, tagname, mediatype):