From 158f33845ba84ffc7670877d1765b5e87f4a701b Mon Sep 17 00:00:00 2001 From: rembo10 Date: Wed, 18 Jul 2012 18:59:09 +0530 Subject: [PATCH] Fixed path for getting cached album art in postprocessor --- headphones/albumart.py | 17 ++++++++++++++++- headphones/postprocessor.py | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/headphones/albumart.py b/headphones/albumart.py index 37147be3..88a2b416 100644 --- a/headphones/albumart.py +++ b/headphones/albumart.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with Headphones. If not, see . -from headphones import db +from headphones import db, cache def getAlbumArt(albumid): @@ -23,3 +23,18 @@ def getAlbumArt(albumid): url = 'http://ec1.images-amazon.com/images/P/%s.01.LZZZZZZZ.jpg' % asin return url + +def getCachedArt(albumid): + + c = 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 602ee4fc..6f275716 100644 --- a/headphones/postprocessor.py +++ b/headphones/postprocessor.py @@ -26,7 +26,7 @@ from lib.beets import autotag from lib.beets.mediafile import MediaFile import headphones -from headphones import db, albumart, lyrics, logger, helpers, cache +from headphones import db, albumart, lyrics, logger, helpers postprocessor_lock = threading.Lock() @@ -239,7 +239,7 @@ def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list) artwork = urllib.urlopen(album_art_path).read() if len(artwork) < 100: logger.info("No suitable album art found from Amazon. Checking Last.FM....") - artwork = urllib.urlopen(cache.getArtwork(AlbumID=albumid)).read() + artwork = albumart.getCachedArt(albumid) if len(artwork) < 100: artwork = False logger.info("No suitable album art found from Last.FM. Not adding album art")