New artwork method implement

Old method still available for backward compatibility
This commit is contained in:
angelblue05 2015-10-08 04:18:56 -05:00
parent 6c4242abeb
commit 06ad9ab18c
3 changed files with 87 additions and 115 deletions

View file

@ -137,18 +137,32 @@ class TextureCache():
for art in artwork:
if art == "Backdrop":
# Backdrop entry is a list
artList = artwork[art]
if artList:
self.addOrUpdateArt(artList[0], kodiId, mediaType, kodiart[art], cursor)
# Backdrop entry is a list, process extra fanart for artwork downloader (fanart, fanart1, fanart2, etc.)
backdrops = artwork[art]
backdropsNumber = len(backdrops)
cursor.execute("SELECT url FROM art WHERE media_id = ? AND media_type = ? AND type LIKE ?", (kodiId, mediaType, "fanart%",))
rows = cursor.fetchall()
if len(rows) > backdropsNumber:
# More backdrops in database than what we are going to process. Delete extra fanart.
cursor.execute("DELETE FROM art WHERE media_id = ? AND media_type = ? AND type LIKE ?", (kodiId, mediaType, "fanart_",))
index = ""
for backdrop in backdrops:
self.addOrUpdateArt(backdrop, kodiId, mediaType, "%s%s" % ("fanart", index), cursor)
if backdropsNumber > 1:
try: # Will only fail on the first try, str to int.
index += 1
except TypeError:
index = 1
elif art == "Primary":
# Primary art is processed as thumb and poster for Kodi.
for artType in kodiart[art]:
self.addOrUpdateArt(artwork[art], kodiId, mediaType, artType, cursor)
else:
# For banner, logo, art, thumb, disc
else: # For banner, logo, art, thumb, disc
self.addOrUpdateArt(artwork[art], kodiId, mediaType, kodiart[art], cursor)
def addOrUpdateArt(self, imageUrl, kodiId, mediaType, imageType, cursor):
@ -166,14 +180,14 @@ class TextureCache():
query = "INSERT INTO art(media_id, media_type, type, url) values(?, ?, ?, ?)"
cursor.execute(query, (kodiId, mediaType, imageType, imageUrl))
else:
else: # Only cache artwork if it changed
if url != imageUrl:
cacheimage = True
# Only for backdrop
if imageType == "fanart":
# Only for the main backdrop, poster
if imageType in {"fanart", "poster"}:
# Delete current entry before updating with the new one
self.deleteFanart(url)
self.deleteCachedArtwork(url)
self.logMsg("Updating Art Link for kodiId: %s (%s) -> (%s)" % (kodiId, url, imageUrl), 1)
query = "UPDATE art set url = ? WHERE media_id = ? AND media_type = ? AND type = ?"
@ -188,26 +202,31 @@ class TextureCache():
if url and self.enableTextureCache:
self.logMsg("Processing: %s" % url, 2)
# add image to texture cache by simply calling it at the http endpoint
# Add image to texture cache by simply calling it at the http endpoint
url = self.double_urlencode(url)
try:
response = requests.head('http://%s:%s/image/image://%s' % (self.xbmc_host, self.xbmc_port, url), auth=(self.xbmc_username, self.xbmc_password),timeout=(0.01, 0.01))
except:
#extreme short timeouts so we will have a exception, but we don't need the result so pass
pass
try: # Extreme short timeouts so we will have a exception, but we don't need the result so pass
response = requests.head('http://%s:%s/image/image://%s' % (self.xbmc_host, self.xbmc_port, url), auth=(self.xbmc_username, self.xbmc_password), timeout=(0.01, 0.01))
except: pass
def deleteFanart(self, url):
# Only necessary to remove and apply a new backdrop
def deleteCachedArtwork(self, url):
# Only necessary to remove and apply a new backdrop or poster
connection = utils.KodiSQL('texture')
cursor = connection.cursor()
cursor.execute("SELECT cachedurl FROM texture WHERE url = ?", (url,))
try:
cursor.fetchone()[0]
cachedurl = cursor.fetchone()[0]
except:
self.logMsg("Could not find cached url.", 1)
else:
else: # Delete thumbnail as well as the entry
thumbnails = xbmc.translatePath("special://thumbnails/%s" % cachedurl)
self.logMsg("Deleting cached thumbnail: %s" % thumbnails, 1)
xbmcvfs.delete(thumbnails)
cursor.execute("DELETE FROM texture WHERE url = ?", (url,))
connection.commit()
finally:
cursor.close()

