fixes for music sync
This commit is contained in:
parent
f7605802d3
commit
46918b914e
5 changed files with 69 additions and 56 deletions
|
@ -433,17 +433,26 @@ class API():
|
|||
if(data.get("ImageTags") != None and data.get("ImageTags").get(type) != None):
|
||||
imageTag = data.get("ImageTags").get(type)
|
||||
|
||||
if (data.get("Type") == "Episode" or data.get("Type") == "Season" or data.get("Type") == "MusicAlbum" or data.get("Type") == "Audio") and type=="Logo":
|
||||
if (data.get("Type") == "Episode" or data.get("Type") == "Season") and type=="Logo":
|
||||
imageTag = data.get("ParentLogoImageTag")
|
||||
if (data.get("Type") == "Episode" or data.get("Type") == "Season") and type=="Art":
|
||||
imageTag = data.get("ParentArtImageTag")
|
||||
if (data.get("Type") == "Episode") and originalType=="Thumb3":
|
||||
if (data.get("Type") == "Episode" and originalType=="Thumb3"):
|
||||
imageTag = data.get("SeriesThumbImageTag")
|
||||
if (data.get("Type") == "Season") and originalType=="Thumb3" and imageTag=="e3ab56fe27d389446754d0fb04910a34" :
|
||||
if (data.get("Type") == "Season" and originalType=="Thumb3" and imageTag=="e3ab56fe27d389446754d0fb04910a34"):
|
||||
imageTag = data.get("ParentThumbImageTag")
|
||||
id = data.get("SeriesId")
|
||||
if (data.get("Type") == "MusicAlbum" or data.get("Type") == "Audio") and type=="Backdrop":
|
||||
|
||||
# for music we return the parent art if no image exists
|
||||
if (data.get("Type") == "MusicAlbum" or data.get("Type") == "Audio") and type=="Backdrop" and not data.get("BackdropImageTags"):
|
||||
data["BackdropImageTags"] = data["ParentBackdropImageTags"]
|
||||
id = data.get("ParentBackdropItemId")
|
||||
if (data.get("Type") == "MusicAlbum" or data.get("Type") == "Audio") and type=="Logo" and (not imageTag or imageTag == "e3ab56fe27d389446754d0fb04910a34"):
|
||||
imageTag = data.get("ParentLogoImageTag")
|
||||
id = data.get("ParentLogoItemId")
|
||||
if (data.get("Type") == "MusicAlbum" or data.get("Type") == "Audio") and type=="Art" and (not imageTag or imageTag == "e3ab56fe27d389446754d0fb04910a34"):
|
||||
imageTag = data.get("ParentArtImageTag")
|
||||
id = data.get("ParentArtItemId")
|
||||
|
||||
query = ""
|
||||
maxHeight = "10000"
|
||||
|
|
|
@ -396,7 +396,9 @@ class LibrarySync(threading.Thread):
|
|||
def MusicFullSync(self, connection,cursor, pDialog):
|
||||
|
||||
self.ProcessMusicArtists(connection,cursor,pDialog)
|
||||
connection.commit()
|
||||
self.ProcessMusicAlbums(connection,cursor,pDialog)
|
||||
connection.commit()
|
||||
self.ProcessMusicSongs(connection,cursor,pDialog)
|
||||
|
||||
### commit all changes to database ###
|
||||
|
@ -436,10 +438,10 @@ class LibrarySync(threading.Thread):
|
|||
kodiSong = kodisong
|
||||
|
||||
if kodiSong == None:
|
||||
WriteKodiMusicDB().addOrUpdateSongToKodiLibrary(item["Id"],connection, cursor)
|
||||
WriteKodiMusicDB().addOrUpdateSongToKodiLibrary(item,connection, cursor)
|
||||
else:
|
||||
if kodiSong[2] != API().getChecksum(item):
|
||||
WriteKodiMusicDB().addOrUpdateSongToKodiLibrary(item["Id"],connection, cursor)
|
||||
WriteKodiMusicDB().addOrUpdateSongToKodiLibrary(item,connection, cursor)
|
||||
|
||||
#### PROCESS DELETES #####
|
||||
allEmbySongIds = set(allEmbySongIds)
|
||||
|
@ -462,7 +464,7 @@ class LibrarySync(threading.Thread):
|
|||
total = len(allEmbyArtists) + 1
|
||||
count = 1
|
||||
|
||||
#### PROCESS SONGS ADDS AND UPDATES ###
|
||||
#### PROCESS ARTIST ADDS AND UPDATES ###
|
||||
for item in allEmbyArtists:
|
||||
|
||||
if (self.ShouldStop()):
|
||||
|
@ -482,10 +484,10 @@ class LibrarySync(threading.Thread):
|
|||
kodiArtist = kodiartist
|
||||
|
||||
if kodiArtist == None:
|
||||
WriteKodiMusicDB().addOrUpdateArtistToKodiLibrary(item["Id"],connection, cursor)
|
||||
WriteKodiMusicDB().addOrUpdateArtistToKodiLibrary(item,connection, cursor)
|
||||
else:
|
||||
if kodiArtist[2] != API().getChecksum(item):
|
||||
WriteKodiMusicDB().addOrUpdateArtistToKodiLibrary(item["Id"],connection, cursor)
|
||||
WriteKodiMusicDB().addOrUpdateArtistToKodiLibrary(item,connection, cursor)
|
||||
|
||||
#### PROCESS DELETES #####
|
||||
allEmbyArtistIds = set(allEmbyArtistIds)
|
||||
|
@ -528,10 +530,10 @@ class LibrarySync(threading.Thread):
|
|||
kodiAlbum = kodialbum
|
||||
|
||||
if kodiAlbum == None:
|
||||
WriteKodiMusicDB().addOrUpdateAlbumToKodiLibrary(item["Id"],connection, cursor)
|
||||
WriteKodiMusicDB().addOrUpdateAlbumToKodiLibrary(item,connection, cursor)
|
||||
else:
|
||||
if kodiAlbum[2] != API().getChecksum(item):
|
||||
WriteKodiMusicDB().addOrUpdateAlbumToKodiLibrary(item["Id"],connection, cursor)
|
||||
WriteKodiMusicDB().addOrUpdateAlbumToKodiLibrary(item,connection, cursor)
|
||||
|
||||
#### PROCESS DELETES #####
|
||||
allEmbyAlbumIds = set(allEmbyAlbumIds)
|
||||
|
|
|
@ -72,7 +72,7 @@ class ReadEmbyDB():
|
|||
doUtils = DownloadUtils()
|
||||
|
||||
#only get basic info for our sync-compares
|
||||
url = "{server}/Artists?Recursive=true&Fields=Etag,CumulativeRunTimeTicks&UserId={UserId}&format=json"
|
||||
url = "{server}/Artists?Recursive=true&Fields=Etag,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&UserId={UserId}&format=json"
|
||||
|
||||
jsonData = doUtils.downloadUrl(url)
|
||||
if (jsonData == ""):
|
||||
|
@ -97,7 +97,7 @@ class ReadEmbyDB():
|
|||
doUtils = DownloadUtils()
|
||||
|
||||
#only get basic info for our sync-compares
|
||||
url = "{server}/mediabrowser/Users/{UserId}/Items?Fields=Name,CumulativeRunTimeTicks,Etag&Recursive=true&IncludeItemTypes=Audio&format=json"
|
||||
url = "{server}/mediabrowser/Users/{UserId}/Items?Fields=Etag,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&IncludeItemTypes=Audio&format=json"
|
||||
|
||||
jsonData = doUtils.downloadUrl(url)
|
||||
if (jsonData == ""):
|
||||
|
@ -122,7 +122,7 @@ class ReadEmbyDB():
|
|||
doUtils = DownloadUtils()
|
||||
|
||||
#only get basic info for our sync-compares
|
||||
url = "{server}/mediabrowser/Users/{UserId}/Items?Fields=Name,CumulativeRunTimeTicks,Etag&Recursive=true&IncludeItemTypes=MusicAlbum&format=json"
|
||||
url = "{server}/mediabrowser/Users/{UserId}/Items?Fields=Etag,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&IncludeItemTypes=MusicAlbum&format=json"
|
||||
|
||||
jsonData = doUtils.downloadUrl(url)
|
||||
if (jsonData == ""):
|
||||
|
|
|
@ -41,15 +41,13 @@ class WriteKodiMusicDB():
|
|||
className = self.__class__.__name__
|
||||
utils.logMsg("%s %s" % (self.addonName, className), msg, int(lvl))
|
||||
|
||||
def addOrUpdateArtistToKodiLibrary(self, embyId, connection, cursor):
|
||||
def addOrUpdateArtistToKodiLibrary(self, MBitem, connection, cursor):
|
||||
|
||||
MBitem = ReadEmbyDB().getFullItem(embyId)
|
||||
if not MBitem:
|
||||
self.logMsg("ADD or UPDATE artist to Kodi library FAILED!, Id: %s" %(embyId), 1)
|
||||
return
|
||||
# If the item already exist in the local Kodi DB we'll perform a full item update
|
||||
# If the item doesn't exist, we'll add it to the database
|
||||
|
||||
embyId = MBitem["Id"]
|
||||
|
||||
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?", (embyId,))
|
||||
try:
|
||||
artistid = cursor.fetchone()[0]
|
||||
|
@ -73,20 +71,7 @@ class WriteKodiMusicDB():
|
|||
fanart = API().getArtwork(MBitem, "Backdrop")
|
||||
if fanart:
|
||||
fanart = "<fanart>%s</fanart>" % fanart
|
||||
|
||||
# Safety check 1: does the artist already exist?
|
||||
cursor.execute("SELECT idArtist FROM artist WHERE strArtist = ?", (name,))
|
||||
try:
|
||||
artistid = cursor.fetchone()[0]
|
||||
except: pass
|
||||
|
||||
# Safety check 2: does the MusicBrainzArtistId already exist?
|
||||
cursor.execute("SELECT idArtist FROM artist WHERE strMusicBrainzArtistID = ?", (musicBrainzId,))
|
||||
try:
|
||||
artistid = cursor.fetchone()[0]
|
||||
except: pass
|
||||
|
||||
|
||||
|
||||
##### UPDATE THE ARTIST #####
|
||||
if artistid:
|
||||
self.logMsg("UPDATE artist to Kodi library, Id: %s - Artist: %s" % (embyId, name), 1)
|
||||
|
@ -101,12 +86,29 @@ class WriteKodiMusicDB():
|
|||
##### OR ADD THE ARTIST #####
|
||||
else:
|
||||
self.logMsg("ADD artist to Kodi library, Id: %s - Artist: %s" % (embyId, name), 1)
|
||||
|
||||
# Create the artist
|
||||
cursor.execute("select coalesce(max(idArtist),0) as artistid from artist")
|
||||
artistid = cursor.fetchone()[0] + 1
|
||||
query = "INSERT INTO artist(idArtist, strArtist, strMusicBrainzArtistID, strGenres, strBiography, strImage, strFanart, lastScraped, dateAdded) values(?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||
cursor.execute(query, (artistid, name, musicBrainzId, genres, bio, thumb, fanart, lastScraped, dateadded))
|
||||
|
||||
#safety checks: It looks like Emby supports the same artist multiple times in the database while Kodi doesn't allow that. In case that happens we just merge the artist in the Kodi database.
|
||||
|
||||
# Safety check 1: does the artist already exist?
|
||||
cursor.execute("SELECT idArtist FROM artist WHERE strArtist = ? COLLATE NOCASE", (name,))
|
||||
try:
|
||||
artistid = cursor.fetchone()[0]
|
||||
self.logMsg("Artist already exists in Kodi library - appending to existing object, Id: %s - Artist: %s - MusicBrainzId: %s - existing Kodi Id: %s" % (embyId, name, musicBrainzId, str(artistid)), 1)
|
||||
except: pass
|
||||
|
||||
# Safety check 2: does the MusicBrainzArtistId already exist?
|
||||
cursor.execute("SELECT idArtist FROM artist WHERE strMusicBrainzArtistID = ?", (musicBrainzId,))
|
||||
try:
|
||||
artistid = cursor.fetchone()[0]
|
||||
self.logMsg("Artist already exists in Kodi library - appending to existing object, Id: %s - Artist: %s - MusicBrainzId: %s - existing Kodi Id: %s" % (embyId, name, musicBrainzId, str(artistid)), 1)
|
||||
except: pass
|
||||
|
||||
if not artistid:
|
||||
# Create the artist
|
||||
cursor.execute("select coalesce(max(idArtist),0) as artistid from artist")
|
||||
artistid = cursor.fetchone()[0] + 1
|
||||
query = "INSERT INTO artist(idArtist, strArtist, strMusicBrainzArtistID, strGenres, strBiography, strImage, strFanart, lastScraped, dateAdded) values(?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
||||
cursor.execute(query, (artistid, name, musicBrainzId, genres, bio, thumb, fanart, lastScraped, dateadded))
|
||||
|
||||
# Create the reference in emby table
|
||||
query = "INSERT INTO emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
||||
|
@ -123,11 +125,11 @@ class WriteKodiMusicDB():
|
|||
self.addOrUpdateArt(API().getArtwork(MBitem, "Disc"), artistid, "artist", "discart", cursor)
|
||||
self.addOrUpdateArt(API().getArtwork(MBitem, "Backdrop"), artistid, "artist", "fanart", cursor)
|
||||
|
||||
def addOrUpdateAlbumToKodiLibrary(self, embyId, connection, cursor):
|
||||
def addOrUpdateAlbumToKodiLibrary(self, MBitem, connection, cursor):
|
||||
|
||||
kodiVersion = self.kodiversion
|
||||
|
||||
MBitem = ReadEmbyDB().getFullItem(embyId)
|
||||
embyId = MBitem["Id"]
|
||||
|
||||
# If the item already exist in the local Kodi DB we'll perform a full item update
|
||||
# If the item doesn't exist, we'll add it to the database
|
||||
|
@ -236,11 +238,11 @@ class WriteKodiMusicDB():
|
|||
query = "INSERT OR REPLACE INTO discography(idArtist, strAlbum, strYear) values(?, ?, ?)"
|
||||
cursor.execute(query, (artistid, name, str(year)))
|
||||
|
||||
def addOrUpdateSongToKodiLibrary(self, embyId, connection, cursor):
|
||||
def addOrUpdateSongToKodiLibrary(self, MBitem, connection, cursor):
|
||||
|
||||
kodiVersion = self.kodiversion
|
||||
|
||||
MBitem = ReadEmbyDB().getFullItem(embyId)
|
||||
|
||||
embyId = MBitem["Id"]
|
||||
|
||||
# If the item already exist in the local Kodi DB we'll perform a full item update
|
||||
# If the item doesn't exist, we'll add it to the database
|
||||
|
@ -430,7 +432,7 @@ class WriteKodiMusicDB():
|
|||
|
||||
for genre in genres:
|
||||
|
||||
cursor.execute("SELECT idGenre as idGenre FROM genre WHERE strGenre = ?", (genre,))
|
||||
cursor.execute("SELECT idGenre as idGenre FROM genre WHERE strGenre = ? COLLATE NOCASE", (genre,))
|
||||
try:
|
||||
idGenre = cursor.fetchone()[0]
|
||||
except: # Create the genre
|
||||
|
|
|
@ -867,10 +867,10 @@ class WriteKodiVideoDB():
|
|||
|
||||
if kodiVersion == 15 or kodiVersion == 16:
|
||||
# Kodi Isengard/jarvis
|
||||
cursor.execute("SELECT actor_id as actorid FROM actor WHERE name = ?", (name,))
|
||||
cursor.execute("SELECT actor_id as actorid FROM actor WHERE name = ? COLLATE NOCASE", (name,))
|
||||
else:
|
||||
# Kodi Gotham or Helix
|
||||
cursor.execute("SELECT idActor as actorid FROM actors WHERE strActor = ?", (name,))
|
||||
cursor.execute("SELECT idActor as actorid FROM actors WHERE strActor = ? COLLATE NOCASE", (name,))
|
||||
|
||||
try: # Update person in database
|
||||
actorid = cursor.fetchone()[0]
|
||||
|
@ -977,7 +977,7 @@ class WriteKodiVideoDB():
|
|||
|
||||
if kodiVersion == 15 or kodiVersion == 16:
|
||||
# Kodi Isengard
|
||||
cursor.execute("SELECT genre_id as genre_id FROM genre WHERE name = ?", (genre,))
|
||||
cursor.execute("SELECT genre_id as genre_id FROM genre WHERE name = ? COLLATE NOCASE", (genre,))
|
||||
try:
|
||||
genre_id = cursor.fetchone()[0]
|
||||
except:
|
||||
|
@ -994,7 +994,7 @@ class WriteKodiVideoDB():
|
|||
cursor.execute(query, (genre_id, id, mediatype))
|
||||
else:
|
||||
# Kodi Gotham or Helix
|
||||
cursor.execute("SELECT idGenre as idGenre FROM genre WHERE strGenre = ?", (genre,))
|
||||
cursor.execute("SELECT idGenre as idGenre FROM genre WHERE strGenre = ? COLLATE NOCASE", (genre,))
|
||||
try:
|
||||
idGenre = cursor.fetchone()[0]
|
||||
except:
|
||||
|
@ -1026,7 +1026,7 @@ class WriteKodiVideoDB():
|
|||
|
||||
if kodiVersion == 15 or kodiVersion == 16:
|
||||
# Kodi Isengard
|
||||
cursor.execute("SELECT country_id as country_id FROM country WHERE name = ?", (country,))
|
||||
cursor.execute("SELECT country_id as country_id FROM country WHERE name = ? COLLATE NOCASE", (country,))
|
||||
try:
|
||||
country_id = cursor.fetchone()[0]
|
||||
except:
|
||||
|
@ -1043,7 +1043,7 @@ class WriteKodiVideoDB():
|
|||
cursor.execute(query, (country_id, id, mediatype))
|
||||
else:
|
||||
# Kodi Gotham or Helix
|
||||
cursor.execute("SELECT idCountry as idCountry FROM country WHERE strCountry = ?", (country,))
|
||||
cursor.execute("SELECT idCountry as idCountry FROM country WHERE strCountry = ? COLLATE NOCASE", (country,))
|
||||
try:
|
||||
idCountry = cursor.fetchone()[0]
|
||||
except:
|
||||
|
@ -1068,7 +1068,7 @@ class WriteKodiVideoDB():
|
|||
|
||||
if kodiVersion == 15 or kodiVersion == 16:
|
||||
# Kodi Isengard
|
||||
cursor.execute("SELECT studio_id as studio_id FROM studio WHERE name = ?", (studio,))
|
||||
cursor.execute("SELECT studio_id as studio_id FROM studio WHERE name = ? COLLATE NOCASE", (studio,))
|
||||
try:
|
||||
studio_id = cursor.fetchone()[0]
|
||||
except: # Studio does not exists.
|
||||
|
@ -1083,7 +1083,7 @@ class WriteKodiVideoDB():
|
|||
cursor.execute(query, (studio_id, id, mediatype))
|
||||
else:
|
||||
# Kodi Gotham or Helix
|
||||
cursor.execute("SELECT idstudio as idstudio FROM studio WHERE strstudio = ?",(studio,))
|
||||
cursor.execute("SELECT idstudio as idstudio FROM studio WHERE strstudio = ? COLLATE NOCASE",(studio,))
|
||||
try:
|
||||
idstudio = cursor.fetchone()[0]
|
||||
except: # Studio does not exists.
|
||||
|
@ -1113,7 +1113,7 @@ class WriteKodiVideoDB():
|
|||
|
||||
if kodiVersion == 15 or kodiVersion == 16:
|
||||
# Kodi Isengard
|
||||
cursor.execute("SELECT tag_id as tag_id FROM tag WHERE name = ?", (tag,))
|
||||
cursor.execute("SELECT tag_id as tag_id FROM tag WHERE name = ? COLLATE NOCASE", (tag,))
|
||||
try:
|
||||
tag_id = cursor.fetchone()[0]
|
||||
except:
|
||||
|
@ -1134,7 +1134,7 @@ class WriteKodiVideoDB():
|
|||
cursor.execute(query, (id, mediatype, tag_id))
|
||||
else:
|
||||
# Kodi Gotham or Helix
|
||||
cursor.execute("SELECT idTag as idTag FROM tag WHERE strTag = ?", (tag,))
|
||||
cursor.execute("SELECT idTag as idTag FROM tag WHERE strTag = ? COLLATE NOCASE", (tag,))
|
||||
try:
|
||||
idTag = cursor.fetchone()[0]
|
||||
except:
|
||||
|
@ -1224,7 +1224,7 @@ class WriteKodiVideoDB():
|
|||
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?", (boxsetmovieid,))
|
||||
try:
|
||||
movieid = cursor.fetchone()[0]
|
||||
cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,))
|
||||
cursor.execute("SELECT idSet FROM sets WHERE strSet = ? COLLATE NOCASE", (strSet,))
|
||||
setid = cursor.fetchone()[0]
|
||||
except: pass
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue