Skip to content

Commit

Permalink
[tsumino] add login capabilities (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Jan 30, 2019
1 parent dd358b4 commit bfbbac4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down
2 changes: 1 addition & 1 deletion docs/supportedsites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion gallery_dl/extractor/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,15 @@ 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)

if "count" in data:
images = zip(
range(1, data["count"]+1),
imgs
imgs,
)
else:
try:
Expand All @@ -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"""

Expand Down
25 changes: 22 additions & 3 deletions gallery_dl/extractor/tsumino.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 = [
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/build_supportedsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"sankaku" : "Optional",
"seiga" : "Required",
"smugmug" : "Optional (OAuth)",
"tsumino" : "Optional",
"tumblr" : "Optional (OAuth)",
"wallhaven" : "Optional",
}
Expand Down

0 comments on commit bfbbac4

Please sign in to comment.