| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright 2022-2025 Mike Fährmann |
| 4 |
# |
| 5 |
# This program is free software; you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License version 2 as |
| 7 |
# published by the Free Software Foundation. |
| 8 |
|
| 9 |
"""Extractors for https://soundgasm.net/""" |
| 10 |
|
| 11 |
from .common import Extractor, Message |
| 12 |
from .. import text |
| 13 |
|
| 14 |
BASE_PATTERN = r"(?:https?://)?(?:www\.)?soundgasm\.net/u(?:ser)?" |
| 15 |
|
| 16 |
|
| 17 |
class SoundgasmExtractor(Extractor): |
| 18 |
"""Base class for soundgasm extractors""" |
| 19 |
category = "soundgasm" |
| 20 |
root = "https://soundgasm.net" |
| 21 |
request_interval = (0.5, 1.5) |
| 22 |
directory_fmt = ("{category}", "{user}") |
| 23 |
filename_fmt = "{title}.{extension}" |
| 24 |
archive_fmt = "{user}_{slug}" |
| 25 |
|
| 26 |
def items(self): |
| 27 |
for sound in map(self._extract_sound, self.sounds()): |
| 28 |
url = sound["url"] |
| 29 |
yield Message.Directory, "", sound |
| 30 |
yield Message.Url, url, text.nameext_from_url(url, sound) |
| 31 |
|
| 32 |
def _extract_sound(self, url): |
| 33 |
extr = text.extract_from(self.request(url).text) |
| 34 |
|
| 35 |
_, user, slug = url.rstrip("/").rsplit("/", 2) |
| 36 |
data = { |
| 37 |
"user" : user, |
| 38 |
"slug" : slug, |
| 39 |
"title": text.unescape(extr('aria-label="title">', "<")), |
| 40 |
"description": text.unescape(text.remove_html(extr( |
| 41 |
'class="jp-description">', '</div>'))), |
| 42 |
} |
| 43 |
|
| 44 |
formats = extr('"setMedia", {', '}') |
| 45 |
data["url"] = text.extr(formats, ': "', '"') |
| 46 |
|
| 47 |
return data |
| 48 |
|
| 49 |
|
| 50 |
class SoundgasmAudioExtractor(SoundgasmExtractor): |
| 51 |
"""Extractor for audio clips from soundgasm.net""" |
| 52 |
subcategory = "audio" |
| 53 |
pattern = BASE_PATTERN + r"/([^/?#]+)/([^/?#]+)" |
| 54 |
example = "https://soundgasm.net/u/USER/TITLE" |
| 55 |
|
| 56 |
def __init__(self, match): |
| 57 |
SoundgasmExtractor.__init__(self, match) |
| 58 |
self.user, self.slug = match.groups() |
| 59 |
|
| 60 |
def sounds(self): |
| 61 |
return (f"{self.root}/u/{self.user}/{self.slug}",) |
| 62 |
|
| 63 |
|
| 64 |
class SoundgasmUserExtractor(SoundgasmExtractor): |
| 65 |
"""Extractor for all sounds from a soundgasm user""" |
| 66 |
subcategory = "user" |
| 67 |
pattern = BASE_PATTERN + r"/([^/?#]+)/?$" |
| 68 |
example = "https://soundgasm.net/u/USER" |
| 69 |
|
| 70 |
def __init__(self, match): |
| 71 |
SoundgasmExtractor.__init__(self, match) |
| 72 |
self.user = match[1] |
| 73 |
|
| 74 |
def sounds(self): |
| 75 |
page = self.request(self.root + "/user/" + self.user).text |
| 76 |
return [ |
| 77 |
text.extr(sound, '<a href="', '"') |
| 78 |
for sound in text.extract_iter( |
| 79 |
page, 'class="sound-details">', "</a>") |
| 80 |
] |