[khinsider] add 'format' option (closes #840)

pull/893/head
Mike Fährmann 4 years ago
parent d594977ca1
commit cb0132e441
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -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
---------------------------
=========== =====

@ -56,12 +56,27 @@ class KhinsiderSoundtrackExtractor(AsynchronousMixin, Extractor):
}}
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

Loading…
Cancel
Save