2016-04-20 08:34:44 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2020-02-07 18:20:38 +01:00
|
|
|
# Copyright 2016-2020 Mike Fährmann
|
2016-04-20 08:34:44 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
|
2020-02-07 18:20:38 +01:00
|
|
|
"""Extractors for https://downloads.khinsider.com/"""
|
2016-04-20 08:34:44 +02:00
|
|
|
|
2019-02-04 14:21:19 +01:00
|
|
|
from .common import Extractor, Message, AsynchronousMixin
|
2016-09-19 16:15:27 +02:00
|
|
|
from .. import text, exception
|
2016-04-20 08:34:44 +02:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2019-02-04 14:21:19 +01:00
|
|
|
class KhinsiderSoundtrackExtractor(AsynchronousMixin, Extractor):
|
2016-09-12 10:20:57 +02:00
|
|
|
"""Extractor for soundtracks from khinsider.com"""
|
2016-04-20 08:34:44 +02:00
|
|
|
category = "khinsider"
|
2016-09-12 10:20:57 +02:00
|
|
|
subcategory = "soundtrack"
|
2020-02-07 18:20:38 +01:00
|
|
|
directory_fmt = ("{category}", "{album[name]}")
|
|
|
|
archive_fmt = "{filename}.{extension}"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?downloads\.khinsider\.com"
|
2020-10-22 23:12:59 +02:00
|
|
|
r"/game-soundtracks/album/([^/?#]+)")
|
2020-02-07 18:20:38 +01:00
|
|
|
root = "https://downloads.khinsider.com"
|
2019-02-08 13:45:40 +01:00
|
|
|
test = (("https://downloads.khinsider.com"
|
|
|
|
"/game-soundtracks/album/horizon-riders-wii"), {
|
2020-02-22 02:59:56 +01:00
|
|
|
"pattern": r"https?://vgmdownloads.com/soundtracks/horizon-riders-wii/"
|
|
|
|
r"[^/]+/Horizon%20Riders%20Wii%20-%20Full%20Soundtrack.mp3",
|
|
|
|
"keyword": "5b2c35cce638c326cab2a4f7a79f245d008d62ff",
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2016-04-20 08:34:44 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
2019-02-11 13:31:10 +01:00
|
|
|
Extractor.__init__(self, match)
|
2016-04-20 08:34:44 +02:00
|
|
|
self.album = match.group(1)
|
|
|
|
|
|
|
|
def items(self):
|
2020-02-07 18:20:38 +01:00
|
|
|
url = self.root + "/game-soundtracks/album/" + self.album
|
2016-07-12 12:06:17 +02:00
|
|
|
page = self.request(url, encoding="utf-8").text
|
2020-02-07 18:20:38 +01:00
|
|
|
if "Download all songs at once:" not in page:
|
|
|
|
raise exception.NotFoundError("soundtrack")
|
|
|
|
|
|
|
|
data = self.metadata(page)
|
2016-04-20 08:34:44 +02:00
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
2020-02-07 18:20:38 +01:00
|
|
|
for track in self.tracks(page):
|
2016-04-20 08:34:44 +02:00
|
|
|
track.update(data)
|
2020-02-07 18:20:38 +01:00
|
|
|
yield Message.Url, track["url"], track
|
2016-04-20 08:34:44 +02:00
|
|
|
|
2020-02-07 18:20:38 +01:00
|
|
|
def metadata(self, page):
|
|
|
|
extr = text.extract_from(page)
|
|
|
|
return {"album": {
|
|
|
|
"name" : text.unescape(extr("Album name: <b>", "<")),
|
|
|
|
"count": text.parse_int(extr("Number of Files: <b>", "<")),
|
|
|
|
"size" : text.parse_bytes(extr("Total Filesize: <b>", "<")[:-1]),
|
|
|
|
"date" : extr("Date added: <b>", "<"),
|
|
|
|
"type" : extr("Album type: <b>", "<"),
|
|
|
|
}}
|
2016-04-20 08:34:44 +02:00
|
|
|
|
2020-02-07 18:20:38 +01:00
|
|
|
def tracks(self, page):
|
2020-07-12 23:06:42 +02:00
|
|
|
fmt = self.config("format", ("mp3",))
|
|
|
|
if fmt and isinstance(fmt, str):
|
|
|
|
if fmt == "all":
|
|
|
|
fmt = None
|
|
|
|
else:
|
|
|
|
fmt = fmt.lower().split(",")
|
2020-02-07 18:20:38 +01:00
|
|
|
|
2020-07-12 23:06:42 +02:00
|
|
|
page = text.extract(page, '<table id="songlist">', '</table>')[0]
|
2017-11-23 15:33:49 +01:00
|
|
|
for num, url in enumerate(text.extract_iter(
|
2017-12-05 23:29:11 +01:00
|
|
|
page, '<td class="clickable-row"><a href="', '"'), 1):
|
2018-04-26 17:00:26 +02:00
|
|
|
url = text.urljoin(self.root, url)
|
|
|
|
page = self.request(url, encoding="utf-8").text
|
2020-07-12 23:06:42 +02:00
|
|
|
track = first = None
|
2020-02-07 18:20:38 +01:00
|
|
|
|
2020-07-12 23:06:42 +02:00
|
|
|
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
|