diff --git a/src/calibre/ebooks/metadata/fetch.py b/src/calibre/ebooks/metadata/fetch.py index 36aec75853..f8631cf605 100644 --- a/src/calibre/ebooks/metadata/fetch.py +++ b/src/calibre/ebooks/metadata/fetch.py @@ -3,14 +3,14 @@ __license__ = 'GPL 3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import traceback, sys, textwrap, re, urllib2 +import traceback, sys, textwrap, re from threading import Thread -from calibre import prints, browser +from calibre import prints from calibre.utils.config import OptionParser from calibre.utils.logging import default_log from calibre.customize import Plugin -from calibre.ebooks.metadata.library_thing import OPENLIBRARY +from calibre.ebooks.metadata.library_thing import check_for_cover metadata_config = None @@ -271,16 +271,10 @@ def filter_metadata_results(item): return False return True -class HeadRequest(urllib2.Request): - def get_method(self): - return "HEAD" - def do_cover_check(item): - opener = browser() item.has_cover = False try: - opener.open(HeadRequest(OPENLIBRARY%item.isbn), timeout=5) - item.has_cover = True + item.has_cover = check_for_cover(item.isbn) except: pass # Cover not found diff --git a/src/calibre/ebooks/metadata/library_thing.py b/src/calibre/ebooks/metadata/library_thing.py index 3a78204e8e..97a8834300 100644 --- a/src/calibre/ebooks/metadata/library_thing.py +++ b/src/calibre/ebooks/metadata/library_thing.py @@ -14,6 +14,16 @@ from calibre.ebooks.BeautifulSoup import BeautifulSoup OPENLIBRARY = 'http://covers.openlibrary.org/b/isbn/%s-L.jpg?default=false' +def check_for_cover(isbn): + br = browser() + br.set_handle_redirect(False) + try: + br.open_novisit(OPENLIBRARY%isbn) + except Exception, e: + if callable(getattr(e, 'getcode', None)) and e.getcode() == 302: + return True + return False + class LibraryThingError(Exception): pass