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')
This commit is contained in:
@@ -19,7 +19,7 @@ class HbrowseMangaExtractor(Extractor):
|
|||||||
subcategory = "manga"
|
subcategory = "manga"
|
||||||
pattern = [r"(?:https?://)?(?:www\.)?hbrowse\.com/(\d+)/?$"]
|
pattern = [r"(?:https?://)?(?:www\.)?hbrowse\.com/(\d+)/?$"]
|
||||||
test = [("http://www.hbrowse.com/10363", {
|
test = [("http://www.hbrowse.com/10363", {
|
||||||
"url": "b89682bfb86c11d2af0dc47463804ec3ac4aadd6",
|
"url": "4d9def5df21c23f8c3d36de2076c189c02ea43bd",
|
||||||
})]
|
})]
|
||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ class ConfigAction(argparse.Action):
|
|||||||
namespace.options.append(((self.dest,), values))
|
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):
|
class ParseAction(argparse.Action):
|
||||||
"""Parse <key>=<value> options and set them as config values"""
|
"""Parse <key>=<value> options and set them as config values"""
|
||||||
def __call__(self, parser, namespace, values, option_string=None):
|
def __call__(self, parser, namespace, values, option_string=None):
|
||||||
@@ -98,6 +104,12 @@ def build_parser():
|
|||||||
metavar="ITEM-SPEC", action=ConfigAction, dest="chapters",
|
metavar="ITEM-SPEC", action=ConfigAction, dest="chapters",
|
||||||
help=("Same as '--images' except for 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(
|
parser.add_argument(
|
||||||
"-R", "--retries",
|
"-R", "--retries",
|
||||||
metavar="RETRIES", action=ConfigAction, dest="retries", type=int,
|
metavar="RETRIES", action=ConfigAction, dest="retries", type=int,
|
||||||
@@ -105,7 +117,7 @@ def build_parser():
|
|||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--http-timeout",
|
"--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)",
|
help="Timeout for HTTP connections (defaut: no timeout)",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|||||||
@@ -133,26 +133,27 @@ class RangePredicate():
|
|||||||
class PathFormat():
|
class PathFormat():
|
||||||
|
|
||||||
def __init__(self, extractor):
|
def __init__(self, extractor):
|
||||||
key = ["extractor", extractor.category]
|
self.filename_fmt = extractor.config(
|
||||||
if extractor.subcategory:
|
"filename", extractor.filename_fmt)
|
||||||
key.append(extractor.subcategory)
|
self.directory_fmt = extractor.config(
|
||||||
self.filename_fmt = config.interpolate(
|
"directory", extractor.directory_fmt)
|
||||||
key + ["filename"], default=extractor.filename_fmt
|
|
||||||
)
|
|
||||||
self.directory_fmt = config.interpolate(
|
|
||||||
key + ["directory"], default=extractor.directory_fmt
|
|
||||||
)
|
|
||||||
self.has_extension = False
|
self.has_extension = False
|
||||||
self.keywords = {}
|
self.keywords = {}
|
||||||
self.directory = self.realdirectory = ""
|
self.directory = self.realdirectory = ""
|
||||||
self.path = self.realpath = ""
|
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):
|
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")
|
return open(self.realpath, "wb")
|
||||||
|
|
||||||
def exists(self):
|
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:
|
if self.has_extension:
|
||||||
return os.path.exists(self.realpath)
|
return os.path.exists(self.realpath)
|
||||||
return False
|
return False
|
||||||
@@ -189,6 +190,15 @@ class PathFormat():
|
|||||||
self.path = self.directory + sep + filename
|
self.path = self.directory + sep + filename
|
||||||
self.realpath = self.realdirectory + 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
|
@staticmethod
|
||||||
def get_base_directory():
|
def get_base_directory():
|
||||||
"""Return the base-destination-directory for downloads"""
|
"""Return the base-destination-directory for downloads"""
|
||||||
|
|||||||
@@ -6,4 +6,4 @@
|
|||||||
# it under the terms of the GNU General Public License version 2 as
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
# published by the Free Software Foundation.
|
# 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
|
# dont work on travis-ci
|
||||||
"exhentai", "kissmanga", "mangafox", "dynastyscans",
|
"exhentai", "kissmanga", "mangafox", "dynastyscans",
|
||||||
# temporary issues
|
# temporary issues
|
||||||
"fallenangels",
|
|
||||||
]
|
]
|
||||||
# enable selective testing for direct calls
|
# enable selective testing for direct calls
|
||||||
if __name__ == '__main__' and len(sys.argv) > 1:
|
if __name__ == '__main__' and len(sys.argv) > 1:
|
||||||
|
|||||||
Reference in New Issue
Block a user