From 363b45851493eb3fc9300e8fda6811884e289bc7 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Fri, 29 Jan 2016 20:40:23 -0600 Subject: [PATCH] Fix newly added album/songs Since we process a dictionary, we can't really control the order it's being processed in. Audio is being added before the album, so added an album verification at song level. --- resources/lib/itemtypes.py | 70 +++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index 09ad964f..08bda44c 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -18,7 +18,8 @@ import utils import embydb_functions as embydb import kodidb_functions as kodidb import read_embyserver as embyserver -import musicutils as musicutils +import musicutils + ################################################################################################## @@ -2040,39 +2041,46 @@ class Music(Items): self.logMsg("Song itemid: %s has no albumId." % itemid, 1) return except TypeError: - # No album found, create a single's album - kodicursor.execute("select coalesce(max(idAlbum),0) from album") - albumid = kodicursor.fetchone()[0] + 1 - if kodiversion in (16, 17): - # Kodi Jarvis, Krypton - query = ( - ''' - INSERT INTO album(idAlbum, strGenres, iYear, strReleaseType) + # No album found. Let's create it + emby_albumId = item['AlbumId'] + album = emby.getItem(emby_albumId) + emby_dbalbum = emby_db.getItem_byId(emby_albumId) + try: + albumid = emby_dbalbum[0] + except TypeError: + # No album found, create a single's album + kodicursor.execute("select coalesce(max(idAlbum),0) from album") + albumid = kodicursor.fetchone()[0] + 1 + if kodiversion == 16: + # Kodi Jarvis + query = ( + ''' + INSERT INTO album(idAlbum, strGenres, iYear, strReleaseType) - VALUES (?, ?, ?, ?) - ''' - ) - kodicursor.execute(query, (albumid, genre, year, "single")) - elif kodiversion == 15: - # Kodi Isengard - query = ( - ''' - INSERT INTO album(idAlbum, strGenres, iYear, dateAdded, strReleaseType) + VALUES (?, ?, ?, ?) + ''' + ) + kodicursor.execute(query, (albumid, genre, year, "single")) + elif kodiversion == 15: + # Kodi Isengard + query = ( + ''' + INSERT INTO album(idAlbum, strGenres, iYear, dateAdded, strReleaseType) - VALUES (?, ?, ?, ?, ?) - ''' - ) - kodicursor.execute(query, (albumid, genre, year, dateadded, "single")) - else: - # Kodi Helix - query = ( - ''' - INSERT INTO album(idAlbum, strGenres, iYear, dateAdded) + VALUES (?, ?, ?, ?, ?) + ''' + ) + kodicursor.execute(query, (albumid, genre, year, dateadded, "single")) + else: + # Kodi Helix + query = ( + ''' + INSERT INTO album(idAlbum, strGenres, iYear, dateAdded) - VALUES (?, ?, ?, ?) - ''' - ) - kodicursor.execute(query, (albumid, genre, year, dateadded)) + VALUES (?, ?, ?, ?) + ''' + ) + kodicursor.execute(query, (albumid, genre, year, dateadded)) # Create the song entry kodicursor.execute("select coalesce(max(idSong),0) from song")