mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-05 08:40:13 -04:00
When downloading metadata use the gzip transfer encoding when possible for a speedup. Fixes #749304 (metadata from google books not readable)
This commit is contained in:
parent
ac3693cfdc
commit
daa0150044
@ -193,6 +193,7 @@ class ResultList(list):
|
|||||||
def search(title=None, author=None, publisher=None, isbn=None,
|
def search(title=None, author=None, publisher=None, isbn=None,
|
||||||
min_viewability='none', verbose=False, max_results=40):
|
min_viewability='none', verbose=False, max_results=40):
|
||||||
br = browser()
|
br = browser()
|
||||||
|
br.set_handle_gzip(True)
|
||||||
start, entries = 1, []
|
start, entries = 1, []
|
||||||
while start > 0 and len(entries) <= max_results:
|
while start > 0 and len(entries) <= max_results:
|
||||||
new, start = Query(title=title, author=author, publisher=publisher,
|
new, start = Query(title=title, author=author, publisher=publisher,
|
||||||
|
@ -283,6 +283,7 @@ class Amazon(Source):
|
|||||||
touched_fields = frozenset(['title', 'authors', 'identifier:amazon',
|
touched_fields = frozenset(['title', 'authors', 'identifier:amazon',
|
||||||
'identifier:isbn', 'rating', 'comments', 'publisher', 'pubdate'])
|
'identifier:isbn', 'rating', 'comments', 'publisher', 'pubdate'])
|
||||||
has_html_comments = True
|
has_html_comments = True
|
||||||
|
supports_gzip_transfer_encoding = True
|
||||||
|
|
||||||
AMAZON_DOMAINS = {
|
AMAZON_DOMAINS = {
|
||||||
'com': _('US'),
|
'com': _('US'),
|
||||||
|
@ -111,6 +111,12 @@ class Source(Plugin):
|
|||||||
#: Set this to True if your plugin return HTML formatted comments
|
#: Set this to True if your plugin return HTML formatted comments
|
||||||
has_html_comments = False
|
has_html_comments = False
|
||||||
|
|
||||||
|
#: Setting this to True means that the browser object will add
|
||||||
|
#: Accept-Encoding: gzip to all requests. This can speedup downloads
|
||||||
|
#: but make sure that the source actually supports gzip transfer encoding
|
||||||
|
#: correctly first
|
||||||
|
supports_gzip_transfer_encoding = False
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
Plugin.__init__(self, *args, **kwargs)
|
Plugin.__init__(self, *args, **kwargs)
|
||||||
self._isbn_to_identifier_cache = {}
|
self._isbn_to_identifier_cache = {}
|
||||||
@ -134,6 +140,8 @@ class Source(Plugin):
|
|||||||
def browser(self):
|
def browser(self):
|
||||||
if self._browser is None:
|
if self._browser is None:
|
||||||
self._browser = browser(user_agent=random_user_agent())
|
self._browser = browser(user_agent=random_user_agent())
|
||||||
|
if self.supports_gzip_transfer_encoding:
|
||||||
|
self._browser.set_handle_gzip(True)
|
||||||
return self._browser.clone_browser()
|
return self._browser.clone_browser()
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -160,6 +160,7 @@ class GoogleBooks(Source):
|
|||||||
touched_fields = frozenset(['title', 'authors', 'tags', 'pubdate',
|
touched_fields = frozenset(['title', 'authors', 'tags', 'pubdate',
|
||||||
'comments', 'publisher', 'identifier:isbn', 'rating',
|
'comments', 'publisher', 'identifier:isbn', 'rating',
|
||||||
'identifier:google']) # language currently disabled
|
'identifier:google']) # language currently disabled
|
||||||
|
supports_gzip_transfer_encoding = True
|
||||||
|
|
||||||
GOOGLE_COVER = 'http://books.google.com/books?id=%s&printsec=frontcover&img=1'
|
GOOGLE_COVER = 'http://books.google.com/books?id=%s&printsec=frontcover&img=1'
|
||||||
|
|
||||||
|
@ -38,10 +38,10 @@ class Browser(B):
|
|||||||
self._clone_actions['set_handle_equiv'] = ('set_handle_equiv',
|
self._clone_actions['set_handle_equiv'] = ('set_handle_equiv',
|
||||||
args, kwargs)
|
args, kwargs)
|
||||||
|
|
||||||
def set_handle_gzip(self, *args, **kwargs):
|
def set_handle_gzip(self, handle):
|
||||||
B.set_handle_gzip(self, *args, **kwargs)
|
self._set_handler('_gzip', handle)
|
||||||
self._clone_actions['set_handle_gzip'] = ('set_handle_gzip',
|
self._clone_actions['set_handle_gzip'] = ('set_handle_gzip',
|
||||||
args, kwargs)
|
(handle,), {})
|
||||||
|
|
||||||
def set_debug_redirect(self, *args, **kwargs):
|
def set_debug_redirect(self, *args, **kwargs):
|
||||||
B.set_debug_redirect(self, *args, **kwargs)
|
B.set_debug_redirect(self, *args, **kwargs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user