Rename --cn-verfication-proxy to --geo-verification-proxy

And deprecate the former one

Since commit f138873900, this option is
not limited to China websites, so rename it.
This commit is contained in:
Yen Chi Hsuan 2016-07-03 23:23:48 +08:00
parent bf3ae6a543
commit 38cce791c7
No known key found for this signature in database
GPG Key ID: 3FDDD575826C5C30
10 changed files with 36 additions and 50 deletions

View File

@ -196,8 +196,8 @@ class YoutubeDL(object):
prefer_insecure: Use HTTP instead of HTTPS to retrieve information. prefer_insecure: Use HTTP instead of HTTPS to retrieve information.
At the moment, this is only supported by YouTube. At the moment, this is only supported by YouTube.
proxy: URL of the proxy server to use proxy: URL of the proxy server to use
cn_verification_proxy: URL of the proxy to use for IP address verification geo_verification_proxy: URL of the proxy to use for IP address verification
on Chinese sites. (Experimental) on geo-restricted sites. (Experimental)
socket_timeout: Time to wait for unresponsive hosts, in seconds socket_timeout: Time to wait for unresponsive hosts, in seconds
bidi_workaround: Work around buggy terminals without bidirectional text bidi_workaround: Work around buggy terminals without bidirectional text
support, using fridibi support, using fridibi
@ -304,6 +304,11 @@ def __init__(self, params=None, auto_init=True):
self.params.update(params) self.params.update(params)
self.cache = Cache(self) self.cache = Cache(self)
if self.params.get('cn_verification_proxy') is not None:
self.report_warning('--cn-verification-proxy is deprecated. Use --geo-verification-proxy instead.')
if self.params.get('geo_verification_proxy') is None:
self.params['geo_verification_proxy'] = self.params['cn_verification_proxy']
if params.get('bidi_workaround', False): if params.get('bidi_workaround', False):
try: try:
import pty import pty

View File

@ -382,6 +382,8 @@ def parse_retries(retries):
'external_downloader_args': external_downloader_args, 'external_downloader_args': external_downloader_args,
'postprocessor_args': postprocessor_args, 'postprocessor_args': postprocessor_args,
'cn_verification_proxy': opts.cn_verification_proxy, 'cn_verification_proxy': opts.cn_verification_proxy,
'geo_verification_proxy': opts.geo_verification_proxy,
} }
with YoutubeDL(ydl_opts) as ydl: with YoutubeDL(ydl_opts) as ydl:

View File

@ -1729,6 +1729,13 @@ def mark_watched(self, *args, **kwargs):
def _mark_watched(self, *args, **kwargs): def _mark_watched(self, *args, **kwargs):
raise NotImplementedError('This method must be implemented by subclasses') raise NotImplementedError('This method must be implemented by subclasses')
def geo_verification_headers(self):
headers = {}
geo_verification_proxy = self._downloader.params.get('geo_verification_proxy')
if geo_verification_proxy:
headers['Ytdl-request-proxy'] = geo_verification_proxy
return headers
class SearchInfoExtractor(InfoExtractor): class SearchInfoExtractor(InfoExtractor):
""" """

View File

@ -293,14 +293,10 @@ def get_raw_data(self, tvid, video_id):
't': tm, 't': tm,
} }
headers = {}
cn_verification_proxy = self._downloader.params.get('cn_verification_proxy')
if cn_verification_proxy:
headers['Ytdl-request-proxy'] = cn_verification_proxy
return self._download_json( return self._download_json(
'http://cache.m.iqiyi.com/jp/tmts/%s/%s/' % (tvid, video_id), 'http://cache.m.iqiyi.com/jp/tmts/%s/%s/' % (tvid, video_id),
video_id, transform_source=lambda s: remove_start(s, 'var tvInfoJs='), video_id, transform_source=lambda s: remove_start(s, 'var tvInfoJs='),
query=params, headers=headers) query=params, headers=self.geo_verification_headers())
def _extract_playlist(self, webpage): def _extract_playlist(self, webpage):
PAGE_SIZE = 50 PAGE_SIZE = 50

View File

@ -26,11 +26,6 @@ class KuwoBaseIE(InfoExtractor):
def _get_formats(self, song_id, tolerate_ip_deny=False): def _get_formats(self, song_id, tolerate_ip_deny=False):
formats = [] formats = []
for file_format in self._FORMATS: for file_format in self._FORMATS:
headers = {}
cn_verification_proxy = self._downloader.params.get('cn_verification_proxy')
if cn_verification_proxy:
headers['Ytdl-request-proxy'] = cn_verification_proxy
query = { query = {
'format': file_format['ext'], 'format': file_format['ext'],
'br': file_format.get('br', ''), 'br': file_format.get('br', ''),
@ -42,7 +37,7 @@ def _get_formats(self, song_id, tolerate_ip_deny=False):
song_url = self._download_webpage( song_url = self._download_webpage(
'http://antiserver.kuwo.cn/anti.s', 'http://antiserver.kuwo.cn/anti.s',
song_id, note='Download %s url info' % file_format['format'], song_id, note='Download %s url info' % file_format['format'],
query=query, headers=headers, query=query, headers=self.geo_verification_headers(),
) )
if song_url == 'IPDeny' and not tolerate_ip_deny: if song_url == 'IPDeny' and not tolerate_ip_deny:

View File

@ -20,7 +20,6 @@
int_or_none, int_or_none,
orderedSet, orderedSet,
parse_iso8601, parse_iso8601,
sanitized_Request,
str_or_none, str_or_none,
url_basename, url_basename,
urshift, urshift,
@ -121,16 +120,11 @@ def _real_extract(self, url):
'tkey': self.calc_time_key(int(time.time())), 'tkey': self.calc_time_key(int(time.time())),
'domain': 'www.le.com' 'domain': 'www.le.com'
} }
play_json_req = sanitized_Request(
'http://api.le.com/mms/out/video/playJson?' + compat_urllib_parse_urlencode(params)
)
cn_verification_proxy = self._downloader.params.get('cn_verification_proxy')
if cn_verification_proxy:
play_json_req.add_header('Ytdl-request-proxy', cn_verification_proxy)
play_json = self._download_json( play_json = self._download_json(
play_json_req, 'http://api.le.com/mms/out/video/playJson',
media_id, 'Downloading playJson data') media_id, 'Downloading playJson data', query=params,
headers=self.geo_verification_headers())
# Check for errors # Check for errors
playstatus = play_json['playstatus'] playstatus = play_json['playstatus']

