summaryrefslogtreecommitdiffstats
path: root/gallery_dl/extractor/redgifs.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2022-11-01 21:32:54 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2022-11-01 21:32:54 -0400
commite59d46ecda74190381b1d2725b0bd9df5c0be8d8 (patch)
treecff6d69d4f68ef011a496ff2311173ebef70bf3f /gallery_dl/extractor/redgifs.py
parent78e2d1672e4301497f786cd03637de9ddbc717ac (diff)
New upstream version 1.23.5.upstream/1.23.5
Diffstat (limited to 'gallery_dl/extractor/redgifs.py')
-rw-r--r--gallery_dl/extractor/redgifs.py32
1 files changed, 14 insertions, 18 deletions
diff --git a/gallery_dl/extractor/redgifs.py b/gallery_dl/extractor/redgifs.py
index 1111c3a..53e5e79 100644
--- a/gallery_dl/extractor/redgifs.py
+++ b/gallery_dl/extractor/redgifs.py
@@ -10,7 +10,7 @@
from .common import Extractor, Message
from .. import text
-from ..cache import cache
+from ..cache import memcache
class RedgifsExtractor(Extractor):
@@ -133,10 +133,11 @@ class RedgifsAPI():
def __init__(self, extractor):
self.extractor = extractor
self.headers = {
- "Referer" : extractor.root + "/",
- "authorization": "Bearer " + self._fetch_bearer_token(extractor),
- "content-type" : "application/json",
- "Origin" : extractor.root,
+ "Referer" : extractor.root + "/",
+ "authorization" : None,
+ "content-type" : "application/json",
+ "x-customheader": extractor.root + "/",
+ "Origin" : extractor.root,
}
def gif(self, gif_id):
@@ -156,6 +157,7 @@ class RedgifsAPI():
def _call(self, endpoint, params=None):
url = self.API_ROOT + endpoint
+ self.headers["authorization"] = self._auth()
return self.extractor.request(
url, params=params, headers=self.headers).json()
@@ -170,16 +172,10 @@ class RedgifsAPI():
return
params["page"] += 1
- @cache(maxage=3600)
- def _fetch_bearer_token(self, extr):
- extr.log.debug("Retrieving Bearer token")
-
- page = extr.request(extr.root + "/").text
- index = text.extract(page, "/assets/js/index", ".js")[0]
-
- url = extr.root + "/assets/js/index" + index + ".js"
- page = extr.request(url, encoding="utf-8").text
- token = "ey" + text.extract(page, '="ey', '"')[0]
-
- extr.log.debug("Token: '%s'", token)
- return token
+ @memcache(maxage=600)
+ def _auth(self):
+ # https://github.com/Redgifs/api/wiki/Temporary-tokens
+ url = self.API_ROOT + "/v2/auth/temporary"
+ self.headers["authorization"] = None
+ return "Bearer " + self.extractor.request(
+ url, headers=self.headers).json()["token"]