diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index f3d4559e..b964b9a8 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -63,6 +63,8 @@ def main(): config.load(*args.yamlfiles, format="yaml", strict=True) for key, value in args.options: config.set(key, value) + if args.loglevel >= logging.ERROR: + config.set(("output", "mode"), "null") if args.list_modules: for module_name in extractor.modules: diff --git a/gallery_dl/option.py b/gallery_dl/option.py index 6dd14b2b..ef31cbce 100644 --- a/gallery_dl/option.py +++ b/gallery_dl/option.py @@ -140,6 +140,11 @@ def build_parser(): "--list-modules", dest="list_modules", action="store_true", help="Print a list of available modules/supported sites", ) + parser.add_argument( + "-q", "--quiet", dest="loglevel", action="store_const", + const=logging.ERROR, default=logging.INFO, + help="Activate quiet mode", + ) parser.add_argument( "-v", "--verbose", dest="loglevel", action="store_const", const=logging.DEBUG, default=logging.INFO, diff --git a/gallery_dl/output.py b/gallery_dl/output.py index e1c97d61..1536bae4 100644 --- a/gallery_dl/output.py +++ b/gallery_dl/output.py @@ -13,22 +13,23 @@ from . import config def select(): - """Automatically select a suitable printer class""" + """Automatically select a suitable output class""" pdict = { - "default": Printer, - "pipe": Printer, - "term": TerminalPrinter, - "terminal": TerminalPrinter, - "color": ColorPrinter, + "default": PipeOutput, + "pipe": PipeOutput, + "term": TerminalOutput, + "terminal": TerminalOutput, + "color": ColorOutput, + "null": NullOutput, } omode = config.get(("output", "mode"), "auto").lower() if omode in pdict: return pdict[omode]() elif omode == "auto": if hasattr(sys.stdout, "isatty") and sys.stdout.isatty(): - return ColorPrinter() if ANSI else TerminalPrinter() + return ColorOutput() if ANSI else TerminalOutput() else: - return Printer() + return PipeOutput() else: raise Exception("invalid output mode: " + omode) @@ -43,26 +44,31 @@ def safeprint(txt, **kwargs): print(txt, **kwargs) -class Printer(): +class NullOutput(): def start(self, path): """Print a message indicating the start of a download""" - pass def skip(self, path): """Print a message indicating that a download has been skipped""" - print(CHAR_SKIP, path, sep="", flush=True) def success(self, path, tries): """Print a message indicating the completion of a download""" - print(path, flush=True) def error(self, path, error, tries, max_tries): """Print a message indicating an error during download""" - pass -class TerminalPrinter(Printer): +class PipeOutput(NullOutput): + + def skip(self, path): + print(CHAR_SKIP, path, sep="", flush=True) + + def success(self, path, tries): + print(path, flush=True) + + +class TerminalOutput(NullOutput): def __init__(self): self.short = config.get(("output", "shorten"), True) @@ -99,7 +105,7 @@ class TerminalPrinter(Printer): return txt -class ColorPrinter(TerminalPrinter): +class ColorOutput(TerminalOutput): def start(self, path): print(self.shorten(path), end="", flush=True)