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
This commit is contained in:
XZS 2016-09-10 13:17:15 +02:00
parent c6129feb7f
commit 6851963304

View File

@ -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: