# -*- coding: latin1 -*- # Copyright (c) 2003,2004 Guilherme Salgado # All rights reserved. # # This file is part of coverhunter. # # coverhunter is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # coverhunter is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with coverhunter; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Author: Guilherme Salgado # This library is heavily based on the albumart.py module, written by Sami # Kyöstilä . # import amazon, config def setup_sources(): token = config.get_amazon_token() if token: amazon.setLicense(token) setup_sources() class Source: """A virtual base class that defines an album cover source.""" def find_album(self, artist, album): """Return a list of matches for the given search string.""" pass class Amazon(Source): """Amazon.com album cover source.""" def find_album(self, artist, album): try: if artist is None and album is not None: return amazon.searchByKeyword(album, type="lite", product_line="music") elif album is None and artist is not None: return amazon.searchByArtist(artist, type="lite") else: return amazon.searchByKeyword("%s %s" % (artist, album), type="lite", product_line="music") except amazon.AmazonError: pass # the sources to be used sources = [Amazon] class AlbumSearch: def find(self, album): for src in sources: s = src() results = [] try: results += s.find_album(album.artist, album.name) except TypeError: try: results += s.find_album(None, album.name) except TypeError: try: results += s.find_album(album.artist, None) except TypeError: pass for cover in results: yield cover