From 408fcb89faf37edd28603ea6821e92c885d60b49 Mon Sep 17 00:00:00 2001 From: bato3 Date: Sun, 29 Jul 2018 02:09:01 +0200 Subject: [PATCH] Remove only login credintails from options --- youtube_dl/YoutubeDL.py | 6 ++---- youtube_dl/options.py | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index b21daadff..c0d269f6d 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -104,6 +104,7 @@ from .postprocessor import ( FFmpegPostProcessor, get_postprocessor, ) +from .options import hide_url_login_info from .version import __version__ if compat_os_name == 'nt': @@ -2273,10 +2274,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: ' + re.sub( - r'((?:http|socks5)s?://)(?:(?:[^:@]+:)?[^@]+)(@)', - r'\1PRIVATE\2', - 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') diff --git a/youtube_dl/options.py b/youtube_dl/options.py index f11bf13df..0c90b6dd6 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -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', '--proxy', '--geo-verification-proxy']) + 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' + ('|'.join(re.escape(po) for po in PRIVATE_OPTS)) + ')=.+$') + equre = re.compile('^(?P' + ('|'.join(re.escape(po) for po in URL_PRIVATE_OPTS)) + ')=(?P.+)$') 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