[extractors] Use http_headers for setting the User-Agent and the Referer

This commit is contained in:
Jaime Marquínez Ferrándiz 2015-01-24 18:19:58 +01:00
parent 3fcfb8e9fa
commit e1554a407d
5 changed files with 9 additions and 8 deletions

View file

@ -24,10 +24,6 @@ def real_download(self, filename, info_dict):
# Do not include the Accept-Encoding header # Do not include the Accept-Encoding header
headers = {'Youtubedl-no-compression': 'True'} headers = {'Youtubedl-no-compression': 'True'}
if 'user_agent' in info_dict:
headers['User-agent'] = info_dict['user_agent']
if 'http_referer' in info_dict:
headers['Referer'] = info_dict['http_referer']
add_headers = info_dict.get('http_headers') add_headers = info_dict.get('http_headers')
if add_headers: if add_headers:
headers.update(add_headers) headers.update(add_headers)

View file

@ -129,7 +129,9 @@ def _clean_json(m):
'thumbnail': thumbnail, 'thumbnail': thumbnail,
'upload_date': upload_date, 'upload_date': upload_date,
'uploader_id': uploader_id, 'uploader_id': uploader_id,
'user_agent': 'QuickTime compatible (youtube-dl)', 'http_headers': {
'User-Agent': 'QuickTime compatible (youtube-dl)',
},
}) })
return { return {

View file

@ -108,7 +108,6 @@ class InfoExtractor(object):
(quality takes higher priority) (quality takes higher priority)
-1 for default (order by other properties), -1 for default (order by other properties),
-2 or smaller for less than default. -2 or smaller for less than default.
* http_referer HTTP Referer header value to set.
* http_method HTTP method to use for the download. * http_method HTTP method to use for the download.
* http_headers A dictionary of additional HTTP headers * http_headers A dictionary of additional HTTP headers
to add to the request. to add to the request.

View file

@ -62,5 +62,7 @@ def _real_extract(self, url):
'title': title, 'title': title,
'formats': formats, 'formats': formats,
'thumbnail': thumbnail, 'thumbnail': thumbnail,
'http_referer': iframe_url, 'http_headers': {
'Referer': iframe_url,
},
} }

View file

@ -169,7 +169,9 @@ def _real_extract(self, url):
'title': mobj.group('title'), 'title': mobj.group('title'),
'age_limit': int(mobj.group('age_limit')), 'age_limit': int(mobj.group('age_limit')),
'url': url, 'url': url,
'user_agent': 'mobile', 'http_headers': {
'User-Agent': 'mobile',
},
} }