update/fix --list-extractors

This commit is contained in:
Mike Fährmann
2023-09-11 17:32:59 +02:00
parent 65b6011cc5
commit 4cdab8074e
3 changed files with 6 additions and 34 deletions

View File

@@ -196,16 +196,15 @@ def main():
elif args.list_extractors:
write = sys.stdout.write
fmt = "{}\n{}\nCategory: {} - Subcategory: {}{}\n\n".format
fmt = ("{}{}\nCategory: {} - Subcategory: {}"
"\nExample : {}\n\n").format
for extr in extractor.extractors():
if not extr.__doc__:
continue
test = next(extr._get_tests(), None)
write(fmt(
extr.__name__, extr.__doc__,
extr.__name__,
"\n" + extr.__doc__ if extr.__doc__ else "",
extr.category, extr.subcategory,
"\nExample : " + test[0] if test else "",
extr.example,
))
elif args.clear_cache:

View File

@@ -34,7 +34,6 @@ class Extractor():
archive_fmt = ""
cookies_domain = ""
browser = None
example = ""
root = ""
request_interval = 0.0
request_interval_min = 0.0
@@ -508,21 +507,6 @@ class Extractor():
result.append((Message.Queue, url, {"_extractor": extr}))
return iter(result)
@classmethod
def _get_tests(cls):
"""Yield an extractor's test cases as (URL, RESULTS) tuples"""
tests = cls.test
if not tests:
return
if len(tests) == 2 and (not tests[1] or isinstance(tests[1], dict)):
tests = (tests,)
for test in tests:
if isinstance(test, str):
test = (test, None)
yield test
@classmethod
def _dump(cls, obj):
util.dump_json(obj, ensure_ascii=False, indent=2)

View File

@@ -110,18 +110,7 @@ class FlickrAlbumExtractor(FlickrExtractor):
"Albums", "{album[id]} {album[title]}")
archive_fmt = "a_{album[id]}_{id}"
pattern = BASE_PATTERN + r"/photos/([^/?#]+)/(?:album|set)s(?:/(\d+))?"
test = (
(("https://www.flickr.com/photos/shona_s/albums/72157633471741607"), {
"pattern": FlickrImageExtractor.pattern,
"count": 6,
}),
("https://www.flickr.com/photos/shona_s/albums", {
"pattern": pattern,
"count": 2,
}),
("https://secure.flickr.com/photos/shona_s/albums"),
("https://m.flickr.com/photos/shona_s/albums"),
)
example = "https://www.flickr.com/photos/USER/albums/12345"
def __init__(self, match):
FlickrExtractor.__init__(self, match)