2016-04-20 08:34:44 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-09-11 16:30:55 +02:00
|
|
|
# Copyright 2016-2023 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"
|
2023-09-11 16:30:55 +02:00
|
|
|
root = "https://downloads.khinsider.com"
|
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/([^/?#]+)")
|
2023-09-11 16:30:55 +02:00
|
|
|
example = ("https://downloads.khinsider.com"
|
|
|
|
"/game-soundtracks/album/TITLE")
|
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.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": {
|
2022-05-20 20:00:39 +02:00
|
|
|
"name" : text.unescape(extr("<h2>", "<")),
|
2022-07-12 18:31:31 +02:00
|
|
|
"platform": extr("Platforms: <a", "<").rpartition(">")[2],
|
2020-02-07 18:20:38 +01:00
|
|
|
"count": text.parse_int(extr("Number of Files: <b>", "<")),
|
|
|
|
"size" : text.parse_bytes(extr("Total Filesize: <b>", "<")[:-1]),
|
2022-05-20 20:00:39 +02:00
|
|
|
"date" : extr("Date Added: <b>", "<"),
|
2022-12-07 21:36:34 +01:00
|
|
|
"type" : text.remove_html(extr("Album type: <b>", "</b>")),
|
2020-02-07 18:20:38 +01:00
|
|
|
}}
|
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
|
|
|
|
2022-11-04 23:39:38 +01:00
|
|
|
page = text.extr(page, '<table id="songlist">', '</table>')
|
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
|
|
|
|
2022-11-15 12:20:47 +01:00
|
|
|
for url in text.extract_iter(page, '<p><a href="', '"'):
|
2020-07-12 23:06:42 +02:00
|
|
|
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
|