[booru] allow multiple 'url' keys (#5859)

This commit is contained in:
Mike Fährmann
2024-07-17 20:40:29 +02:00
parent bf44add132
commit 6940ad0e72
2 changed files with 16 additions and 3 deletions

View File

@@ -4577,14 +4577,18 @@ Description
extractor.[booru].url
---------------------
Type
``string``
* ``string``
* ``list`` of ``strings``
Default
``"file_url"``
Example
``"preview_url"``
* ``"preview_url"``
* ``["sample_url", "preview_url", "file_url"}``
Description
Alternate field name to retrieve download URLs from.
When multiple names are given, download the first available one.
extractor.[manga-extractor].chapter-reverse
-------------------------------------------

View File

@@ -29,7 +29,11 @@ class BooruExtractor(BaseExtractor):
url_key = self.config("url")
if url_key:
self._file_url = operator.itemgetter(url_key)
if isinstance(url_key, (list, tuple)):
self._file_url = self._file_url_list
self._file_url_keys = url_key
else:
self._file_url = operator.itemgetter(url_key)
for post in self.posts():
try:
@@ -74,6 +78,11 @@ class BooruExtractor(BaseExtractor):
_file_url = operator.itemgetter("file_url")
def _file_url_list(self, post):
urls = (post[key] for key in self._file_url_keys if post.get(key))
post["_fallback"] = it = iter(urls)
return next(it)
def _prepare(self, post):
"""Prepare a 'post's metadata"""