Use an up-to-date UA when downloading news

This commit is contained in:
Kovid Goyal 2020-12-27 12:56:45 +05:30
parent e0ec185ea2
commit 0e19f6a399
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 4 additions and 2 deletions

View File

@ -529,8 +529,8 @@ class BasicNewsRecipe(Recipe):
'''
if 'user_agent' not in kwargs:
# More and more news sites are serving JPEG XR images to IE
kwargs['user_agent'] = self.last_used_user_agent = getattr(
self, 'last_used_user_agent', None) or random_user_agent(allow_ie=False)
ua = getattr(self, 'last_used_user_agent', None) or self.calibre_most_common_ua or random_user_agent(allow_ie=False)
kwargs['user_agent'] = self.last_used_user_agent = ua
self.log('Using user agent:', kwargs['user_agent'])
br = browser(*args, **kwargs)
br.addheaders += [('Accept', '*/*')]

View File

@ -51,10 +51,12 @@ def compile_recipe(src):
'xrange': range,
}
exec(src, namespace)
ua = namespace.get('calibre_most_common_ua')
for x in itervalues(namespace):
if (isinstance(x, type) and issubclass(x, BasicNewsRecipe) and x not
in basic_recipes):
x.calibre_most_common_ua = ua
return x
return None