Skip to content

Commit

Permalink
[options] Hide --password=secret in verbose output
Browse files Browse the repository at this point in the history
  • Loading branch information
phihag committed Aug 2, 2016
1 parent 6a9b3b6 commit 3aa9a73
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions youtube_dl/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os.path
import optparse
import re
import sys

from .downloader.external import list_external_downloaders
Expand Down Expand Up @@ -93,8 +94,18 @@ def _comma_separated_values_options_callback(option, opt_str, value, parser):
setattr(parser.values, option.dest, value.split(','))

def _hide_login_info(opts):
opts = list(opts)
for private_opt in ['-p', '--password', '-u', '--username', '--video-password']:
PRIVATE_OPTS = ['-p', '--password', '-u', '--username', '--video-password']
eqre = re.compile('^(?P<key>' + ('|'.join(re.escape(po) for po in PRIVATE_OPTS)) + ')=.+$')

def _scrub_eq(o):
m = eqre.match(o)
if m:
return m.group('key') + '=PRIVATE'
else:
return o

opts = list(map(_scrub_eq, opts))
for private_opt in PRIVATE_OPTS:
try:
i = opts.index(private_opt)
opts[i + 1] = 'PRIVATE'
Expand Down

0 comments on commit 3aa9a73

Please sign in to comment.