View file

@ -64,12 +64,16 @@ class WriteKodiMusicDB():
bio = API().getOverview(MBitem)
# Associate artwork
thumb = API().getArtwork(MBitem, "Primary")
artworks = API().getAllArtwork(MBitem)
thumb = artworks['Primary']
backdrops = artworks['Backdrop'] # List
if thumb:
thumb = "<thumb>%s</thumb>" % thumb
fanart = API().getArtwork(MBitem, "Backdrop")
if fanart:
fanart = "<fanart>%s</fanart>" % fanart
if backdrops:
fanart = "<fanart>%s</fanart>" % backdrops[0]
else:
fanart = ""
##### UPDATE THE ARTIST #####
if artistid:
@ -121,16 +125,8 @@ class WriteKodiMusicDB():
query = "INSERT INTO emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
cursor.execute(query, (embyId, artistid, "artist", checksum))
# Update artwork
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), artistid, "artist", "thumb", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), artistid, "artist", "poster", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Banner"), artistid, "artist", "banner", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Logo"), artistid, "artist", "clearlogo", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Art"), artistid, "artist", "clearart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Thumb"), artistid, "artist", "landscape", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Disc"), artistid, "artist", "discart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Backdrop"), artistid, "artist", "fanart", cursor)
self.textureCache.addArtwork(artworks, artistid, "artist", cursor)
def addOrUpdateAlbumToKodiLibrary(self, MBitem, connection, cursor):
@ -166,7 +162,8 @@ class WriteKodiMusicDB():
artists = " / ".join(MBartists)
# Associate the artwork
thumb = API().getArtwork(MBitem, "Primary")
artworks = API().getAllArtwork(MBitem)
thumb = artworks['Primary']
if thumb:
thumb = "<thumb>%s</thumb>" % thumb
@ -224,14 +221,7 @@ class WriteKodiMusicDB():
self.AddGenresToMedia(albumid, genres, "album", cursor)
# Update artwork
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), albumid, "album", "thumb", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "BoxRear"), albumid, "album", "poster", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Banner"), albumid, "album", "banner", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Logo"), albumid, "album", "clearlogo", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Art"), albumid, "album", "clearart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Thumb"), albumid, "album", "landscape", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Disc"), albumid, "album", "discart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Backdrop"), albumid, "album", "fanart", cursor)
self.textureCache.addArtwork(artworks, albumid, "album", cursor)
# Link album to artists
if MBartists:
@ -390,14 +380,7 @@ class WriteKodiMusicDB():
cursor.execute(query, (artistid, songid, artist['Name']))
# Update artwork
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), songid, "song", "thumb", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), songid, "song", "poster", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Banner"), songid, "song", "banner", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Logo"), songid, "song", "clearlogo", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Art"), songid, "song", "clearart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Thumb"), songid, "song", "landscape", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Disc"), songid, "song", "discart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Backdrop"), songid, "song", "fanart", cursor)
self.textureCache.addArtwork(API().getAllArtwork(MBitem), songid, "song", cursor)
def deleteItemFromKodiLibrary(self, id, connection, cursor):

View file

