From cf8e04d999778f41b990672a1ada03be1833cb8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 29 Aug 2024 09:33:24 +0200 Subject: [PATCH] [koharu] improve format selection (#6088) - allow specifying more than one possible format - ignore not available formats --- docs/configuration.rst | 13 ++++++++----- gallery_dl/extractor/koharu.py | 27 ++++++++++++++++++++------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 7fed4eb7..5795fc03 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -2689,14 +2689,17 @@ Description extractor.koharu.format ----------------------- Type - ``string`` + * ``string`` + * ``list`` of ``strings`` Default - ``"original"`` + ``["0", "1600", "1280", "980", "780"]`` Description - Name of the image format to download. + Name(s) of the image format to download. - | Available formats are - | ``"780"``, ``"980"``, ``"1280"``, ``"1600"``, ``"0"``/``"original"`` + When more than one format is given, the first available one is selected. + + | Possible formats are + | ``"780"``, ``"980"``, ``"1280"``, ``"1600"``, ``"0"`` (original) extractor.lolisafe.domain diff --git a/gallery_dl/extractor/koharu.py b/gallery_dl/extractor/koharu.py index 979b1a21..cacf5046 100644 --- a/gallery_dl/extractor/koharu.py +++ b/gallery_dl/extractor/koharu.py @@ -161,16 +161,29 @@ class KoharuGalleryExtractor(KoharuExtractor, GalleryExtractor): return results def _select_format(self, formats): - if not self.fmt or self.fmt == "original": - fmtid = "0" - else: - fmtid = str(self.fmt) + fmt = self.fmt - try: - fmt = formats[fmtid] - except KeyError: + if not fmt or fmt == "best": + fmtids = ("0", "1600", "1280", "980", "780") + elif isinstance(fmt, str): + fmtids = fmt.split(",") + elif isinstance(fmt, list): + fmtids = fmt + else: + fmtids = (str(self.fmt),) + + for fmtid in fmtids: + try: + fmt = formats[fmtid] + if fmt["id"]: + break + except KeyError: + self.log.debug("%s: Format %s is not available", + self.groups[0], fmtid) + else: raise exception.NotFoundError("format") + self.log.debug("%s: Selected format %s", self.groups[0], fmtid) fmt["w"] = fmtid return fmt