1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 10:42:34 +01:00

do not try to read from stdin when it is non-interactive (#5733)

add '--no-input' command-line option and 'input' config file option
to allow users to manually configure this
This commit is contained in:
Mike Fährmann 2024-06-16 18:31:39 +02:00
parent 76385f5f18
commit a1bb32792b
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
4 changed files with 35 additions and 1 deletions

View File

@ -461,6 +461,17 @@ Description
(see `getpass() <https://docs.python.org/3/library/getpass.html#getpass.getpass>`__).
extractor.*.input
-----------------
Type
``bool``
Default
``true`` if `stdin` is attached to a terminal ,
``false`` otherwise
Description
Allow prompting the user for interactive input.
extractor.*.netrc
-----------------
Type

View File

@ -30,6 +30,7 @@
-x, --input-file-delete FILE
Download URLs found in FILE. Delete them after
they were downloaded successfully.
--no-input Do not prompt for passwords/tokens
## Output Options:
-q, --quiet Activate quiet mode

View File

@ -11,6 +11,7 @@
import os
import re
import ssl
import sys
import time
import netrc
import queue
@ -263,6 +264,10 @@ class Extractor():
time.sleep(seconds)
def input(self, prompt, echo=True):
if not self._input:
raise exception.StopExtraction(
"User input required (%s)", prompt.strip(" :"))
if echo:
try:
return input(prompt)
@ -277,7 +282,13 @@ class Extractor():
password = None
if username:
password = self.config("password") or util.LazyPrompt()
password = self.config("password")
if not password:
if not self._input:
raise exception.StopExtraction(
"User input required (password)")
password = util.LazyPrompt()
elif self.config("netrc", False):
try:
info = netrc.netrc().authenticators(self.category)
@ -298,6 +309,7 @@ class Extractor():
self._retries = self.config("retries", 4)
self._timeout = self.config("timeout", 30)
self._verify = self.config("verify", True)
self._input = self.config("input")
self._proxies = util.build_proxy_map(self.config("proxy"), self.log)
self._interval = util.build_duration_func(
self.config("sleep-request", self.request_interval),
@ -307,6 +319,11 @@ class Extractor():
self.config("sleep-429", 60),
)
if self._input is None:
try:
self._input = sys.stdin.isatty()
except Exception:
self._input = False
if self._retries < 0:
self._retries = float("inf")
if not self._retry_codes:

View File

@ -256,6 +256,11 @@ def build_parser():
help=("Download URLs found in FILE. "
"Delete them after they were downloaded successfully."),
)
input.add_argument(
"--no-input",
dest="input", nargs=0, action=ConfigConstAction, const=False,
help=("Do not prompt for passwords/tokens"),
)
output = parser.add_argument_group("Output Options")
output.add_argument(