From f8ccde455908393e211153871cd6eae0c0d4b492 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Wed, 18 Jul 2012 18:33:20 +0530 Subject: [PATCH 1/4] Fixed import for postprocessor threading --- headphones/postprocessor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index 309d613d..b4363d0f 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 From 5bb0c016545a73062f29682df9623bda6566fcb2 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Wed, 18 Jul 2012 18:46:09 +0530 Subject: [PATCH 2/4] Check cache/last.fm for album art --- headphones/postprocessor.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/headphones/postprocessor.py b/headphones/postprocessor.py index b4363d0f..602ee4fc 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 +from headphones import db, albumart, lyrics, logger, helpers, cache postprocessor_lock = threading.Lock() @@ -238,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 = urllib.urlopen(cache.getArtwork(AlbumID=albumid)).read() + 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) From 158f33845ba84ffc7670877d1765b5e87f4a701b Mon Sep 17 00:00:00 2001 From: rembo10 Date: Wed, 18 Jul 2012 18:59:09 +0530 Subject: [PATCH 3/4] 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") From 22c807ddbb1bc5e76b8f8b12c2555be933d17711 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Wed, 18 Jul 2012 19:02:33 +0530 Subject: [PATCH 4/4] Fix for circular import --- headphones/albumart.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/headphones/albumart.py b/headphones/albumart.py index 88a2b416..3b80e5f5 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, cache +from headphones import db def getAlbumArt(albumid): @@ -26,7 +26,10 @@ def getAlbumArt(albumid): def getCachedArt(albumid): - c = Cache() + from headphones import cache + + c = cache.Cache() + artwork_path = c.get_artwork_from_cache(AlbumID=albumid) if not artwork_path: