add '--items' option
this allows to specify which manga-chapters/comic-issues to download when using gallery-dl on a manga/comic URL
This commit is contained in:
@@ -51,6 +51,13 @@ def build_cmdline_parser():
|
|||||||
metavar="FILE", dest="inputfile",
|
metavar="FILE", dest="inputfile",
|
||||||
help="download URLs found in local FILE",
|
help="download URLs found in local FILE",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--items",
|
||||||
|
metavar="ITEM-SPEC", dest="items",
|
||||||
|
help=("specify which items to download through a comma seperated list "
|
||||||
|
"of indices or index-ranges; for example '--items -2,4,6-8,10-' "
|
||||||
|
"will download items 1, 2, 4, 6, 7, 8 and 10 up to the last one")
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-c", "--config",
|
"-c", "--config",
|
||||||
metavar="CFG", dest="cfgfiles", action="append",
|
metavar="CFG", dest="cfgfiles", action="append",
|
||||||
@@ -120,6 +127,8 @@ def main():
|
|||||||
config.set(("username",), args.username)
|
config.set(("username",), args.username)
|
||||||
if args.password:
|
if args.password:
|
||||||
config.set(("password",), args.password)
|
config.set(("password",), args.password)
|
||||||
|
if args.items:
|
||||||
|
config.set(("items",), args.items)
|
||||||
|
|
||||||
for opt in args.option:
|
for opt in args.option:
|
||||||
parse_option(opt)
|
parse_option(opt)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright 2015, 2016 Mike Fährmann
|
# Copyright 2015-2017 Mike Fährmann
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License version 2 as
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
from . import extractor, downloader, path, output, exception
|
from . import extractor, downloader, config, util, path, output, exception
|
||||||
from .extractor.message import Message
|
from .extractor.message import Message
|
||||||
|
|
||||||
|
|
||||||
@@ -81,6 +81,9 @@ class DownloadJob(Job):
|
|||||||
def run(self):
|
def run(self):
|
||||||
Job.run(self)
|
Job.run(self)
|
||||||
if self.queue:
|
if self.queue:
|
||||||
|
itemspec = config.get(("items",))
|
||||||
|
if itemspec:
|
||||||
|
self.queue = util.apply_range(self.queue, str(itemspec))
|
||||||
for url in self.queue:
|
for url in self.queue:
|
||||||
try:
|
try:
|
||||||
DownloadJob(url).run()
|
DownloadJob(url).run()
|
||||||
|
|||||||
47
gallery_dl/util.py
Normal file
47
gallery_dl/util.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright 2017 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
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
|
||||||
|
"""Utility functions"""
|
||||||
|
|
||||||
|
|
||||||
|
def apply_range(iterable, rangespec):
|
||||||
|
"""Return a new iterable containing only the items specified in the given
|
||||||
|
integer range
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
maxval = len(iterable)
|
||||||
|
except TypeError:
|
||||||
|
maxval = 0
|
||||||
|
rset = parse_range(rangespec, maxval)
|
||||||
|
return (
|
||||||
|
item
|
||||||
|
for index, item in enumerate(iterable, 1)
|
||||||
|
if index in rset
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_range(rangespec, maxval=0):
|
||||||
|
"""Parse an integer range and return the resulting set
|
||||||
|
|
||||||
|
Examples
|
||||||
|
parse_range("-2,4,6-8,10-", 12) -> set(1, 2, 4, 6, 7, 8, 10, 11, 12)
|
||||||
|
parse_range(" - 3 , 4- 4, 6-2") -> set(1, 2, 3, 4)
|
||||||
|
"""
|
||||||
|
result = set()
|
||||||
|
for group in rangespec.split(","):
|
||||||
|
parts = group.split("-", maxsplit=1)
|
||||||
|
try:
|
||||||
|
if len(parts) == 1:
|
||||||
|
result.add(int(parts[0]))
|
||||||
|
else:
|
||||||
|
beg = int(parts[0]) if parts[0].strip() else 1
|
||||||
|
end = int(parts[1]) if parts[1].strip() else maxval
|
||||||
|
result.update(range(beg, end+1))
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
return result
|
||||||
Reference in New Issue
Block a user