implement -g,--get-urls option
This commit is contained in:
@@ -37,12 +37,16 @@ def build_cmdline_parser():
|
|||||||
metavar="OPT", action="append", default=[],
|
metavar="OPT", action="append", default=[],
|
||||||
help="option value",
|
help="option value",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-g", "--get-urls", dest="list_urls", action="store_true",
|
||||||
|
help="print download urls",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--list-modules", dest="list_modules", action="store_true",
|
"--list-modules", dest="list_modules", action="store_true",
|
||||||
help="print a list of available modules/supported sites",
|
help="print a list of available modules/supported sites",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
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",
|
help="print a list of available keywords for the given URLs",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -77,7 +81,12 @@ def main():
|
|||||||
else:
|
else:
|
||||||
if not args.urls:
|
if not args.urls:
|
||||||
parser.error("the following arguments are required: URL")
|
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:
|
for url in args.urls:
|
||||||
jobtype(url).run()
|
jobtype(url).run()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
from . import config, extractor, downloader, text, output
|
from . import config, extractor, downloader, text, output
|
||||||
from .extractor.message import Message
|
from .extractor.message import Message
|
||||||
|
|
||||||
@@ -145,3 +144,18 @@ class KeywordJob():
|
|||||||
for key, value in sorted(keywords.items()):
|
for key, value in sorted(keywords.items()):
|
||||||
print(key, ":", " "*(offset-len(key)), value, sep="")
|
print(key, ":", " "*(offset-len(key)), value, sep="")
|
||||||
print()
|
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])
|
||||||
|
|||||||
Reference in New Issue
Block a user