From d5aad999dcb6a124ad8b826a25185a05c9b94b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 29 Mar 2021 23:06:47 +0200 Subject: [PATCH] [tapas] implement login with username & password (#692) --- README.rst | 1 + docs/configuration.rst | 1 + docs/supportedsites.md | 2 +- gallery_dl/extractor/tapas.py | 43 +++++++++++++++++++++++++++++++---- scripts/supportedsites.py | 1 + 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 6d412bb4..976fd492 100644 --- a/README.rst +++ b/README.rst @@ -212,6 +212,7 @@ and optional for ``pinterest``, ``sankaku``, ``subscribestar``, +``tapas``, ``tsumino``, and ``twitter``. diff --git a/docs/configuration.rst b/docs/configuration.rst index f695d28b..d89bba86 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -299,6 +299,7 @@ Description * ``pinterest`` * ``sankaku`` * ``subscribestar`` + * ``tapas`` * ``tsumino`` * ``twitter`` diff --git a/docs/supportedsites.md b/docs/supportedsites.md index 3a10fde8..d727b140 100644 --- a/docs/supportedsites.md +++ b/docs/supportedsites.md @@ -647,7 +647,7 @@ Consider all sites to be NSFW unless otherwise known. Tapas https://tapas.io/ Episodes, Series - + Supported Tsumino diff --git a/gallery_dl/extractor/tapas.py b/gallery_dl/extractor/tapas.py index 93c8ae3c..ec1e0441 100644 --- a/gallery_dl/extractor/tapas.py +++ b/gallery_dl/extractor/tapas.py @@ -10,6 +10,7 @@ from .common import Extractor, Message from .. import text, exception +from ..cache import cache BASE_PATTERN = r"(?:https?://)?tapas\.io" @@ -21,15 +22,17 @@ class TapasExtractor(Extractor): directory_fmt = ("{category}", "{series[title]}", "{id} {title}") filename_fmt = "{num:>02}.{extension}" archive_fmt = "{id}_{num}" - _cache = {} + cookiedomain = ".tapas.io" + cookienames = ("_cpc_",) + _cache = None def __init__(self, match): Extractor.__init__(self, match) - setcookie = self.session.cookies.set - setcookie("birthDate" , "1981-02-03", domain=".tapas.io") - setcookie("adjustedBirthDate", "1981-02-03", domain=".tapas.io") + if self._cache is None: + TapasExtractor._cache = {} def items(self): + self.login() headers = {"Accept": "application/json, text/javascript, */*;"} for episode_id in self.episode_ids(): @@ -66,6 +69,38 @@ class TapasExtractor(Extractor): html, 'data-src="', '"'), 1): yield Message.Url, url, text.nameext_from_url(url, episode) + def login(self): + if not self._check_cookies(self.cookienames): + username, password = self._get_auth_info() + if username: + self._update_cookies(self._login_impl(username, password)) + else: + sc = self.session.cookies.set + sc("birthDate" , "1981-02-03", domain=self.cookiedomain) + sc("adjustedBirthDate", "1981-02-03", domain=self.cookiedomain) + + @cache(maxage=14*24*3600, keyarg=1) + def _login_impl(self, username, password): + self.log.info("Logging in as %s", username) + + url = self.root + "/account/authenticate" + headers = { + "Referer" : url, + } + data = { + "from" : "https://tapas.io/", + "email" : username, + "password": password, + } + response = self.request( + url, method="POST", headers=headers, data=data) + + if not response.history or \ + "/account/signin_fail" in response.history[-1].url: + raise exception.AuthenticationError() + + return {"_cpc_": response.history[0].cookies.get("_cpc_")} + class TapasSeriesExtractor(TapasExtractor): subcategory = "series" diff --git a/scripts/supportedsites.py b/scripts/supportedsites.py index 174f71da..2ac11351 100755 --- a/scripts/supportedsites.py +++ b/scripts/supportedsites.py @@ -224,6 +224,7 @@ AUTH_MAP = { "seiga" : "Required", "smugmug" : _OAUTH, "subscribestar" : "Supported", + "tapas" : "Supported", "tsumino" : "Supported", "tumblr" : _OAUTH, "twitter" : "Supported",