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')
pull/17/head
Mike Fährmann 7 years ago
parent 7c8f61a116
commit fc9223c072
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -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):

@ -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 <key>=<value> 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(

@ -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"""

@ -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"

@ -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:

Loading…
Cancel
Save