1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 10:42:34 +01:00

implement -g,--get-urls option

This commit is contained in:
Mike Fährmann 2015-12-10 02:14:28 +01:00
parent 50ec170b00
commit 2dfed4d40a
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 26 additions and 3 deletions

View File

@ -37,12 +37,16 @@ def build_cmdline_parser():
metavar="OPT", action="append", default=[],
help="option value",
)
parser.add_argument(
"-g", "--get-urls", dest="list_urls", action="store_true",
help="print download urls",
)
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",
"--list-keywords", dest="list_keywords", action="store_true",
help="print a list of available keywords for the given URLs",
)
parser.add_argument(
@ -77,7 +81,12 @@ def main():
else:
if not args.urls:
parser.error("the following arguments are required: URL")
jobtype = jobs.KeywordJob if args.keywords else jobs.DownloadJob
if args.list_urls:
jobtype = jobs.UrlJob
elif args.list_keywords:
jobtype = jobs.KeywordJob
else:
jobtype = jobs.DownloadJob
for url in args.urls:
jobtype(url).run()
except KeyboardInterrupt:

View File

@ -8,7 +8,6 @@
import os
import sys
import tempfile
from . import config, extractor, downloader, text, output
from .extractor.message import Message
@ -145,3 +144,18 @@ class KeywordJob():
for key, value in sorted(keywords.items()):
print(key, ":", " "*(offset-len(key)), value, sep="")
print()
class UrlJob():
def __init__(self, url):
self.extractor = extractor.find(url)
if self.extractor is None:
print(url, ": No extractor found", sep="", file=sys.stderr)
def run(self):
if self.extractor is None:
return
for msg in self.extractor:
if msg[0] == Message.Url:
print(msg[1])