[koharu] improve format selection (#6088)
- allow specifying more than one possible format - ignore not available formats
This commit is contained in:
@@ -2689,14 +2689,17 @@ Description
|
|||||||
extractor.koharu.format
|
extractor.koharu.format
|
||||||
-----------------------
|
-----------------------
|
||||||
Type
|
Type
|
||||||
``string``
|
* ``string``
|
||||||
|
* ``list`` of ``strings``
|
||||||
Default
|
Default
|
||||||
``"original"``
|
``["0", "1600", "1280", "980", "780"]``
|
||||||
Description
|
Description
|
||||||
Name of the image format to download.
|
Name(s) of the image format to download.
|
||||||
|
|
||||||
| Available formats are
|
When more than one format is given, the first available one is selected.
|
||||||
| ``"780"``, ``"980"``, ``"1280"``, ``"1600"``, ``"0"``/``"original"``
|
|
||||||
|
| Possible formats are
|
||||||
|
| ``"780"``, ``"980"``, ``"1280"``, ``"1600"``, ``"0"`` (original)
|
||||||
|
|
||||||
|
|
||||||
extractor.lolisafe.domain
|
extractor.lolisafe.domain
|
||||||
|
|||||||
@@ -161,16 +161,29 @@ class KoharuGalleryExtractor(KoharuExtractor, GalleryExtractor):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
def _select_format(self, formats):
|
def _select_format(self, formats):
|
||||||
if not self.fmt or self.fmt == "original":
|
fmt = self.fmt
|
||||||
fmtid = "0"
|
|
||||||
else:
|
|
||||||
fmtid = str(self.fmt)
|
|
||||||
|
|
||||||
try:
|
if not fmt or fmt == "best":
|
||||||
fmt = formats[fmtid]
|
fmtids = ("0", "1600", "1280", "980", "780")
|
||||||
except KeyError:
|
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")
|
raise exception.NotFoundError("format")
|
||||||
|
|
||||||
|
self.log.debug("%s: Selected format %s", self.groups[0], fmtid)
|
||||||
fmt["w"] = fmtid
|
fmt["w"] = fmtid
|
||||||
return fmt
|
return fmt
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user