Skip to content

Commit

Permalink
add '"skip": "terminate"' option
Browse files Browse the repository at this point in the history
Stops not only the current extractor/job,
but all parent extractors/jobs as well.
  • Loading branch information
mikf committed May 12, 2021
1 parent 4835888 commit c693db5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

## Unreleased

## 1.17.4 - 2021-05-07
### Additions
- [gelbooru] add extractor for `/redirect.php` URLs ([#1530](https://github.com/mikf/gallery-dl/issues/1530))
Expand Down
8 changes: 6 additions & 2 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,14 @@ Description
* ``true``: Skip downloads
* ``false``: Overwrite already existing files

* ``"abort"``: Abort the current extractor run
* ``"abort:N"``: Skip downloads and abort extractor run
* ``"abort"``: Stop the current extractor run
* ``"abort:N"``: Skip downloads and stop the current extractor run
after ``N`` consecutive skips

* ``"terminate"``: Stop the current extractor run, including parent extractors
* ``"terminate:N"``: Skip downloads and stop the current extractor run,
including parent extractors, after ``N`` consecutive skips

* ``"exit"``: Exit the program altogether
* ``"exit:N"``: Skip downloads and exit the program
after ``N`` consecutive skips
Expand Down
2 changes: 2 additions & 0 deletions gallery_dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ def main():
retval |= jobtype(url.value).run()
else:
retval |= jobtype(url).run()
except exception.TerminateExtraction:
pass
except exception.NoExtractorError:
log.error("No suitable extractor found for '%s'", url)
retval |= 64
Expand Down
8 changes: 7 additions & 1 deletion gallery_dl/exception.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright 2015-2019 Mike Fährmann
# Copyright 2015-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
Expand All @@ -23,6 +23,7 @@
+-- FilterError
+-- NoExtractorError
+-- StopExtraction
+-- TerminateExtraction
"""


Expand Down Expand Up @@ -109,3 +110,8 @@ def __init__(self, message=None, *args):
GalleryDLException.__init__(self)
self.message = message % args if args else message
self.code = 1 if message else 0


class TerminateExtraction(GalleryDLException):
"""Terminate data extraction"""
code = 0
4 changes: 4 additions & 0 deletions gallery_dl/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def run(self):
if exc.message:
log.error(exc.message)
self.status |= exc.code
except exception.TerminateExtraction:
raise
except exception.GalleryDLException as exc:
log.error("%s: %s", exc.__class__.__name__, exc)
self.status |= exc.code
Expand Down Expand Up @@ -400,6 +402,8 @@ def initialize(self, kwdict=None):
skip, _, smax = skip.partition(":")
if skip == "abort":
self._skipexc = exception.StopExtraction
elif skip == "terminate":
self._skipexc = exception.TerminateExtraction
elif skip == "exit":
self._skipexc = sys.exit
self._skipcnt = 0
Expand Down
2 changes: 1 addition & 1 deletion gallery_dl/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.

__version__ = "1.17.4"
__version__ = "1.17.5-dev"

0 comments on commit c693db5

Please sign in to comment.