2016-04-20 08:34:44 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-02-04 14:21:19 +01:00
|
|
|
# Copyright 2016-2019 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.
|
|
|
|
|
2017-04-20 13:20:41 +02:00
|
|
|
"""Extract soundtracks from 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"
|
2019-02-08 13:45:40 +01:00
|
|
|
directory_fmt = ("{category}", "{album}")
|
2019-02-14 16:07:17 +01:00
|
|
|
archive_fmt = "{album}_{filename}.{extension}"
|
2019-02-08 13:45:40 +01:00
|
|
|
pattern = (r"(?:https?://)?downloads\.khinsider\.com"
|
|
|
|
r"/game-soundtracks/album/([^/?&#]+)")
|
|
|
|
test = (("https://downloads.khinsider.com"
|
|
|
|
"/game-soundtracks/album/horizon-riders-wii"), {
|
|
|
|
"pattern": r"https?://\d+\.\d+\.\d+\.\d+/ost/horizon-riders-wii/[^/]+"
|
|
|
|
r"/Horizon%20Riders%20Wii%20-%20Full%20Soundtrack\.mp3",
|
2017-11-23 15:33:49 +01:00
|
|
|
"count": 1,
|
2019-02-14 16:07:17 +01:00
|
|
|
"keyword": "b4f460c78dd23e1f1121f4ac784dd67ded7c2679",
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2017-12-17 16:21:05 +01:00
|
|
|
root = "https://downloads.khinsider.com"
|
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):
|
2017-12-17 16:21:05 +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
|
2016-04-20 08:34:44 +02:00
|
|
|
data = self.get_job_metadata(page)
|
|
|
|
yield Message.Version, 1
|
|
|
|
yield Message.Directory, data
|
|
|
|
for url, track in self.get_album_tracks(page):
|
|
|
|
track.update(data)
|
|
|
|
yield Message.Url, url, track
|
|
|
|
|
|
|
|
def get_job_metadata(self, page):
|
2016-09-19 16:15:27 +02:00
|
|
|
"""Collect metadata for extractor-job"""
|
2017-12-01 13:58:06 +01:00
|
|
|
if "Download all songs at once:" not in page:
|
|
|
|
raise exception.NotFoundError("soundtrack")
|
2016-10-25 15:26:32 +02:00
|
|
|
data = text.extract_all(page, (
|
2016-04-20 08:34:44 +02:00
|
|
|
("album", "Album name: <b>", "</b>"),
|
|
|
|
("count", "Number of Files: <b>", "</b>"),
|
|
|
|
("size" , "Total Filesize: <b>", "</b>"),
|
|
|
|
("date" , "Date added: <b>", "</b>"),
|
|
|
|
("type" , "Album type: <b>", "</b>"),
|
2016-09-25 14:22:07 +02:00
|
|
|
))[0]
|
2016-10-25 15:26:32 +02:00
|
|
|
data["album"] = text.unescape(data["album"])
|
|
|
|
return data
|
2016-04-20 08:34:44 +02:00
|
|
|
|
|
|
|
def get_album_tracks(self, page):
|
2016-09-19 16:15:27 +02:00
|
|
|
"""Collect url and metadata for all tracks of a soundtrack"""
|
2017-12-05 23:29:11 +01: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
|
2017-11-28 19:35:47 +01:00
|
|
|
url = text.extract(
|
|
|
|
page, '<p><a style="color: #21363f;" href="', '"')[0]
|
|
|
|
yield url, text.nameext_from_url(url, {"num": num})
|