You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gallery-dl/gallery_dl/__init__.py

79 lines
2.2 KiB

# -*- coding: utf-8 -*-
# Copyright 2014, 2015 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.
10 years ago
__author__ = "Mike Fährmann"
__copyright__ = "Copyright 2014, 2015 Mike Fährmann"
10 years ago
__license__ = "GPLv2"
__version__ = "0.3.2"
10 years ago
__maintainer__ = "Mike Fährmann"
__email__ = "mike_faehrmann@web.de"
import os
import sys
import argparse
from . import config, jobs
10 years ago
def build_cmdline_parser():
parser = argparse.ArgumentParser(
10 years ago
description='Download images from various sources')
parser.add_argument(
"-c", "--config",
default="~/.config/gallery/config", metavar="CFG",
help="alternate configuration file"
)
parser.add_argument(
"-d", "--dest",
metavar="DEST",
help="destination directory"
)
parser.add_argument(
"-o", "--option",
9 years ago
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",
)
parser.add_argument(
"urls",
nargs="*", metavar="URL",
help="url to download images from"
)
return parser
10 years ago
def main():
try:
config.load()
parser = build_cmdline_parser()
args = parser.parse_args()
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
for url in args.urls:
jobtype(url).run()
except KeyboardInterrupt:
9 years ago
print("\nKeyboardInterrupt")