From 2df1a15fb801bc5e1e050df673b86b66bc77ecce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 25 May 2018 16:07:18 +0200 Subject: [PATCH] add '-s/--simulate' to run data extraction without download Useful for quick testing (even though -g and -j kind of do the same) and to fill a download archive without actually downloading the files. -s does the same as the default behaviour, except downloading stuff. Maybe it should get a more fitting name, as it does actually write to disk (cache, archive)? --- gallery_dl/__init__.py | 2 ++ gallery_dl/job.py | 14 +++++++++++++- gallery_dl/option.py | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index e698de62..7fb9ba09 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -275,6 +275,8 @@ def main(): jobtype = job.KeywordJob elif args.list_data: jobtype = job.DataJob + elif args.simulate: + jobtype = job.SimulationJob else: jobtype = job.DownloadJob diff --git a/gallery_dl/job.py b/gallery_dl/job.py index 61755f3a..c89743ee 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -209,7 +209,7 @@ class DownloadJob(Job): def handle_queue(self, url, keywords): try: - DownloadJob(url, self).run() + self.__class__(url, self).run() except exception.NoExtractorError: self._write_unsupported(url) @@ -227,6 +227,18 @@ class DownloadJob(Job): return instance +class SimulationJob(DownloadJob): + """Simulate the extraction process without downloading anything""" + + def handle_url(self, url, keywords, fallback=None): + self.pathfmt.set_keywords(keywords) + self.out.skip(self.pathfmt.path) + if self.sleep: + time.sleep(self.sleep) + if self.archive: + self.archive.add(keywords) + + class KeywordJob(Job): """Print available keywords""" diff --git a/gallery_dl/option.py b/gallery_dl/option.py index 03d5b263..45a4a99f 100644 --- a/gallery_dl/option.py +++ b/gallery_dl/option.py @@ -113,6 +113,10 @@ def build_parser(): "-j", "--dump-json", dest="list_data", action="store_true", help="Print JSON information", ) + output.add_argument( + "-s", "--simulate", dest="simulate", action="store_true", + help="Simulate data extraction; do not download anything", + ) output.add_argument( "-K", "--list-keywords", dest="list_keywords", action="store_true", help=("Print a list of available keywords and example values "