mirror of
https://github.com/rembo10/headphones.git
synced 2026-03-21 12:19:27 +00:00
Use CAA artwork for post processing
Preference is: CAA Amazon last.fm
This commit is contained in:
@@ -17,12 +17,64 @@ from headphones import request, db, logger
|
||||
|
||||
|
||||
def getAlbumArt(albumid):
|
||||
|
||||
artwork_path = None
|
||||
artwork = None
|
||||
|
||||
# CAA
|
||||
artwork_path = 'http://coverartarchive.org/release-group/%s/front' % albumid
|
||||
artwork = request.request_content(artwork_path, timeout=20)
|
||||
if artwork and len(artwork) >= 100:
|
||||
logger.info("Artwork found at CAA")
|
||||
return artwork_path, artwork
|
||||
|
||||
# Amazon
|
||||
myDB = db.DBConnection()
|
||||
asin = myDB.action(
|
||||
'SELECT AlbumASIN from albums WHERE AlbumID=?', [albumid]).fetchone()[0]
|
||||
|
||||
if asin:
|
||||
return 'http://ec1.images-amazon.com/images/P/%s.01.LZZZZZZZ.jpg' % asin
|
||||
artwork_path = 'http://ec1.images-amazon.com/images/P/%s.01.LZZZZZZZ.jpg' % asin
|
||||
artwork = request.request_content(artwork_path, timeout=20)
|
||||
if artwork and len(artwork) >= 100:
|
||||
logger.info("Artwork found at Amazon")
|
||||
return artwork_path, artwork
|
||||
|
||||
# last.fm
|
||||
from headphones import lastfm
|
||||
|
||||
myDB = db.DBConnection()
|
||||
dbalbum = myDB.action(
|
||||
'SELECT ArtistName, AlbumTitle, ReleaseID FROM albums WHERE AlbumID=?',
|
||||
[albumid]).fetchone()
|
||||
if dbalbum['ReleaseID'] != albumid:
|
||||
data = lastfm.request_lastfm("album.getinfo", mbid=dbalbum['ReleaseID'])
|
||||
if not data:
|
||||
data = lastfm.request_lastfm("album.getinfo", artist=dbalbum['ArtistName'],
|
||||
album=dbalbum['AlbumTitle'])
|
||||
else:
|
||||
data = lastfm.request_lastfm("album.getinfo", artist=dbalbum['ArtistName'],
|
||||
album=dbalbum['AlbumTitle'])
|
||||
|
||||
if data:
|
||||
try:
|
||||
images = data['album']['image']
|
||||
for image in images:
|
||||
if image['size'] == 'extralarge':
|
||||
artwork_path = image['#text']
|
||||
elif image['size'] == 'mega':
|
||||
artwork_path = image['#text']
|
||||
break
|
||||
except KeyError:
|
||||
artwork_path = None
|
||||
|
||||
if artwork_path:
|
||||
artwork = request.request_content(artwork_path, timeout=20)
|
||||
if artwork and len(artwork) >= 100:
|
||||
logger.info("Artwork found at last.fm")
|
||||
return artwork_path, artwork
|
||||
|
||||
logger.info("No suitable album art found.")
|
||||
return None, None
|
||||
|
||||
|
||||
def getCachedArt(albumid):
|
||||
|
||||
@@ -410,21 +410,15 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list,
|
||||
shutil.rmtree(new_folder)
|
||||
return
|
||||
|
||||
# get artwork and path
|
||||
album_art_path = None
|
||||
artwork = None
|
||||
album_art_path = albumart.getAlbumArt(albumid)
|
||||
if headphones.CONFIG.EMBED_ALBUM_ART or headphones.CONFIG.ADD_ALBUM_ART:
|
||||
if headphones.CONFIG.EMBED_ALBUM_ART or headphones.CONFIG.ADD_ALBUM_ART or \
|
||||
(headphones.CONFIG.PLEX_ENABLED and headphones.CONFIG.PLEX_NOTIFY) or \
|
||||
(headphones.CONFIG.XBMC_ENABLED and CONFIG.XBMC_NOTIFY):
|
||||
|
||||
if album_art_path:
|
||||
artwork = request.request_content(album_art_path)
|
||||
else:
|
||||
artwork = None
|
||||
|
||||
if not album_art_path or not artwork or len(artwork) < 100:
|
||||
logger.info("No suitable album art found from Amazon. Checking Last.FM....")
|
||||
artwork = albumart.getCachedArt(albumid)
|
||||
if not artwork or len(artwork) < 100:
|
||||
artwork = False
|
||||
logger.info("No suitable album art found from Last.FM. Not adding album art")
|
||||
logger.info('Searching for artwork')
|
||||
album_art_path, artwork = albumart.getAlbumArt(albumid)
|
||||
|
||||
if headphones.CONFIG.EMBED_ALBUM_ART and artwork:
|
||||
embedAlbumArt(artwork, downloaded_track_list)
|
||||
|
||||
Reference in New Issue
Block a user