From 6940ad0e72a3f9b02ff6fa3952a760754076a2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 17 Jul 2024 20:40:29 +0200 Subject: [PATCH] [booru] allow multiple 'url' keys (#5859) --- docs/configuration.rst | 8 ++++++-- gallery_dl/extractor/booru.py | 11 ++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 055e4e29..c3ed5626 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -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 ------------------------------------------- diff --git a/gallery_dl/extractor/booru.py b/gallery_dl/extractor/booru.py index 875265cb..7e26f38b 100644 --- a/gallery_dl/extractor/booru.py +++ b/gallery_dl/extractor/booru.py @@ -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"""