diff --git a/README.rst b/README.rst index 15ac73c291..8b145edee9 100644 --- a/README.rst +++ b/README.rst @@ -156,7 +156,7 @@ Some extractors require you to provide valid login-credentials in the form of a username & password pair. This is necessary for ``pixiv``, ``nijie`` and ``seiga`` and optional (but strongly recommended) for ``exhentai``, ``luscious``, -``sankaku``, ``idolcomplex`` and ``wallhaven``. +``sankaku``, ``idolcomplex``, ``tsumino`` and ``wallhaven``. You can set the necessary information in your configuration file (cf. gallery-dl.conf_) diff --git a/docs/supportedsites.rst b/docs/supportedsites.rst index 36ff1da349..e298bb25f6 100644 --- a/docs/supportedsites.rst +++ b/docs/supportedsites.rst @@ -83,7 +83,7 @@ Simply Hentai https://www.simply-hentai.com/ Galleries, individual I SlideShare https://www.slideshare.net/ Presentations SmugMug https://www.smugmug.com/ |Capabilities-8| Optional (OAuth) The /b/ Archive https://thebarchive.com/ Threads -Tsumino https://www.tsumino.com/ Galleries +Tsumino https://www.tsumino.com/ Galleries Optional Tumblr https://www.tumblr.com/ Images from Users, Likes, Posts, Tag-Searches Optional (OAuth) Twitter https://twitter.com/ Media Timelines, Timelines, Tweets Wallhaven https://alpha.wallhaven.cc/ individual Images, Search Results Optional diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 2ec435f139..1a5e56e91f 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -223,6 +223,7 @@ def __init__(self, url): self.url = url def items(self): + self.login() page = self.request(self.url).text data = self.get_metadata(page) imgs = self.get_images(page) @@ -230,7 +231,7 @@ def items(self): if "count" in data: images = zip( range(1, data["count"]+1), - imgs + imgs, ) else: try: @@ -246,6 +247,9 @@ def items(self): data.update(imgdata) yield Message.Url, url, text.nameext_from_url(url, data) + def login(self): + """Login and set necessary cookies""" + def get_metadata(self, page): """Return a dict with general metadata""" diff --git a/gallery_dl/extractor/tsumino.py b/gallery_dl/extractor/tsumino.py index a8170b3491..1a46d84eb3 100644 --- a/gallery_dl/extractor/tsumino.py +++ b/gallery_dl/extractor/tsumino.py @@ -9,7 +9,8 @@ """Extractors for https://www.tsumino.com/""" from .common import ChapterExtractor -from .. import text +from .. import text, exception +from ..cache import cache class TsuminoGalleryExtractor(ChapterExtractor): @@ -19,6 +20,7 @@ class TsuminoGalleryExtractor(ChapterExtractor): filename_fmt = "{category}_{gallery_id}_{page:>03}.{extension}" directory_fmt = ["{category}", "{gallery_id} {title}"] archive_fmt = "{gallery_id}_{page}" + cookiedomain = "www.tsumino.com" pattern = [r"(?i)(?:https?://)?(?:www\.)?tsumino\.com" r"/(?:Book/Info|Read/View)/(\d+)"] test = [ @@ -35,8 +37,25 @@ def __init__(self, match): url = "{}/Book/Info/{}".format(self.root, self.gallery_id) ChapterExtractor.__init__(self, url) - self.session.cookies.setdefault( - "ASP.NET_SessionId", "x1drgggilez4cpkttneukrc5") + def login(self): + username, password = self._get_auth_info() + if username: + self._update_cookies(self._login_impl(username, password)) + else: + self.session.cookies.setdefault( + "ASP.NET_SessionId", "x1drgggilez4cpkttneukrc5") + + @cache(maxage=14*24*60*60, keyarg=1) + def _login_impl(self, username, password): + self.log.info("Logging in as %s", username) + url = "{}/Account/Login".format(self.root) + headers = {"Referer": url} + data = {"Username": username, "Password": password} + + response = self.request(url, method="POST", headers=headers, data=data) + if not response.history: + raise exception.AuthenticationError() + return {".aotsumino": response.history[0].cookies[".aotsumino"]} def get_metadata(self, page): extr = text.extract diff --git a/scripts/build_supportedsites.py b/scripts/build_supportedsites.py index a8f9a54dbc..e3905f3c90 100755 --- a/scripts/build_supportedsites.py +++ b/scripts/build_supportedsites.py @@ -100,6 +100,7 @@ "sankaku" : "Optional", "seiga" : "Required", "smugmug" : "Optional (OAuth)", + "tsumino" : "Optional", "tumblr" : "Optional (OAuth)", "wallhaven" : "Optional", }