View File

@ -20,17 +20,12 @@ def _extract_relinker_formats(self, relinker_url, video_id):
formats = [] formats = []
for platform in ('mon', 'flash', 'native'): for platform in ('mon', 'flash', 'native'):
headers = {}
# TODO: rename --cn-verification-proxy
cn_verification_proxy = self._downloader.params.get('cn_verification_proxy')
if cn_verification_proxy:
headers['Ytdl-request-proxy'] = cn_verification_proxy
relinker = self._download_xml( relinker = self._download_xml(
relinker_url, video_id, relinker_url, video_id,
note='Downloading XML metadata for platform %s' % platform, note='Downloading XML metadata for platform %s' % platform,
transform_source=fix_xml_ampersands, transform_source=fix_xml_ampersands,
query={'output': 45, 'pl': platform}, headers=headers) query={'output': 45, 'pl': platform},
headers=self.geo_verification_headers())
media_url = find_xpath_attr(relinker, './url', 'type', 'content').text media_url = find_xpath_attr(relinker, './url', 'type', 'content').text
if media_url == 'http://download.rai.it/video_no_available.mp4': if media_url == 'http://download.rai.it/video_no_available.mp4':

View File

@ -8,10 +8,7 @@
compat_str, compat_str,
compat_urllib_parse_urlencode, compat_urllib_parse_urlencode,
) )
from ..utils import ( from ..utils import ExtractorError
ExtractorError,
sanitized_Request,
)
class SohuIE(InfoExtractor): class SohuIE(InfoExtractor):
@ -96,15 +93,10 @@ def _fetch_data(vid_id, mytv=False):
else: else:
base_data_url = 'http://hot.vrs.sohu.com/vrs_flash.action?vid=' base_data_url = 'http://hot.vrs.sohu.com/vrs_flash.action?vid='
req = sanitized_Request(base_data_url + vid_id)
cn_verification_proxy = self._downloader.params.get('cn_verification_proxy')
if cn_verification_proxy:
req.add_header('Ytdl-request-proxy', cn_verification_proxy)
return self._download_json( return self._download_json(
req, video_id, base_data_url + vid_id, video_id,
'Downloading JSON data for %s' % vid_id) 'Downloading JSON data for %s' % vid_id,
headers=self.geo_verification_headers())
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id') video_id = mobj.group('id')

View File

@ -16,7 +16,6 @@
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
get_element_by_attribute, get_element_by_attribute,
sanitized_Request,
) )
@ -218,14 +217,10 @@ def retrieve_data(req_url, note):
headers = { headers = {
'Referer': req_url, 'Referer': req_url,
} }
headers.update(self.geo_verification_headers())
self._set_cookie('youku.com', 'xreferrer', 'http://www.youku.com') self._set_cookie('youku.com', 'xreferrer', 'http://www.youku.com')
req = sanitized_Request(req_url, headers=headers)
cn_verification_proxy = self._downloader.params.get('cn_verification_proxy') raw_data = self._download_json(req_url, video_id, note=note, headers=headers)
if cn_verification_proxy:
req.add_header('Ytdl-request-proxy', cn_verification_proxy)
raw_data = self._download_json(req, video_id, note=note)
return raw_data['data'] return raw_data['data']

View File

@ -209,11 +209,16 @@ def _hide_login_info(opts):
action='store_const', const='::', dest='source_address', action='store_const', const='::', dest='source_address',
help='Make all connections via IPv6 (experimental)', help='Make all connections via IPv6 (experimental)',
) )
network.add_option(
'--geo-verification-proxy',
dest='geo_verification_proxy', default=None, metavar='URL',
help='Use this proxy to verify the IP address for some geo-restricted sites. '
'The default proxy specified by --proxy (or none, if the options is not present) is used for the actual downloading. (experimental)'
)
network.add_option( network.add_option(
'--cn-verification-proxy', '--cn-verification-proxy',
dest='cn_verification_proxy', default=None, metavar='URL', dest='cn_verification_proxy', default=None, metavar='URL',
help='Use this proxy to verify the IP address for some Chinese sites. ' help=optparse.SUPPRESS_HELP,
'The default proxy specified by --proxy (or none, if the options is not present) is used for the actual downloading. (experimental)'
) )
selection = optparse.OptionGroup(parser, 'Video Selection') selection = optparse.OptionGroup(parser, 'Video Selection')