Skip to content

Commit

Permalink
[khinsider] add 'format' option (closes #840)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jul 13, 2020
1 parent d594977 commit cb0132e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
15 changes: 15 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,21 @@ Description Download video files.
=========== =====


extractor.khinsider.format
--------------------------
=========== =====
Type ``string``
Default ``"mp3"``
Description The name of the preferred file format to download.

Use ``"all"`` to download all available formats,
or a (comma-separated) list to select multiple formats.

If the selected format is not available,
the first in the list gets chosen (usually `mp3`).
=========== =====


extractor.kissmanga.captcha
---------------------------
=========== =====
Expand Down
21 changes: 18 additions & 3 deletions gallery_dl/extractor/khinsider.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,27 @@ def metadata(self, page):
}}

def tracks(self, page):
page = text.extract(page, '<table id="songlist">', '</table>')[0]
fmt = self.config("format", ("mp3",))
if fmt and isinstance(fmt, str):
if fmt == "all":
fmt = None
else:
fmt = fmt.lower().split(",")

page = text.extract(page, '<table id="songlist">', '</table>')[0]
for num, url in enumerate(text.extract_iter(
page, '<td class="clickable-row"><a href="', '"'), 1):
url = text.urljoin(self.root, url)
page = self.request(url, encoding="utf-8").text
track = first = None

url = text.extract(page, 'style="color: #21363f;" href="', '"')[0]
yield text.nameext_from_url(url, {"num": num, "url": url})
for url in text.extract_iter(
page, 'style="color: #21363f;" href="', '"'):
track = text.nameext_from_url(url, {"num": num, "url": url})
if first is None:
first = track
if not fmt or track["extension"] in fmt:
first = False
yield track
if first:
yield first

0 comments on commit cb0132e

Please sign in to comment.