aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/subscribestar.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/extractor/subscribestar.py')
-rw-r--r--gallery_dl/extractor/subscribestar.py67
1 files changed, 49 insertions, 18 deletions
diff --git a/gallery_dl/extractor/subscribestar.py b/gallery_dl/extractor/subscribestar.py
index 5d0ec46..1054a63 100644
--- a/gallery_dl/extractor/subscribestar.py
+++ b/gallery_dl/extractor/subscribestar.py
@@ -23,14 +23,15 @@ class SubscribestarExtractor(Extractor):
directory_fmt = ("{category}", "{author_name}")
filename_fmt = "{post_id}_{id}.{extension}"
archive_fmt = "{id}"
- cookies_domain = "www.subscribestar.com"
- cookies_names = ("auth_token",)
+ cookies_domain = ".subscribestar.com"
+ cookies_names = ("_personalization_id",)
+ _warning = True
def __init__(self, match):
tld, self.item = match.groups()
if tld == "adult":
self.root = "https://subscribestar.adult"
- self.cookies_domain = "subscribestar.adult"
+ self.cookies_domain = ".subscribestar.adult"
self.subcategory += "-adult"
Extractor.__init__(self, match)
@@ -78,34 +79,64 @@ class SubscribestarExtractor(Extractor):
username, password = self._get_auth_info()
if username:
- self.cookies_update(self._login_impl(username, password))
+ self.cookies_update(self._login_impl(
+ (username, self.cookies_domain), password))
+
+ if self._warning:
+ if not username or not self.cookies_check(self.cookies_names):
+ self.log.warning("no '_personalization_id' cookie set")
+ SubscribestarExtractor._warning = False
@cache(maxage=28*86400, keyarg=1)
def _login_impl(self, username, password):
+ username = username[0]
self.log.info("Logging in as %s", username)
- url = "https://www.subscribestar.com/session.json"
+ if self.root.endswith(".adult"):
+ self.cookies.set("18_plus_agreement_generic", "true",
+ domain=self.cookies_domain)
+
+ # load login page
+ url = self.root + "/login"
+ page = self.request(url).text
+
headers = {
- "Origin" : "https://www.subscribestar.com",
- "Referer" : "https://www.subscribestar.com/login",
+ "Accept": "*/*;q=0.5, text/javascript, application/javascript, "
+ "application/ecmascript, application/x-ecmascript",
+ "Referer": self.root + "/login",
+ "X-CSRF-Token": text.unescape(text.extr(
+ page, '<meta name="csrf-token" content="', '"')),
+ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"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()
+ def check_errors(response):
+ errors = response.json().get("errors")
+ if errors:
+ self.log.debug(errors)
+ try:
+ msg = '"{}"'.format(errors.popitem()[1])
+ except Exception:
+ msg = None
+ raise exception.AuthenticationError(msg)
+ return response
+
+ # submit username / email
+ url = self.root + "/session.json"
+ data = {"email": username}
+ response = check_errors(self.request(
+ url, method="POST", headers=headers, data=data, fatal=False))
+
+ # submit password
+ url = self.root + "/session/password.json"
+ data = {"password": password}
+ response = check_errors(self.request(
+ url, method="POST", headers=headers, data=data, fatal=False))
+ # return cookies
return {
cookie.name: cookie.value
for cookie in response.cookies
- if cookie.name.startswith("auth")
}
def _media_from_post(self, html):