diff --git a/headphones/albumart.py b/headphones/albumart.py index 37147be3..3b80e5f5 100644 --- a/headphones/albumart.py +++ b/headphones/albumart.py @@ -23,3 +23,21 @@ def getAlbumArt(albumid): url = 'http://ec1.images-amazon.com/images/P/%s.01.LZZZZZZZ.jpg' % asin return url + +def getCachedArt(albumid): + + from headphones import cache + + c = cache.Cache() + + artwork_path = c.get_artwork_from_cache(AlbumID=albumid) + + if not artwork_path: + return None + + if artwork_path.startswith('http://'): + artwork = urllib.urlopen(artwork_path).read() + return artwork + else: + artwork = open(artwork_path, "r").read() + return artwork diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 309d613d..6f275716 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -13,8 +13,11 @@ # You should have received a copy of the GNU General Public License # along with Headphones. If not, see . +from __future__ import with_statement + import os import time +import threading import music_encoder import urllib, shutil, re from headphones import notifiers @@ -235,8 +238,11 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list) if headphones.EMBED_ALBUM_ART or headphones.ADD_ALBUM_ART: artwork = urllib.urlopen(album_art_path).read() if len(artwork) < 100: - artwork = False - logger.info("No suitable album art found. Not adding album art") + logger.info("No suitable album art found from Amazon. Checking Last.FM....") + artwork = albumart.getCachedArt(albumid) + if len(artwork) < 100: + artwork = False + logger.info("No suitable album art found from Last.FM. Not adding album art") if headphones.EMBED_ALBUM_ART and artwork: embedAlbumArt(artwork, downloaded_track_list)