2020-07-03 21:08:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-02-07 23:14:53 +01:00
|
|
|
# Copyright 2020-2023 Mike Fährmann
|
2020-07-03 21:08:47 +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.
|
|
|
|
|
|
|
|
"""Extractors for https://www.subscribestar.com/"""
|
|
|
|
|
|
|
|
from .common import Extractor, Message
|
2023-02-07 23:14:53 +01:00
|
|
|
from .. import text, util, exception
|
2020-07-17 19:42:32 +02:00
|
|
|
from ..cache import cache
|
2020-07-03 21:08:47 +02:00
|
|
|
|
|
|
|
BASE_PATTERN = r"(?:https?://)?(?:www\.)?subscribestar\.(com|adult)"
|
|
|
|
|
|
|
|
|
|
|
|
class SubscribestarExtractor(Extractor):
|
|
|
|
"""Base class for subscribestar extractors"""
|
|
|
|
category = "subscribestar"
|
|
|
|
root = "https://www.subscribestar.com"
|
|
|
|
directory_fmt = ("{category}", "{author_name}")
|
|
|
|
filename_fmt = "{post_id}_{id}.{extension}"
|
|
|
|
archive_fmt = "{id}"
|
2023-07-21 22:38:39 +02:00
|
|
|
cookies_domain = "www.subscribestar.com"
|
|
|
|
cookies_names = ("auth_token",)
|
2020-07-03 21:08:47 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
tld, self.item = match.groups()
|
|
|
|
if tld == "adult":
|
|
|
|
self.root = "https://subscribestar.adult"
|
2023-07-21 22:38:39 +02:00
|
|
|
self.cookies_domain = "subscribestar.adult"
|
2020-07-03 21:08:47 +02:00
|
|
|
self.subcategory += "-adult"
|
|
|
|
Extractor.__init__(self, match)
|
|
|
|
|
|
|
|
def items(self):
|
2020-07-17 19:42:32 +02:00
|
|
|
self.login()
|
2020-07-03 21:08:47 +02:00
|
|
|
for post_html in self.posts():
|
|
|
|
media = self._media_from_post(post_html)
|
|
|
|
data = self._data_from_post(post_html)
|
|
|
|
yield Message.Directory, data
|
2021-11-18 23:38:41 +01:00
|
|
|
for num, item in enumerate(media, 1):
|
2020-07-03 21:08:47 +02:00
|
|
|
item.update(data)
|
2021-11-18 23:38:41 +01:00
|
|
|
item["num"] = num
|
2021-06-10 17:09:13 +02:00
|
|
|
text.nameext_from_url(item.get("name") or item["url"], item)
|
2024-05-23 19:12:01 +02:00
|
|
|
if item["url"][0] == "/":
|
|
|
|
item["url"] = self.root + item["url"]
|
2021-06-10 17:09:13 +02:00
|
|
|
yield Message.Url, item["url"], item
|
2020-07-03 21:08:47 +02:00
|
|
|
|
|
|
|
def posts(self):
|
|
|
|
"""Yield HTML content of all relevant posts"""
|
|
|
|
|
2020-07-17 19:42:32 +02:00
|
|
|
def login(self):
|
2023-07-21 22:38:39 +02:00
|
|
|
if self.cookies_check(self.cookies_names):
|
2020-07-17 19:42:32 +02:00
|
|
|
return
|
2023-07-21 22:38:39 +02:00
|
|
|
|
2020-07-17 19:42:32 +02:00
|
|
|
username, password = self._get_auth_info()
|
|
|
|
if username:
|
2023-07-21 22:38:39 +02:00
|
|
|
self.cookies_update(self._login_impl(username, password))
|
2020-07-17 19:42:32 +02:00
|
|
|
|
2023-12-18 23:19:44 +01:00
|
|
|
@cache(maxage=28*86400, keyarg=1)
|
2020-07-17 19:42:32 +02:00
|
|
|
def _login_impl(self, username, password):
|
|
|
|
self.log.info("Logging in as %s", username)
|
|
|
|
|
|
|
|
url = "https://www.subscribestar.com/session.json"
|
|
|
|
headers = {
|
|
|
|
"Origin" : "https://www.subscribestar.com",
|
|
|
|
"Referer" : "https://www.subscribestar.com/login",
|
|
|
|
"X-Requested-With": "XMLHttpRequest",
|
|
|
|
}
|
|
|
|
data = {
|
|
|
|
"utf8" : "✓",
|
|
|
|
"email" : username,
|
|
|
|
"password": password,
|
|
|
|
}
|
|
|
|
|
|
|
|
response = self.request(
|
|
|
|
url, method="POST", headers=headers, data=data, fatal=False)
|
|
|
|
if response.json().get("errors"):
|
|
|
|
self.log.debug(response.json()["errors"])
|
|
|
|
raise exception.AuthenticationError()
|
|
|
|
|
|
|
|
return {
|
|
|
|
cookie.name: cookie.value
|
|
|
|
for cookie in response.cookies
|
|
|
|
if cookie.name.startswith("auth")
|
|
|
|
}
|
|
|
|
|
2023-09-04 22:04:52 +02:00
|
|
|
def _media_from_post(self, html):
|
2020-08-03 22:02:42 +02:00
|
|
|
media = []
|
|
|
|
|
2022-11-04 23:39:38 +01:00
|
|
|
gallery = text.extr(html, 'data-gallery="', '"')
|
2020-07-03 21:08:47 +02:00
|
|
|
if gallery:
|
2023-09-04 22:04:52 +02:00
|
|
|
for item in util.json_loads(text.unescape(gallery)):
|
|
|
|
if "/previews" in item["url"]:
|
|
|
|
self._warn_preview()
|
|
|
|
else:
|
|
|
|
media.append(item)
|
2020-08-03 22:02:42 +02:00
|
|
|
|
2022-11-04 23:39:38 +01:00
|
|
|
attachments = text.extr(
|
|
|
|
html, 'class="uploads-docs"', 'data-role="post-edit_form"')
|
2020-08-03 22:02:42 +02:00
|
|
|
if attachments:
|
|
|
|
for att in attachments.split('class="doc_preview"')[1:]:
|
|
|
|
media.append({
|
2022-11-04 23:39:38 +01:00
|
|
|
"id" : text.parse_int(text.extr(
|
|
|
|
att, 'data-upload-id="', '"')),
|
|
|
|
"name": text.unescape(text.extr(
|
|
|
|
att, 'doc_preview-title">', '<')),
|
|
|
|
"url" : text.unescape(text.extr(att, 'href="', '"')),
|
2020-08-03 22:02:42 +02:00
|
|
|
"type": "attachment",
|
|
|
|
})
|
|
|
|
|
|
|
|
return media
|
2020-07-03 21:08:47 +02:00
|
|
|
|
|
|
|
def _data_from_post(self, html):
|
|
|
|
extr = text.extract_from(html)
|
2020-07-24 22:27:36 +02:00
|
|
|
return {
|
2020-07-03 21:08:47 +02:00
|
|
|
"post_id" : text.parse_int(extr('data-id="', '"')),
|
|
|
|
"author_id" : text.parse_int(extr('data-user-id="', '"')),
|
|
|
|
"author_name": text.unescape(extr('href="/', '"')),
|
|
|
|
"author_nick": text.unescape(extr('>', '<')),
|
2022-06-04 12:19:16 +02:00
|
|
|
"date" : self._parse_datetime(extr(
|
|
|
|
'class="post-date">', '</').rpartition(">")[2]),
|
2020-07-03 21:08:47 +02:00
|
|
|
"content" : (extr(
|
|
|
|
'<div class="post-content', '<div class="post-uploads')
|
|
|
|
.partition(">")[2]),
|
|
|
|
}
|
|
|
|
|
2020-07-09 22:12:39 +02:00
|
|
|
def _parse_datetime(self, dt):
|
2024-06-24 16:40:59 +02:00
|
|
|
if dt.startswith("Updated on "):
|
|
|
|
dt = dt[11:]
|
2020-07-24 22:27:36 +02:00
|
|
|
date = text.parse_datetime(dt, "%b %d, %Y %I:%M %p")
|
2020-07-03 21:08:47 +02:00
|
|
|
if date is dt:
|
2020-07-24 22:27:36 +02:00
|
|
|
date = text.parse_datetime(dt, "%B %d, %Y %I:%M %p")
|
2020-07-03 21:08:47 +02:00
|
|
|
return date
|
|
|
|
|
2023-09-04 22:04:52 +02:00
|
|
|
def _warn_preview(self):
|
|
|
|
self.log.warning("Preview image detected")
|
|
|
|
self._warn_preview = util.noop
|
|
|
|
|
2020-07-03 21:08:47 +02:00
|
|
|
|
|
|
|
class SubscribestarUserExtractor(SubscribestarExtractor):
|
|
|
|
"""Extractor for media from a subscribestar user"""
|
|
|
|
subcategory = "user"
|
2020-10-22 23:12:59 +02:00
|
|
|
pattern = BASE_PATTERN + r"/(?!posts/)([^/?#]+)"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://www.subscribestar.com/USER"
|
2020-07-03 21:08:47 +02:00
|
|
|
|
|
|
|
def posts(self):
|
|
|
|
needle_next_page = 'data-role="infinite_scroll-next_page" href="'
|
|
|
|
page = self.request("{}/{}".format(self.root, self.item)).text
|
|
|
|
|
|
|
|
while True:
|
|
|
|
posts = page.split('<div class="post ')[1:]
|
|
|
|
if not posts:
|
|
|
|
return
|
|
|
|
yield from posts
|
|
|
|
|
2022-11-04 23:39:38 +01:00
|
|
|
url = text.extr(posts[-1], needle_next_page, '"')
|
2020-07-03 21:08:47 +02:00
|
|
|
if not url:
|
|
|
|
return
|
|
|
|
page = self.request(self.root + text.unescape(url)).json()["html"]
|
|
|
|
|
|
|
|
|
|
|
|
class SubscribestarPostExtractor(SubscribestarExtractor):
|
|
|
|
"""Extractor for media from a single subscribestar post"""
|
|
|
|
subcategory = "post"
|
|
|
|
pattern = BASE_PATTERN + r"/posts/(\d+)"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://www.subscribestar.com/posts/12345"
|
2020-07-03 21:08:47 +02:00
|
|
|
|
|
|
|
def posts(self):
|
|
|
|
url = "{}/posts/{}".format(self.root, self.item)
|
2020-07-24 22:27:36 +02:00
|
|
|
return (self.request(url).text,)
|
2020-07-03 21:08:47 +02:00
|
|
|
|
|
|
|
def _data_from_post(self, html):
|
|
|
|
extr = text.extract_from(html)
|
|
|
|
return {
|
|
|
|
"post_id" : text.parse_int(extr('data-id="', '"')),
|
|
|
|
"author_name": text.unescape(extr('href="/', '"')),
|
|
|
|
"author_id" : text.parse_int(extr('data-user-id="', '"')),
|
|
|
|
"author_nick": text.unescape(extr('alt="', '"')),
|
|
|
|
"date" : self._parse_datetime(extr(
|
2024-03-22 00:45:09 +01:00
|
|
|
'<span class="star_link-types">', '<')),
|
2020-07-03 21:08:47 +02:00
|
|
|
"content" : (extr(
|
|
|
|
'<div class="post-content', '<div class="post-uploads')
|
|
|
|
.partition(">")[2]),
|
|
|
|
}
|