diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 6f6d64bc..0f40bb9c 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -7,6 +7,7 @@ # published by the Free Software Foundation. import sys +import json import time import errno import logging @@ -575,6 +576,38 @@ class UrlJob(Job): self._write_unsupported(url) +class InfoJob(Job): + """Print extractor defaults and settings""" + + def run(self): + ex = self.extractor + pm = self._print_multi + pc = self._print_config + + if ex.basecategory: + pm("Category / Subcategory / Basecategory", + ex.category, ex.subcategory, ex.basecategory) + else: + pm("Category / Subcategory", ex.category, ex.subcategory) + + pc("Filename format", "filename", ex.filename_fmt) + pc("Directory format", "directory", ex.directory_fmt) + pc("Request interval", "sleep-request", ex.request_interval) + + return 0 + + def _print_multi(self, title, *values): + print(title, "\n ", " / ".join(json.dumps(v) for v in values), sep="") + + def _print_config(self, title, optname, value): + optval = self.extractor.config(optname, util.SENTINEL) + if optval is not util.SENTINEL: + print(title, "(custom):\n ", json.dumps(optval)) + print(title, "(default):\n ", json.dumps(value)) + elif value: + print(title, "(default):\n ", json.dumps(value)) + + class DataJob(Job): """Collect extractor results and dump them""" diff --git a/gallery_dl/option.py b/gallery_dl/option.py index 0ca32aa6..60d911b9 100644 --- a/gallery_dl/option.py +++ b/gallery_dl/option.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2017-2020 Mike Fährmann +# Copyright 2017-2021 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -150,6 +150,11 @@ def build_parser(): dest="jobtype", action="store_const", const=job.SimulationJob, help="Simulate data extraction; do not download anything", ) + output.add_argument( + "-E", "--extractor-info", + dest="jobtype", action="store_const", const=job.InfoJob, + help="Print extractor defaults and settings", + ) output.add_argument( "-K", "--list-keywords", dest="jobtype", action="store_const", const=job.KeywordJob,