For the record: '/webtoken' and '/weblogin' are not the same ...
This commit is contained in:
@@ -382,6 +382,7 @@ Description
|
|||||||
* ``e621`` (*)
|
* ``e621`` (*)
|
||||||
* ``e926`` (*)
|
* ``e926`` (*)
|
||||||
* ``exhentai``
|
* ``exhentai``
|
||||||
|
* ``gfycat``
|
||||||
* ``idolcomplex``
|
* ``idolcomplex``
|
||||||
* ``imgbb``
|
* ``imgbb``
|
||||||
* ``inkbunny``
|
* ``inkbunny``
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ Consider all sites to be NSFW unless otherwise known.
|
|||||||
<td>Gfycat</td>
|
<td>Gfycat</td>
|
||||||
<td>https://gfycat.com/</td>
|
<td>https://gfycat.com/</td>
|
||||||
<td>Collections, individual Images, Search Results, User Profiles</td>
|
<td>Collections, individual Images, Search Results, User Profiles</td>
|
||||||
<td></td>
|
<td>Supported</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Gofile</td>
|
<td>Gofile</td>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
from .common import Extractor, Message
|
from .common import Extractor, Message
|
||||||
from .. import text, exception
|
from .. import text, exception
|
||||||
|
from ..cache import cache
|
||||||
|
|
||||||
|
|
||||||
class GfycatExtractor(Extractor):
|
class GfycatExtractor(Extractor):
|
||||||
@@ -221,6 +222,8 @@ class GfycatAPI():
|
|||||||
|
|
||||||
def __init__(self, extractor):
|
def __init__(self, extractor):
|
||||||
self.extractor = extractor
|
self.extractor = extractor
|
||||||
|
self.headers = {}
|
||||||
|
self.username, self.password = extractor._get_auth_info()
|
||||||
|
|
||||||
def collection(self, user, collection):
|
def collection(self, user, collection):
|
||||||
endpoint = "/v1/users/{}/collections/{}/gfycats".format(
|
endpoint = "/v1/users/{}/collections/{}/gfycats".format(
|
||||||
@@ -252,9 +255,45 @@ class GfycatAPI():
|
|||||||
params = {"count": 100}
|
params = {"count": 100}
|
||||||
return self._pagination(endpoint, params)
|
return self._pagination(endpoint, params)
|
||||||
|
|
||||||
|
def authenticate(self):
|
||||||
|
self.headers["Authorization"] = \
|
||||||
|
self._authenticate_impl(self.username, self.password)
|
||||||
|
|
||||||
|
@cache(maxage=3600, keyarg=1)
|
||||||
|
def _authenticate_impl(self, username, password):
|
||||||
|
self.extractor.log.info("Logging in as %s", username)
|
||||||
|
|
||||||
|
url = "https://weblogin.gfycat.com/oauth/webtoken"
|
||||||
|
headers = {"Origin": "https://gfycat.com"}
|
||||||
|
data = {
|
||||||
|
"access_key": "Anr96uuqt9EdamSCwK4txKPjMsf2"
|
||||||
|
"M95Rfa5FLLhPFucu8H5HTzeutyAa",
|
||||||
|
}
|
||||||
|
response = self.extractor.request(
|
||||||
|
url, method="POST", headers=headers, json=data).json()
|
||||||
|
|
||||||
|
url = "https://weblogin.gfycat.com/oauth/weblogin"
|
||||||
|
headers["authorization"] = "Bearer " + response["access_token"]
|
||||||
|
data = {
|
||||||
|
"grant_type": "password",
|
||||||
|
"username" : username,
|
||||||
|
"password" : password,
|
||||||
|
}
|
||||||
|
response = self.extractor.request(
|
||||||
|
url, method="POST", headers=headers, json=data, fatal=None).json()
|
||||||
|
|
||||||
|
if "errorMessage" in response:
|
||||||
|
raise exception.AuthenticationError(
|
||||||
|
response["errorMessage"]["description"])
|
||||||
|
return "Bearer " + response["access_token"]
|
||||||
|
|
||||||
def _call(self, endpoint, params=None):
|
def _call(self, endpoint, params=None):
|
||||||
|
if self.username:
|
||||||
|
self.authenticate()
|
||||||
|
|
||||||
url = self.API_ROOT + endpoint
|
url = self.API_ROOT + endpoint
|
||||||
return self.extractor.request(url, params=params).json()
|
return self.extractor.request(
|
||||||
|
url, params=params, headers=self.headers).json()
|
||||||
|
|
||||||
def _pagination(self, endpoint, params, key="gfycats"):
|
def _pagination(self, endpoint, params, key="gfycats"):
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
@@ -312,6 +312,7 @@ AUTH_MAP = {
|
|||||||
"fanbox" : _COOKIES,
|
"fanbox" : _COOKIES,
|
||||||
"fantia" : _COOKIES,
|
"fantia" : _COOKIES,
|
||||||
"flickr" : _OAUTH,
|
"flickr" : _OAUTH,
|
||||||
|
"gfycat" : "Supported",
|
||||||
"furaffinity" : _COOKIES,
|
"furaffinity" : _COOKIES,
|
||||||
"horne" : "Required",
|
"horne" : "Required",
|
||||||
"idolcomplex" : "Supported",
|
"idolcomplex" : "Supported",
|
||||||
|
|||||||
@@ -325,7 +325,7 @@ def setup_test_config():
|
|||||||
for category in ("danbooru", "atfbooru", "aibooru", "e621", "e926",
|
for category in ("danbooru", "atfbooru", "aibooru", "e621", "e926",
|
||||||
"instagram", "twitter", "subscribestar", "deviantart",
|
"instagram", "twitter", "subscribestar", "deviantart",
|
||||||
"inkbunny", "tapas", "pillowfort", "mangadex",
|
"inkbunny", "tapas", "pillowfort", "mangadex",
|
||||||
"vipergirls"):
|
"vipergirls", "gfycat"):
|
||||||
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