From fc9223c072ae7bf6d3809704710c7dd8f6a9984b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 3 May 2017 15:17:08 +0200 Subject: [PATCH] add '--abort-on-skip' option and ability to control skip behavior the 'skip' config option controls skipping behavior: true - skip download if file already exist (default) false - download and overwrite files even if it exists "abort" - abort extractor run if a download would be skipped (same as '--abort-on-skip') --- gallery_dl/extractor/hbrowse.py | 2 +- gallery_dl/option.py | 14 +++++++++++++- gallery_dl/util.py | 32 +++++++++++++++++++++----------- gallery_dl/version.py | 2 +- test/test_extractors.py | 2 +- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/gallery_dl/extractor/hbrowse.py b/gallery_dl/extractor/hbrowse.py index da299114..36798847 100644 --- a/gallery_dl/extractor/hbrowse.py +++ b/gallery_dl/extractor/hbrowse.py @@ -19,7 +19,7 @@ class HbrowseMangaExtractor(Extractor): subcategory = "manga" pattern = [r"(?:https?://)?(?:www\.)?hbrowse\.com/(\d+)/?$"] test = [("http://www.hbrowse.com/10363", { - "url": "b89682bfb86c11d2af0dc47463804ec3ac4aadd6", + "url": "4d9def5df21c23f8c3d36de2076c189c02ea43bd", })] def __init__(self, match): diff --git a/gallery_dl/option.py b/gallery_dl/option.py index ef31cbce..9daef141 100644 --- a/gallery_dl/option.py +++ b/gallery_dl/option.py @@ -22,6 +22,12 @@ class ConfigAction(argparse.Action): namespace.options.append(((self.dest,), values)) +class ConfigConstAction(argparse.Action): + """Set argparse const values as config values""" + def __call__(self, parser, namespace, values, option_string=None): + namespace.options.append(((self.dest,), self.const)) + + class ParseAction(argparse.Action): """Parse = options and set them as config values""" def __call__(self, parser, namespace, values, option_string=None): @@ -98,6 +104,12 @@ def build_parser(): metavar="ITEM-SPEC", action=ConfigAction, dest="chapters", help=("Same as '--images' except for chapters") ) + parser.add_argument( + "--abort-on-skip", + action=ConfigConstAction, nargs=0, dest="skip", const="abort", + help=("Abort extractor run if a file download would normally be " + "skipped, i.e. if a file with the same filename already exists") + ) parser.add_argument( "-R", "--retries", metavar="RETRIES", action=ConfigAction, dest="retries", type=int, @@ -105,7 +117,7 @@ def build_parser(): ) parser.add_argument( "--http-timeout", - metavar="SECONDS", action=ConfigAction, dest="timeout", type=int, + metavar="SECONDS", action=ConfigAction, dest="timeout", type=float, help="Timeout for HTTP connections (defaut: no timeout)", ) parser.add_argument( diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 4e2cac67..95e67ce1 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -133,26 +133,27 @@ class RangePredicate(): class PathFormat(): def __init__(self, extractor): - key = ["extractor", extractor.category] - if extractor.subcategory: - key.append(extractor.subcategory) - self.filename_fmt = config.interpolate( - key + ["filename"], default=extractor.filename_fmt - ) - self.directory_fmt = config.interpolate( - key + ["directory"], default=extractor.directory_fmt - ) + self.filename_fmt = extractor.config( + "filename", extractor.filename_fmt) + self.directory_fmt = extractor.config( + "directory", extractor.directory_fmt) self.has_extension = False self.keywords = {} self.directory = self.realdirectory = "" self.path = self.realpath = "" + skipmode = extractor.config("skip", True) + if skipmode == "abort": + self.exists = self._exists_abort + elif not skipmode: + self.exists = self._exists_false + def open(self): - """Open file ta 'realpath' and return a corresponding file object""" + """Open file to 'realpath' and return a corresponding file object""" return open(self.realpath, "wb") def exists(self): - """Return True if 'path' is complete and referse to an existing path""" + """Return True if 'path' is complete and refers to an existing path""" if self.has_extension: return os.path.exists(self.realpath) return False @@ -189,6 +190,15 @@ class PathFormat(): self.path = self.directory + sep + filename self.realpath = self.realdirectory + sep + filename + def _exists_abort(self): + if self.has_extension and os.path.exists(self.realpath): + raise exception.StopExtraction() + return False + + @staticmethod + def _exists_false(): + return False + @staticmethod def get_base_directory(): """Return the base-destination-directory for downloads""" diff --git a/gallery_dl/version.py b/gallery_dl/version.py index b2bd8c44..689eda6c 100644 --- a/gallery_dl/version.py +++ b/gallery_dl/version.py @@ -6,4 +6,4 @@ # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. -__version__ = "0.8.3" +__version__ = "0.8.4-dev" diff --git a/test/test_extractors.py b/test/test_extractors.py index 6489e581..6dd84ce9 100644 --- a/test/test_extractors.py +++ b/test/test_extractors.py @@ -51,7 +51,7 @@ skip = [ # dont work on travis-ci "exhentai", "kissmanga", "mangafox", "dynastyscans", # temporary issues - "fallenangels", + ] # enable selective testing for direct calls if __name__ == '__main__' and len(sys.argv) > 1: