This commit is contained in:
bato3 2020-09-26 01:18:03 -05:00 committed by GitHub
commit 03f64a9fcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -107,6 +107,7 @@ from .postprocessor import (
FFmpegPostProcessor,
get_postprocessor,
)
from .options import hide_url_login_info
from .version import __version__
if compat_os_name == 'nt':
@ -2300,7 +2301,7 @@ class YoutubeDL(object):
for handler in self._opener.handlers:
if hasattr(handler, 'proxies'):
proxy_map.update(handler.proxies)
self._write_string('[debug] Proxy map: ' + compat_str(proxy_map) + '\n')
self._write_string('[debug] Proxy map: ' + hide_url_login_info(compat_str(proxy_map)) + '\n')
if self.params.get('call_home', False):
ipaddr = self.urlopen('https://yt-dl.org/ip').read().decode('utf-8')

View File

@ -20,21 +20,37 @@ from .utils import (
from .version import __version__
def hide_url_login_info(url):
return re.sub(
r'((?:http|socks5)s?://)(?:(?:[^:@]+:)?[^@]+)(@)',
r'\1PRIVATE\2', url)
def _hide_login_info(opts):
PRIVATE_OPTS = set(['-p', '--password', '-u', '--username', '--video-password', '--ap-password', '--ap-username'])
URL_PRIVATE_OPTS = set(['--proxy', '--geo-verification-proxy'])
eqre = re.compile('^(?P<key>' + ('|'.join(re.escape(po) for po in PRIVATE_OPTS)) + ')=.+$')
equre = re.compile('^(?P<key>' + ('|'.join(re.escape(po) for po in URL_PRIVATE_OPTS)) + ')=(?P<url>.+)$')
def _scrub_eq(o):
m = eqre.match(o)
if m:
return m.group('key') + '=PRIVATE'
else:
return o
m = equre.match(o)
if m:
return m.group('key') + '=' + hide_url_login_info(m.group('url'))
else:
return o
opts = list(map(_scrub_eq, opts))
for idx, opt in enumerate(opts):
if opt in PRIVATE_OPTS and idx + 1 < len(opts):
opts[idx + 1] = 'PRIVATE'
else:
if opt in URL_PRIVATE_OPTS and idx + 1 < len(opts):
opts[idx + 1] = hide_url_login_info(opts[idx + 1])
return opts