From 6851963304cd2b86d1ef67f0c8ef77ff032db926 Mon Sep 17 00:00:00 2001 From: XZS Date: Sat, 10 Sep 2016 13:17:15 +0200 Subject: [PATCH 1/2] ask libsecret for password When it knows a user name, youtube-dl can ask the secret service [1] for a user password on systems that have it, instead of interactively requesting to type it. The user name is expected to be found in a field named "username". This scheme corresponds with how keyring integration Add-Ons [2] for Firefox and Thunderbird store login passwords. So, a single entry suffices to universally store login data per site. If libsecret is not available or the user name could not be found, the old behaviour of asking to enter the password manually is retained. [1]: https://developer.gnome.org/libsecret/ [2]: https://github.com/swick/mozilla-gnome-keyring --- youtube_dl/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 42128272a..41242a802 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -129,7 +129,15 @@ def _real_main(argv=None): if opts.usetitle and opts.useid: parser.error('using title conflicts with using video ID') if opts.username is not None and opts.password is None: - opts.password = compat_getpass('Type account password and press [Return]: ') + try: + from gi import require_version + require_version('Secret', '1') + from gi.repository import Secret + opts.password = Secret.Service.get_sync( + Secret.ServiceFlags.NONE, None).lookup_sync(None, { + "username": opts.username}).get_text() + except: + opts.password = compat_getpass('Type account password and press [Return]: ') if opts.ratelimit is not None: numeric_limit = FileDownloader.parse_bytes(opts.ratelimit) if numeric_limit is None: From 3dcd982c860ec2c7d5fb836a34a27df56064f4cd Mon Sep 17 00:00:00 2001 From: XZS Date: Sat, 10 Sep 2016 13:42:08 +0200 Subject: [PATCH 2/2] document libsecret integration --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7543f81ac..d49b34e67 100644 --- a/README.md +++ b/README.md @@ -353,7 +353,8 @@ which means you can modify it, redistribute it or use it however you like. ## Authentication Options: -u, --username USERNAME Login with this account ID -p, --password PASSWORD Account password. If this option is left - out, youtube-dl will ask interactively. + out, youtube-dl will query libsecret, if + available, or ask interactively. -2, --twofactor TWOFACTOR Two-factor auth code -n, --netrc Use .netrc authentication data --video-password PASSWORD Video password (vimeo, smotri, youku)