mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
More efficient cover checking
This commit is contained in:
parent
ffd3b62049
commit
b2f16f291e
@ -3,14 +3,14 @@ __license__ = 'GPL 3'
|
||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user