[pillowfort] implement login with username & password (#846)
This commit is contained in:
@@ -210,6 +210,7 @@ and optional for
|
|||||||
``inkbunny``,
|
``inkbunny``,
|
||||||
``instagram``,
|
``instagram``,
|
||||||
``mangoxo``,
|
``mangoxo``,
|
||||||
|
``pillowfort``,
|
||||||
``pinterest``,
|
``pinterest``,
|
||||||
``sankaku``,
|
``sankaku``,
|
||||||
``subscribestar``,
|
``subscribestar``,
|
||||||
|
|||||||
@@ -310,6 +310,7 @@ Description
|
|||||||
* ``inkbunny``
|
* ``inkbunny``
|
||||||
* ``instagram``
|
* ``instagram``
|
||||||
* ``mangoxo``
|
* ``mangoxo``
|
||||||
|
* ``pillowfort``
|
||||||
* ``pinterest``
|
* ``pinterest``
|
||||||
* ``sankaku``
|
* ``sankaku``
|
||||||
* ``subscribestar``
|
* ``subscribestar``
|
||||||
@@ -1843,7 +1844,7 @@ Description
|
|||||||
Note: This requires 1 additional HTTP request for each post.
|
Note: This requires 1 additional HTTP request for each post.
|
||||||
|
|
||||||
extractor.[booru].notes
|
extractor.[booru].notes
|
||||||
----------------------
|
-----------------------
|
||||||
Type
|
Type
|
||||||
``bool``
|
``bool``
|
||||||
Default
|
Default
|
||||||
|
|||||||
@@ -527,7 +527,7 @@ Consider all sites to be NSFW unless otherwise known.
|
|||||||
<td>Pillowfort</td>
|
<td>Pillowfort</td>
|
||||||
<td>https://www.pillowfort.social/</td>
|
<td>https://www.pillowfort.social/</td>
|
||||||
<td>Posts, User Profiles</td>
|
<td>Posts, User Profiles</td>
|
||||||
<td></td>
|
<td>Supported</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Pinterest</td>
|
<td>Pinterest</td>
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
"""Extractors for https://www.pillowfort.social/"""
|
"""Extractors for https://www.pillowfort.social/"""
|
||||||
|
|
||||||
from .common import Extractor, Message
|
from .common import Extractor, Message
|
||||||
from .. import text
|
from ..cache import cache
|
||||||
|
from .. import text, exception
|
||||||
import re
|
import re
|
||||||
|
|
||||||
BASE_PATTERN = r"(?:https?://)?www\.pillowfort\.social"
|
BASE_PATTERN = r"(?:https?://)?www\.pillowfort\.social"
|
||||||
@@ -20,15 +21,17 @@ class PillowfortExtractor(Extractor):
|
|||||||
category = "pillowfort"
|
category = "pillowfort"
|
||||||
root = "https://www.pillowfort.social"
|
root = "https://www.pillowfort.social"
|
||||||
directory_fmt = ("{category}", "{username}")
|
directory_fmt = ("{category}", "{username}")
|
||||||
filename_fmt = ("{post_id} {title|original_post[title]} "
|
filename_fmt = ("{post_id} {title|original_post[title]:?/ /}"
|
||||||
"{num:>02}.{extension}")
|
"{num:>02}.{extension}")
|
||||||
archive_fmt = "{id}"
|
archive_fmt = "{id}"
|
||||||
|
cookiedomain = "www.pillowfort.social"
|
||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
Extractor.__init__(self, match)
|
Extractor.__init__(self, match)
|
||||||
self.item = match.group(1)
|
self.item = match.group(1)
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
|
self.login()
|
||||||
inline = self.config("inline", True)
|
inline = self.config("inline", True)
|
||||||
reblogs = self.config("reblogs", False)
|
reblogs = self.config("reblogs", False)
|
||||||
external = self.config("external", False)
|
external = self.config("external", False)
|
||||||
@@ -78,6 +81,43 @@ class PillowfortExtractor(Extractor):
|
|||||||
|
|
||||||
yield msgtype, url, post
|
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):
|
class PillowfortPostExtractor(PillowfortExtractor):
|
||||||
"""Extractor for a single pillowfort post"""
|
"""Extractor for a single pillowfort post"""
|
||||||
|
|||||||
@@ -223,6 +223,7 @@ AUTH_MAP = {
|
|||||||
"nijie" : "Required",
|
"nijie" : "Required",
|
||||||
"patreon" : _COOKIES,
|
"patreon" : _COOKIES,
|
||||||
"pawoo" : _OAUTH,
|
"pawoo" : _OAUTH,
|
||||||
|
"pillowfort" : "Supported",
|
||||||
"pinterest" : "Supported",
|
"pinterest" : "Supported",
|
||||||
"pixiv" : _OAUTH,
|
"pixiv" : _OAUTH,
|
||||||
"ponybooru" : "API Key",
|
"ponybooru" : "API Key",
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ def setup_test_config():
|
|||||||
config.set(("extractor", "mangoxo") , "password", "5zbQF10_5u25259Ma")
|
config.set(("extractor", "mangoxo") , "password", "5zbQF10_5u25259Ma")
|
||||||
|
|
||||||
for category in ("danbooru", "instagram", "twitter", "subscribestar",
|
for category in ("danbooru", "instagram", "twitter", "subscribestar",
|
||||||
"e621", "inkbunny", "tapas"):
|
"e621", "inkbunny", "tapas", "pillowfort"):
|
||||||
config.set(("extractor", category), "username", None)
|
config.set(("extractor", category), "username", None)
|
||||||
|
|
||||||
config.set(("extractor", "mastodon.social"), "access-token",
|
config.set(("extractor", "mastodon.social"), "access-token",
|
||||||
|
|||||||
Reference in New Issue
Block a user