[deviantart] improve public-private token switching
- rename option to `prefer-public` - now also works for galleries with less than 24 items
This commit is contained in:
@@ -333,6 +333,23 @@ Description Download full-sized original images if available.
|
||||
=========== =====
|
||||
|
||||
|
||||
extractor.deviantart.prefer-public
|
||||
----------------------------------
|
||||
=========== =====
|
||||
Type ``bool``
|
||||
Default ``false``
|
||||
Description Call API endpoints with a public access token first
|
||||
and only switch to a private access token if deviations are missing
|
||||
(i.e. they are only visible to logged in users).
|
||||
|
||||
This option only has an effect when using a `refresh token`__
|
||||
and tries to minimize the amount of API calls with private access
|
||||
tokens, as they have a much lower rate limit than public ones.
|
||||
|
||||
__ extractor.deviantart.refresh-token_
|
||||
=========== =====
|
||||
|
||||
|
||||
extractor.deviantart.refresh-token
|
||||
----------------------------------
|
||||
=========== =====
|
||||
@@ -346,27 +363,10 @@ Description The ``refresh_token`` value you get from linking your
|
||||
=========== =====
|
||||
|
||||
|
||||
extractor.deviantart.try-public
|
||||
-------------------------------
|
||||
=========== =====
|
||||
Type ``bool``
|
||||
Default ``false``
|
||||
Description Try accessing a user's deviations with a public access token first
|
||||
and only switch to a private access token if deviations are
|
||||
detected as missing (i.e. they are only visible to logged in users).
|
||||
|
||||
This option only has an effect when using a `refresh token`__
|
||||
and tries to minimize the amount of API calls with private access
|
||||
tokens, as they have a much lower rate limit than public ones.
|
||||
|
||||
__ extractor.deviantart.refresh-token_
|
||||
=========== =====
|
||||
|
||||
|
||||
extractor.deviantart.wait-min
|
||||
-----------------------------
|
||||
=========== =====
|
||||
Type ``int``
|
||||
Type ``integer``
|
||||
Default ``0``
|
||||
Description Minimum wait time in seconds before API requests.
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
"deviantart":
|
||||
{
|
||||
"refresh-token": null,
|
||||
"prefer-public": false,
|
||||
"flat": true,
|
||||
"journals": "html",
|
||||
"mature": true,
|
||||
|
||||
@@ -461,7 +461,7 @@ class DeviantartAPI():
|
||||
if not isinstance(self.mature, str):
|
||||
self.mature = "true" if self.mature else "false"
|
||||
|
||||
self.try_public = extractor.config("try-public", False)
|
||||
self.prefer_public = extractor.config("prefer-public", False)
|
||||
self.refresh_token = extractor.config("refresh-token")
|
||||
self.client_id = extractor.config("client-id", self.CLIENT_ID)
|
||||
self.client_secret = extractor.config(
|
||||
@@ -603,24 +603,25 @@ class DeviantartAPI():
|
||||
self.delay += 1
|
||||
self.log.warning("%s. Using %ds delay.", msg, 2 ** self.delay)
|
||||
|
||||
def _pagination(self, endpoint, params=None):
|
||||
public = self.try_public
|
||||
def _pagination(self, endpoint, params):
|
||||
public = self.prefer_public
|
||||
while True:
|
||||
data = self._call(endpoint, params, public=public)
|
||||
if "results" not in data:
|
||||
self.log.error("Unexpected API response: %s", data)
|
||||
return
|
||||
if (public and len(data["results"]) < params["limit"] and
|
||||
self.refresh_token and data["has_more"]):
|
||||
self.log.info("Switching to private access token")
|
||||
if (public and self.refresh_token and
|
||||
len(data["results"]) < params["limit"]):
|
||||
self.log.debug("Repeating API call with private access token")
|
||||
public = False
|
||||
continue
|
||||
yield from data["results"]
|
||||
if not data["has_more"]:
|
||||
return
|
||||
public = self.prefer_public
|
||||
params["offset"] = data["next_offset"]
|
||||
|
||||
def _pagination_list(self, endpoint, params=None):
|
||||
def _pagination_list(self, endpoint, params):
|
||||
result = []
|
||||
result.extend(self._pagination(endpoint, params))
|
||||
return result
|
||||
|
||||
@@ -150,7 +150,7 @@ class FlickrGalleryExtractor(FlickrExtractor):
|
||||
test = [(("https://www.flickr.com/photos/flickr/"
|
||||
"galleries/72157681572514792/"), {
|
||||
"url": "1e0e300fa5fe8c49ba5dfa7ccca0cb0da8a04f93",
|
||||
"keyword": "ba1f0e4bf5ee4e10071bdc272c19f015985cf055",
|
||||
"keyword": "7dd699ce77343921e8f149555ab2486a8ba1e9ec",
|
||||
})]
|
||||
|
||||
def __init__(self, match):
|
||||
|
||||
Reference in New Issue
Block a user