From 6851963304cd2b86d1ef67f0c8ef77ff032db926 Mon Sep 17 00:00:00 2001 From: XZS Date: Sat, 10 Sep 2016 13:17:15 +0200 Subject: [PATCH] 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: