[khinsider] add 'format' option (closes #840)
This commit is contained in:
@@ -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
|
extractor.kissmanga.captcha
|
||||||
---------------------------
|
---------------------------
|
||||||
=========== =====
|
=========== =====
|
||||||
|
|||||||
@@ -56,12 +56,27 @@ class KhinsiderSoundtrackExtractor(AsynchronousMixin, Extractor):
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
def tracks(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(
|
for num, url in enumerate(text.extract_iter(
|
||||||
page, '<td class="clickable-row"><a href="', '"'), 1):
|
page, '<td class="clickable-row"><a href="', '"'), 1):
|
||||||
url = text.urljoin(self.root, url)
|
url = text.urljoin(self.root, url)
|
||||||
page = self.request(url, encoding="utf-8").text
|
page = self.request(url, encoding="utf-8").text
|
||||||
|
track = first = None
|
||||||
|
|
||||||
url = text.extract(page, 'style="color: #21363f;" href="', '"')[0]
|
for url in text.extract_iter(
|
||||||
yield text.nameext_from_url(url, {"num": num, "url": url})
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user