Revert "constructor (with Artwork() as art)"

This reverts commit 168014c33b.
This commit is contained in:
tomkat83 2016-09-11 15:49:50 +02:00
parent 168014c33b
commit c4de7587bf
5 changed files with 62 additions and 87 deletions

View file

@ -173,8 +173,8 @@ class Main():
elif mode == "texturecache":
import artwork
with artwork.Artwork('music') as art:
art.fullTextureCacheSync()
artwork.Artwork().fullTextureCacheSync()
else:
entrypoint.doMainListing()

View file

@ -120,13 +120,6 @@ def setKodiWebServerDetails():
class Artwork():
"""
Use like this:
with Artwork(db_type) as art:
art.method()
db_type: the Kodi db to open: 'video' or 'music'
"""
lock = Lock()
enableTextureCache = settings('enableTextureCache') == "true"
@ -143,25 +136,6 @@ class Artwork():
imageCacheThreads = []
def __init__(self, db_type):
self.db_type = db_type
def __enter__(self):
"""
Open DB connections and cursors
"""
self.connection = kodiSQL(self.db_type)
self.cursor = self.connection.cursor()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
"""
Make sure DB changes are committed and connection to DB is closed.
"""
self.connection.commit()
self.connection.close()
return self
def double_urlencode(self, text):
text = self.single_urlencode(text)
text = self.single_urlencode(text)
@ -317,7 +291,7 @@ class Artwork():
else:
self.addWorkerImageCacheThread(url)
def addArtwork(self, artwork, kodiId, mediaType):
def addArtwork(self, artwork, kodiId, mediaType, cursor):
# Kodi conversion table
kodiart = {
@ -348,8 +322,8 @@ class Artwork():
"AND media_type = ?",
"AND type LIKE ?"
))
self.cursor.execute(query, (kodiId, mediaType, "fanart%",))
rows = self.cursor.fetchall()
cursor.execute(query, (kodiId, mediaType, "fanart%",))
rows = cursor.fetchall()
if len(rows) > backdropsNumber:
# More backdrops in database. Delete extra fanart.
@ -360,7 +334,7 @@ class Artwork():
"AND media_type = ?",
"AND type LIKE ?"
))
self.cursor.execute(query, (kodiId, mediaType, "fanart_",))
cursor.execute(query, (kodiId, mediaType, "fanart_",))
# Process backdrops and extra fanart
index = ""
@ -369,11 +343,11 @@ class Artwork():
imageUrl=backdrop,
kodiId=kodiId,
mediaType=mediaType,
imageType="%s%s" % ("fanart", index))
imageType="%s%s" % ("fanart", index),
cursor=cursor)
if backdropsNumber > 1:
try:
# Will only fail on the first try, str to int.
try: # Will only fail on the first try, str to int.
index += 1
except TypeError:
index = 1
@ -385,16 +359,19 @@ class Artwork():
imageUrl=artwork[art],
kodiId=kodiId,
mediaType=mediaType,
imageType=artType)
imageType=artType,
cursor=cursor)
elif kodiart.get(art):
# Process the rest artwork type that Kodi can use
self.addOrUpdateArt(
imageUrl=artwork[art],
kodiId=kodiId,
mediaType=mediaType,
imageType=kodiart[art])
imageType=kodiart[art],
cursor=cursor)
def addOrUpdateArt(self, imageUrl, kodiId, mediaType, imageType):
def addOrUpdateArt(self, imageUrl, kodiId, mediaType, imageType, cursor):
if not imageUrl:
# Possible that the imageurl is an empty string
return
@ -406,10 +383,10 @@ class Artwork():
"AND media_type = ?",
"AND type = ?"
))
self.cursor.execute(query, (kodiId, mediaType, imageType,))
cursor.execute(query, (kodiId, mediaType, imageType,))
try:
# Update the artwork
url = self.cursor.fetchone()[0]
url = cursor.fetchone()[0]
except TypeError:
# Add the artwork
log.debug("Adding Art Link for kodiId: %s (%s)"
@ -420,8 +397,7 @@ class Artwork():
VALUES (?, ?, ?, ?)
'''
)
self.cursor.execute(query,
(kodiId, mediaType, imageType, imageUrl))
cursor.execute(query, (kodiId, mediaType, imageType, imageUrl))
else:
if url == imageUrl:
# Only cache artwork if it changed
@ -440,21 +416,20 @@ class Artwork():
"AND media_type = ?",
"AND type = ?"
))
self.cursor.execute(query,
(imageUrl, kodiId, mediaType, imageType))
cursor.execute(query, (imageUrl, kodiId, mediaType, imageType))
# Cache fanart and poster in Kodi texture cache
self.cacheTexture(imageUrl)
def deleteArtwork(self, kodiId, mediaType):
def deleteArtwork(self, kodiId, mediaType, cursor):
query = ' '.join((
"SELECT url",
"FROM art",
"WHERE media_id = ?",
"AND media_type = ?"
))
self.cursor.execute(query, (kodiId, mediaType,))
rows = self.cursor.fetchall()
cursor.execute(query, (kodiId, mediaType,))
rows = cursor.fetchall()
for row in rows:
self.deleteCachedArtwork(row[0])

View file

@ -39,6 +39,7 @@ class Items(object):
self.kodiversion = int(xbmc.getInfoLabel("System.BuildVersion")[:2])
self.directpath = window('useDirectPaths') == 'true'
self.artwork = artwork.Artwork()
self.userid = window('currUserId')
self.server = window('pms_server')
@ -72,19 +73,19 @@ class Items(object):
API = PlexAPI.API(item)
if allartworks is None:
allartworks = API.getAllArtwork()
with artwork.Artwork('video') as art:
art.addArtwork(API.getFanartArtwork(allartworks),
kodiId,
mediaType)
self.artwork.addArtwork(API.getFanartArtwork(allartworks),
kodiId,
mediaType,
self.kodicursor)
# Also get artwork for collections/movie sets
if mediaType == 'movie':
for setname in API.getCollections():
log.debug('Getting artwork for movie set %s' % setname)
setid = self.kodi_db.createBoxset(setname)
with artwork.Artwork('video') as art:
art.addArtwork(API.getSetArtwork(),
setid,
"set")
self.artwork.addArtwork(API.getSetArtwork(),
setid,
"set",
self.kodicursor)
self.kodi_db.assignBoxset(setid, kodiId)
def itemsbyId(self, items, process, pdialog=None):
@ -308,6 +309,7 @@ class Movies(Items):
# Process single movie
kodicursor = self.kodicursor
emby_db = self.emby_db
artwork = self.artwork
API = PlexAPI.API(item)
# If the item already exist in the local Kodi DB we'll perform a full
@ -494,8 +496,7 @@ class Movies(Items):
# Process genres
self.kodi_db.addGenres(movieid, genres, "movie")
# Process artwork
with artwork.Artwork('video') as art:
art.addArtwork(API.getAllArtwork(), movieid, "movie")
artwork.addArtwork(API.getAllArtwork(), movieid, "movie", kodicursor)
# Process stream details
self.kodi_db.addStreams(fileid, API.getMediaStreams(), runtime)
# Process studios
@ -515,6 +516,8 @@ class Movies(Items):
# Remove movieid, fileid, emby reference
emby_db = self.emby_db
kodicursor = self.kodicursor
artwork = self.artwork
emby_dbitem = emby_db.getItem_byId(itemid)
try:
kodiid = emby_dbitem[0]
@ -528,8 +531,7 @@ class Movies(Items):
# Remove the emby reference
emby_db.removeItem(itemid)
# Remove artwork
with artwork.Artwork('video') as art:
art.deleteArtwork(kodiid, mediatype)
artwork.deleteArtwork(kodiid, mediatype, kodicursor)
if mediatype == "movie":
# Delete kodi movie and file
@ -559,6 +561,7 @@ class TVShows(Items):
# Process single tvshow
kodicursor = self.kodicursor
emby_db = self.emby_db
artwork = self.artwork
API = PlexAPI.API(item)
update_item = True
@ -716,8 +719,8 @@ class TVShows(Items):
# Process genres
self.kodi_db.addGenres(showid, genres, "tvshow")
# Process artwork
with artwork.Artwork('video') as art:
art.addArtwork(API.getAllArtwork(), showid, "tvshow")
allartworks = API.getAllArtwork()
artwork.addArtwork(allartworks, showid, "tvshow", kodicursor)
# Process studios
self.kodi_db.addStudios(showid, studios, "tvshow")
# Process tags: view, PMS collection tags
@ -740,6 +743,7 @@ class TVShows(Items):
return
kodicursor = self.kodicursor
emby_db = self.emby_db
artwork = self.artwork
seasonnum = API.getIndex()
# Get parent tv show Plex id
plexshowid = item.attrib.get('parentRatingKey')
@ -763,8 +767,8 @@ class TVShows(Items):
update_item = False
# Process artwork
with artwork.Artwork('video') as art:
art.addArtwork(API.getAllArtwork(), seasonid, "season")
allartworks = API.getAllArtwork()
artwork.addArtwork(allartworks, seasonid, "season", kodicursor)
if update_item:
# Update a reference: checksum in emby table
@ -786,6 +790,7 @@ class TVShows(Items):
# Process single episode
kodicursor = self.kodicursor
emby_db = self.emby_db
artwork = self.artwork
API = PlexAPI.API(item)
# If the item already exist in the local Kodi DB we'll perform a full
@ -1032,8 +1037,8 @@ class TVShows(Items):
if poster:
poster = API.addPlexCredentialsToUrl(
"%s%s" % (self.server, poster))
with artwork.Artwork('video') as art:
art.addOrUpdateArt(poster, episodeid, "episode", "thumb")
artwork.addOrUpdateArt(
poster, episodeid, "episode", "thumb", kodicursor)
# poster of TV show itself
# poster = item.attrib.get('grandparentThumb')
# if poster:
@ -1172,22 +1177,19 @@ class TVShows(Items):
def removeShow(self, kodiid):
kodicursor = self.kodicursor
with artwork.Artwork('video') as art:
art.deleteArtwork(kodiid, "tvshow")
self.artwork.deleteArtwork(kodiid, "tvshow", kodicursor)
kodicursor.execute("DELETE FROM tvshow WHERE idShow = ?", (kodiid,))
log.info("Removed tvshow: %s." % kodiid)
def removeSeason(self, kodiid):
kodicursor = self.kodicursor
with artwork.Artwork('video') as art:
art.deleteArtwork(kodiid, "season")
self.artwork.deleteArtwork(kodiid, "season", kodicursor)
kodicursor.execute("DELETE FROM seasons WHERE idSeason = ?", (kodiid,))
log.info("Removed season: %s." % kodiid)
def removeEpisode(self, kodiid, fileid):
kodicursor = self.kodicursor
with artwork.Artwork('video') as art:
art.deleteArtwork(kodiid, "episode")
self.artwork.deleteArtwork(kodiid, "episode", kodicursor)
kodicursor.execute("DELETE FROM episode WHERE idEpisode = ?", (kodiid,))
kodicursor.execute("DELETE FROM files WHERE idFile = ?", (fileid,))
log.info("Removed episode: %s." % kodiid)
@ -1222,6 +1224,7 @@ class Music(Items):
artisttype="MusicArtist"):
kodicursor = self.kodicursor
emby_db = self.emby_db
artwork = self.artwork
API = PlexAPI.API(item)
update_item = True
@ -1296,13 +1299,13 @@ class Music(Items):
dateadded, artistid))
# Update artwork
with artwork.Artwork('music') as art:
art.addArtwork(artworks, artistid, "artist")
artwork.addArtwork(artworks, artistid, "artist", kodicursor)
@CatchExceptions(warnuser=True)
def add_updateAlbum(self, item, viewtag=None, viewid=None):
kodicursor = self.kodicursor
emby_db = self.emby_db
artwork = self.artwork
API = PlexAPI.API(item)
update_item = True
@ -1485,14 +1488,14 @@ class Music(Items):
# Add genres
self.kodi_db.addMusicGenres(albumid, genres, "album")
# Update artwork
with artwork.Artwork('music') as art:
art.addArtwork(artworks, albumid, "album")
artwork.addArtwork(artworks, albumid, "album", kodicursor)
@CatchExceptions(warnuser=True)
def add_updateSong(self, item, viewtag=None, viewid=None):
# Process single song
kodicursor = self.kodicursor
emby_db = self.emby_db
artwork = self.artwork
API = PlexAPI.API(item)
update_item = True
@ -1818,14 +1821,12 @@ class Music(Items):
allart = API.getAllArtwork(parentInfo=True)
if hasEmbeddedCover:
allart["Primary"] = "image://music@" + artwork.single_urlencode( playurl )
with artwork.Artwork('music') as art:
art.addArtwork(allart, songid, "song")
artwork.addArtwork(allart, songid, "song", kodicursor)
# if item.get('AlbumId') is None:
if item.get('parentKey') is None:
# Update album artwork
with artwork.Artwork('music') as art:
art.addArtwork(allart, albumid, "album")
artwork.addArtwork(allart, albumid, "album", kodicursor)
def remove(self, itemid):
# Remove kodiid, fileid, pathid, emby reference
@ -1905,19 +1906,16 @@ class Music(Items):
log.info("Deleted %s: %s from kodi database" % (mediatype, itemid))
def removeSong(self, kodiid):
with artwork.Artwork('music') as art:
art.deleteArtwork(kodiid, "song")
self.artwork.deleteArtwork(kodiid, "song", self.kodicursor)
self.kodicursor.execute("DELETE FROM song WHERE idSong = ?",
(kodiid,))
def removeAlbum(self, kodiid):
with artwork.Artwork('music') as art:
art.deleteArtwork(kodiid, "album")
self.artwork.deleteArtwork(kodiid, "album", self.kodicursor)
self.kodicursor.execute("DELETE FROM album WHERE idAlbum = ?",
(kodiid,))
def removeArtist(self, kodiid):
with artwork.Artwork('music') as art:
art.deleteArtwork(kodiid, "artist")
self.artwork.deleteArtwork(kodiid, "artist", self.kodicursor)
self.kodicursor.execute("DELETE FROM artist WHERE idArtist = ?",
(kodiid,))

View file

@ -50,6 +50,7 @@ class Kodidb_Functions():
self.cursor = cursor
self.clientInfo = clientinfo.ClientInfo()
self.artwork = artwork.Artwork()
def pathHack(self):
"""
@ -505,8 +506,7 @@ class Kodidb_Functions():
if "writing" in arttype:
arttype = "writer"
with artwork.Artwork('video') as art:
art.addOrUpdateArt(thumb, actorid, arttype, "thumb")
self.artwork.addOrUpdateArt(thumb, actorid, arttype, "thumb", self.cursor)
def existingArt(self, kodiId, mediaType, refresh=False):
"""

View file

@ -11,6 +11,7 @@ import xbmc
import xbmcgui
import xbmcplugin
import artwork
import playutils as putils
import playlist
from utils import window, settings, tryEncode, tryDecode
@ -38,6 +39,7 @@ class PlaybackUtils():
self.userid = window('currUserId')
self.server = window('pms_server')
self.artwork = artwork.Artwork()
if self.API.getType() == 'track':
self.pl = playlist.Playlist(typus='music')
else: