mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 02:32:33 +01:00
[koharu] improve format selection (#6088)
- allow specifying more than one possible format - ignore not available formats
This commit is contained in:
parent
c51938b82b
commit
cf8e04d999
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user