@ -234,19 +234,12 @@ class WriteKodiVideoDB():
self.AddTagsToMedia(movieid, tags, "movie", cursor)
# Update artwork
self.textureCache.addArtwork(API().getAllArtwork(MBitem), movieid, "movie", cursor)
# Update or insert actors
self.AddPeopleToMedia(movieid, MBitem.get('People'), "movie", connection, cursor)
# Update artwork
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "movie"), movieid, "movie", "thumb", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "movie"), movieid, "movie", "poster", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Banner", mediaType = "movie"), movieid, "movie", "banner", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Logo", mediaType = "movie"), movieid, "movie", "clearlogo", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Art", mediaType = "movie"), movieid, "movie", "clearart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Thumb", mediaType = "movie"), movieid, "movie", "landscape", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Disc", mediaType = "movie"), movieid, "movie", "discart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Backdrop", mediaType = "movie"), movieid, "movie", "fanart", cursor)
# Update genres
self.AddGenresToMedia(movieid, genres, "movie", cursor)
@ -405,18 +398,12 @@ class WriteKodiVideoDB():
#update the checksum in emby table
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(MBitem),MBitem["Id"]))
#update or insert actors
self.AddPeopleToMedia(idMVideo,MBitem.get("People"),"musicvideo", connection, cursor)
#update artwork
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "musicvideo"), idMVideo, "musicvideo", "thumb", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "musicvideo"), idMVideo, "musicvideo", "poster", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Banner", mediaType = "musicvideo"), idMVideo, "musicvideo", "banner", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Logo", mediaType = "musicvideo"), idMVideo, "musicvideo", "clearlogo", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Art", mediaType = "musicvideo"), idMVideo, "musicvideo", "clearart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Thumb", mediaType = "musicvideo"), idMVideo, "musicvideo", "landscape", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Disc", mediaType = "musicvideo"), idMVideo, "musicvideo", "discart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Backdrop", mediaType = "musicvideo"), idMVideo, "musicvideo", "fanart", cursor)
# Update artwork
self.textureCache.addArtwork(API().getAllArtwork(MBitem), idMVideo, "musicvideo", cursor)
#update genres
self.AddGenresToMedia(idMVideo, genres, "musicvideo", cursor)
@ -546,6 +533,9 @@ class WriteKodiVideoDB():
self.AddTagsToMedia(showid, tags, "tvshow", cursor)
# Update artwork
self.textureCache.addArtwork(API().getAllArtwork(MBitem), showid, "tvshow", cursor)
# Update or insert people
self.AddPeopleToMedia(showid, MBitem.get('People'),"tvshow", connection, cursor)
@ -554,16 +544,6 @@ class WriteKodiVideoDB():
# Update studios
self.AddStudiosToMedia(showid, studios, "tvshow", cursor)
# Update artwork
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "tvshow"), showid, "tvshow", "thumb", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "tvshow"), showid, "tvshow", "poster", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Banner", mediaType = "tvshow"), showid, "tvshow", "banner", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Logo", mediaType = "tvshow"), showid, "tvshow", "clearlogo", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Art", mediaType = "tvshow"), showid, "tvshow", "clearart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Thumb", mediaType = "tvshow"), showid, "tvshow", "landscape", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Disc", mediaType = "tvshow"), showid, "tvshow", "discart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Backdrop", mediaType = "tvshow"), showid, "tvshow", "fanart", cursor)
# Update season details
self.updateSeasons(embyId, showid, connection, cursor)
@ -723,7 +703,8 @@ class WriteKodiVideoDB():
self.AddStreamDetailsToMedia(API().getMediaStreams(MBitem), runtime, fileid, cursor)
# Update artwork
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "episode"), episodeid, "episode", "thumb", cursor)
artworks = API().getAllArtwork(MBitem)
self.textureCache.addOrUpdateArt(artworks['Primary'], episodeid, "episode", "thumb", cursor)
# Set resume point and round to 6th decimal
resume = round(float(timeInfo.get('ResumeTime')), 6)
@ -764,49 +745,38 @@ class WriteKodiVideoDB():
def updateSeasons(self, embyTvShowId, kodiTvShowId, connection, cursor):
textureCache = self.textureCache
seasonData = ReadEmbyDB().getTVShowSeasons(embyTvShowId)
if seasonData: # Verify every season
for season in seasonData:
seasonNum = season.get('IndexNumber')
cursor.execute("SELECT idSeason as seasonid FROM seasons WHERE idShow = ? and season = ?", (kodiTvShowId, seasonNum,))
try:
seasonid = cursor.fetchone()[0]
except: # Create the season
cursor.execute("select coalesce(max(idSeason),0) as seasonid from seasons")
seasonid = cursor.fetchone()[0] + 1
query = "INSERT INTO seasons(idSeason, idShow, season) values(?, ?, ?)"
cursor.execute(query, (seasonid, kodiTvShowId, seasonNum))
finally: # Update artwork
imageUrl = API().getArtwork(season, "Thumb", mediaType = "season")
self.addOrUpdateArt(imageUrl, seasonid, "season", "landscape", cursor)
imageUrl = API().getArtwork(season, "Primary", mediaType = "season")
self.addOrUpdateArt(imageUrl, seasonid, "season", "poster", cursor)
imageUrl = API().getArtwork(season, "Banner", mediaType = "season")
self.addOrUpdateArt(imageUrl, seasonid, "season", "banner", cursor)
imageUrl = API().getArtwork(season, "Backdrop", mediaType = "season")
self.addOrUpdateArt(imageUrl, seasonid, "season", "fanart", cursor)
for season in seasonData:
seasonNum = season.get('IndexNumber')
# All season entry
MBitem = ReadEmbyDB().getFullItem(embyTvShowId)
seasonNum = -1
cursor.execute("SELECT idSeason as seasonid FROM seasons WHERE idShow = ? and season = ?", (kodiTvShowId, seasonNum,))
try:
seasonid = cursor.fetchone()[0]
except: # Create all season entry
except: # Create the season
cursor.execute("select coalesce(max(idSeason),0) as seasonid from seasons")
seasonid = cursor.fetchone()[0] + 1
query = "INSERT INTO seasons(idSeason, idShow, season) values(?, ?, ?)"
cursor.execute(query, (seasonid, kodiTvShowId, seasonNum))
finally: # Update the artwork
imageUrl = API().getArtwork(MBitem, "Primary", mediaType = "season")
self.addOrUpdateArt(imageUrl, seasonid, "season", "poster", cursor)
finally: # Update artwork
textureCache.addArtwork(API().getAllArtwork(season), seasonid, "season", cursor)
# All season entry
MBitem = ReadEmbyDB().getFullItem(embyTvShowId)
seasonNum = -1
cursor.execute("SELECT idSeason as seasonid FROM seasons WHERE idShow = ? and season = ?", (kodiTvShowId, seasonNum,))
try:
seasonid = cursor.fetchone()[0]
except: # Create all season entry
cursor.execute("select coalesce(max(idSeason),0) as seasonid from seasons")
seasonid = cursor.fetchone()[0] + 1
query = "INSERT INTO seasons(idSeason, idShow, season) values(?, ?, ?)"
cursor.execute(query, (seasonid, kodiTvShowId, seasonNum))
finally: # Update the artwork
textureCache.addArtwork(API().getAllArtwork(MBitem), seasonid, "season", cursor)
def addOrUpdateArt(self, imageUrl, kodiId, mediaType, imageType, cursor):
@ -907,7 +877,7 @@ class WriteKodiVideoDB():
if "writing" in arttype:
arttype = "writer"
self.addOrUpdateArt(thumb, actorid, arttype, "thumb", cursor)
self.textureCache.addOrUpdateArt(thumb, actorid, arttype, "thumb", cursor)
# Link person to content in database
if kodiVersion == 15 or kodiVersion == 16: