Skip to content

Commit

Permalink
[pillowfort] implement login with username & password (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed May 19, 2021
1 parent 24dd10a commit 1eabfa5
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ and optional for
``inkbunny``,
``instagram``,
``mangoxo``,
``pillowfort``,
``pinterest``,
``sankaku``,
``subscribestar``,
Expand Down
3 changes: 2 additions & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ Description
* ``inkbunny``
* ``instagram``
* ``mangoxo``
* ``pillowfort``
* ``pinterest``
* ``sankaku``
* ``subscribestar``
Expand Down Expand Up @@ -1843,7 +1844,7 @@ Description
Note: This requires 1 additional HTTP request for each post.

extractor.[booru].notes
----------------------
-----------------------
Type
``bool``
Default
Expand Down
2 changes: 1 addition & 1 deletion docs/supportedsites.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ Consider all sites to be NSFW unless otherwise known.
<td>Pillowfort</td>
<td>https://www.pillowfort.social/</td>
<td>Posts, User Profiles</td>
<td></td>
<td>Supported</td>
</tr>
<tr>
<td>Pinterest</td>
Expand Down
44 changes: 42 additions & 2 deletions gallery_dl/extractor/pillowfort.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"""Extractors for https://www.pillowfort.social/"""

from .common import Extractor, Message
from .. import text
from ..cache import cache
from .. import text, exception
import re

BASE_PATTERN = r"(?:https?://)?www\.pillowfort\.social"
Expand All @@ -20,15 +21,17 @@ class PillowfortExtractor(Extractor):
category = "pillowfort"
root = "https://www.pillowfort.social"
directory_fmt = ("{category}", "{username}")
filename_fmt = ("{post_id} {title|original_post[title]} "
filename_fmt = ("{post_id} {title|original_post[title]:?/ /}"
"{num:>02}.{extension}")
archive_fmt = "{id}"
cookiedomain = "www.pillowfort.social"

def __init__(self, match):
Extractor.__init__(self, match)
self.item = match.group(1)

def items(self):
self.login()
inline = self.config("inline", True)
reblogs = self.config("reblogs", False)
external = self.config("external", False)
Expand Down Expand Up @@ -78,6 +81,43 @@ def items(self):

yield msgtype, url, post

def login(self):
cget = self.session.cookies.get
if cget("_Pf_new_session", domain=self.cookiedomain) \
or cget("remember_user_token", domain=self.cookiedomain):
return

username, password = self._get_auth_info()
if username:
cookies = self._login_impl(username, password)
self._update_cookies(cookies)

@cache(maxage=14*24*3600, keyarg=1)
def _login_impl(self, username, password):
self.log.info("Logging in as %s", username)

url = "https://www.pillowfort.social/users/sign_in"
page = self.request(url).text
auth = text.extract(page, 'name="authenticity_token" value="', '"')[0]

headers = {"Origin": self.root, "Referer": url}
data = {
"utf8" : "✓",
"authenticity_token": auth,
"user[email]" : username,
"user[password]" : password,
"user[remember_me]" : "1",
}
response = self.request(url, method="POST", headers=headers, data=data)

if not response.history:
raise exception.AuthenticationError()

return {
cookie.name: cookie.value
for cookie in response.history[0].cookies
}


class PillowfortPostExtractor(PillowfortExtractor):
"""Extractor for a single pillowfort post"""
Expand Down
1 change: 1 addition & 0 deletions scripts/supportedsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
"nijie" : "Required",
"patreon" : _COOKIES,
"pawoo" : _OAUTH,
"pillowfort" : "Supported",
"pinterest" : "Supported",
"pixiv" : _OAUTH,
"ponybooru" : "API Key",
Expand Down
2 changes: 1 addition & 1 deletion test/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def setup_test_config():
config.set(("extractor", "mangoxo") , "password", "5zbQF10_5u25259Ma")

for category in ("danbooru", "instagram", "twitter", "subscribestar",
"e621", "inkbunny", "tapas"):
"e621", "inkbunny", "tapas", "pillowfort"):
config.set(("extractor", category), "username", None)

config.set(("extractor", "mastodon.social"), "access-token",
Expand Down

0 comments on commit 1eabfa5

Please sign in to comment.