mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use an up-to-date UA when downloading news
This commit is contained in:
parent
e0ec185ea2
commit
0e19f6a399
@ -529,8 +529,8 @@ class BasicNewsRecipe(Recipe):
|
|||||||
'''
|
'''
|
||||||
if 'user_agent' not in kwargs:
|
if 'user_agent' not in kwargs:
|
||||||
# More and more news sites are serving JPEG XR images to IE
|
# More and more news sites are serving JPEG XR images to IE
|
||||||
kwargs['user_agent'] = self.last_used_user_agent = getattr(
|
ua = getattr(self, 'last_used_user_agent', None) or self.calibre_most_common_ua or random_user_agent(allow_ie=False)
|
||||||
self, 'last_used_user_agent', None) or random_user_agent(allow_ie=False)
|
kwargs['user_agent'] = self.last_used_user_agent = ua
|
||||||
self.log('Using user agent:', kwargs['user_agent'])
|
self.log('Using user agent:', kwargs['user_agent'])
|
||||||
br = browser(*args, **kwargs)
|
br = browser(*args, **kwargs)
|
||||||
br.addheaders += [('Accept', '*/*')]
|
br.addheaders += [('Accept', '*/*')]
|
||||||
|
@ -51,10 +51,12 @@ def compile_recipe(src):
|
|||||||
'xrange': range,
|
'xrange': range,
|
||||||
}
|
}
|
||||||
exec(src, namespace)
|
exec(src, namespace)
|
||||||
|
ua = namespace.get('calibre_most_common_ua')
|
||||||
|
|
||||||
for x in itervalues(namespace):
|
for x in itervalues(namespace):
|
||||||
if (isinstance(x, type) and issubclass(x, BasicNewsRecipe) and x not
|
if (isinstance(x, type) and issubclass(x, BasicNewsRecipe) and x not
|
||||||
in basic_recipes):
|
in basic_recipes):
|
||||||
|
x.calibre_most_common_ua = ua
|
||||||
return x
|
return x
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user