Skip to content

Commit

Permalink
[koharu] improve format selection (#6088)
Browse files Browse the repository at this point in the history
- allow specifying more than one possible format
- ignore not available formats
  • Loading branch information
mikf committed Aug 29, 2024
1 parent c51938b commit cf8e04d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
13 changes: 8 additions & 5 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

When more than one format is given, the first available one is selected.

| Available formats are
| ``"780"``, ``"980"``, ``"1280"``, ``"1600"``, ``"0"``/``"original"``
| Possible formats are
| ``"780"``, ``"980"``, ``"1280"``, ``"1600"``, ``"0"`` (original)

extractor.lolisafe.domain
Expand Down
25 changes: 19 additions & 6 deletions gallery_dl/extractor/koharu.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,29 @@ def images(self, _):
return results

def _select_format(self, formats):
if not self.fmt or self.fmt == "original":
fmtid = "0"
fmt = self.fmt

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:
fmtid = str(self.fmt)
fmtids = (str(self.fmt),)

try:
fmt = formats[fmtid]
except KeyError:
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

Expand Down

0 comments on commit cf8e04d

Please sign in to comment.