mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -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>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import traceback, sys, textwrap, re, urllib2
|
import traceback, sys, textwrap, re
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from calibre import prints, browser
|
from calibre import prints
|
||||||
from calibre.utils.config import OptionParser
|
from calibre.utils.config import OptionParser
|
||||||
from calibre.utils.logging import default_log
|
from calibre.utils.logging import default_log
|
||||||
from calibre.customize import Plugin
|
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
|
metadata_config = None
|
||||||
|
|
||||||
@ -271,16 +271,10 @@ def filter_metadata_results(item):
|
|||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
class HeadRequest(urllib2.Request):
|
|
||||||
def get_method(self):
|
|
||||||
return "HEAD"
|
|
||||||
|
|
||||||
def do_cover_check(item):
|
def do_cover_check(item):
|
||||||
opener = browser()
|
|
||||||
item.has_cover = False
|
item.has_cover = False
|
||||||
try:
|
try:
|
||||||
opener.open(HeadRequest(OPENLIBRARY%item.isbn), timeout=5)
|
item.has_cover = check_for_cover(item.isbn)
|
||||||
item.has_cover = True
|
|
||||||
except:
|
except:
|
||||||
pass # Cover not found
|
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'
|
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):
|
class LibraryThingError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user