mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-25 12:12:34 +01:00
Merge branch 'options'
This commit is contained in:
commit
5db2aa29cf
@ -19,46 +19,65 @@ import sys
|
||||
import argparse
|
||||
from . import config, jobs
|
||||
|
||||
def parse_cmdline_options():
|
||||
def build_cmdline_parser():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Download images from various sources')
|
||||
parser.add_argument(
|
||||
"-c", "--config",
|
||||
default="~/.config/gallery/config", metavar="CFG",
|
||||
help="alternate configuration file"
|
||||
metavar="CFG", dest="cfgfiles", action="append",
|
||||
help="additional configuration files",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-d", "--dest",
|
||||
metavar="DEST",
|
||||
help="destination directory"
|
||||
help="destination directory",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-o", "--option",
|
||||
metavar="OPT", action="append", default=[],
|
||||
help="option value",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--list-modules", dest="list_modules", action="store_true",
|
||||
help="print a list of available modules/supported sites",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--list-keywords", dest="keywords", action="store_true",
|
||||
help="print a list of available keywords",
|
||||
help="print a list of available keywords for the given URLs",
|
||||
)
|
||||
parser.add_argument(
|
||||
"urls",
|
||||
nargs="+", metavar="URL",
|
||||
nargs="*", metavar="URL",
|
||||
help="url to download images from"
|
||||
)
|
||||
return parser.parse_args()
|
||||
return parser
|
||||
|
||||
def main():
|
||||
try:
|
||||
config.load()
|
||||
args = parse_cmdline_options()
|
||||
parser = build_cmdline_parser()
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.cfgfiles:
|
||||
config.load(*args.cfgfiles, strict=True)
|
||||
|
||||
if args.dest:
|
||||
config.set(("base-directory",), args.dest)
|
||||
|
||||
for opt in args.option:
|
||||
try:
|
||||
key, value = opt.split("=", 1)
|
||||
config.set(key.split("."), value)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
if args.list_modules:
|
||||
for module_name in extractor.modules:
|
||||
print(module_name)
|
||||
else:
|
||||
if not args.urls:
|
||||
parser.error("the following arguments are required: URL")
|
||||
jobtype = jobs.KeywordJob if args.keywords else jobs.DownloadJob
|
||||
try:
|
||||
for url in args.urls:
|
||||
jobtype(url).run()
|
||||
except KeyboardInterrupt:
|
||||
|
@ -16,7 +16,7 @@ import platform
|
||||
# --------------------------------------------------------------------
|
||||
# public interface
|
||||
|
||||
def load(*files):
|
||||
def load(*files, strict=False):
|
||||
"""Load JSON configuration files"""
|
||||
configfiles = files or _default_configs
|
||||
for conf in configfiles:
|
||||
@ -26,6 +26,8 @@ def load(*files):
|
||||
confdict = json.load(file)
|
||||
_config.update(confdict)
|
||||
except FileNotFoundError:
|
||||
if strict:
|
||||
raise
|
||||
continue
|
||||
except json.decoder.JSONDecodeError as exception:
|
||||
print("Error while loading '", path, "':", sep="", file=sys.stderr)
|
||||
|
Loading…
Reference in New Issue
Block a user