From 9ccb0f85dc109cbb105690dd9cccd296aa29f9ba Mon Sep 17 00:00:00 2001 From: Ade Date: Sat, 11 Mar 2017 12:19:53 +1300 Subject: [PATCH] Use CAA artwork for post processing Preference is: CAA Amazon last.fm --- headphones/albumart.py | 56 +++++++++++++++++++++++++++++++++++-- headphones/postprocessor.py | 20 +++++-------- 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/headphones/albumart.py b/headphones/albumart.py index 8bbbd425..803d469a 100644 --- a/headphones/albumart.py +++ b/headphones/albumart.py @@ -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): diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 9a7a4e9c..39393e58 100755 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -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)