From 9dd5cb8c8a1b1a49403b88b17a7b03fc1f027bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 6 Dec 2023 21:31:31 +0100 Subject: [PATCH] interactively prompt for passwords on login when none is provided --- docs/configuration.rst | 6 +++++- gallery_dl/extractor/common.py | 2 +- gallery_dl/util.py | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index eb263c17..546ab189 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -379,7 +379,7 @@ Description The username and password to use when attempting to log in to another site. - Specifying a username and password is required for + Specifying username and password is required for * ``nijie`` @@ -415,6 +415,10 @@ Description (*) The password value for these sites should be the API key found in your user profile, not the actual account password. + Note: Leave the ``password`` value empty or undefined + to get prompted for a passeword when performing a login + (see `getpass() `__). + extractor.*.netrc ----------------- diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index f3784272..bf4de4d4 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -233,7 +233,7 @@ class Extractor(): password = None if username: - password = self.config("password") + password = self.config("password") or util.LazyPrompt() elif self.config("netrc", False): try: info = netrc.netrc().authenticators(self.category) diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 62aa12da..2fbba3ce 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -14,6 +14,7 @@ import sys import json import time import random +import getpass import hashlib import sqlite3 import binascii @@ -487,6 +488,13 @@ CODES = { } +class LazyPrompt(): + __slots__ = () + + def __str__(self): + return getpass.getpass() + + class CustomNone(): """None-style type that supports more operations than regular None""" __slots__ = ()