From 212130b0484e8d5fde0df5d3e64ad94983e875ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 25 Jul 2018 12:52:36 +0200 Subject: [PATCH] [deviantart] improve public-private token switching - rename option to `prefer-public` - now also works for galleries with less than 24 items --- docs/configuration.rst | 36 +++++++++++++++--------------- docs/gallery-dl.conf | 1 + gallery_dl/extractor/deviantart.py | 15 +++++++------ gallery_dl/extractor/flickr.py | 2 +- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 90866f09..95241bc7 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -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. diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 2cf2868c..2ff80222 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -17,6 +17,7 @@ "deviantart": { "refresh-token": null, + "prefer-public": false, "flat": true, "journals": "html", "mature": true, diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index 65c6d55c..33f66b89 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -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 diff --git a/gallery_dl/extractor/flickr.py b/gallery_dl/extractor/flickr.py index cea46b1d..f5ce0d98 100644 --- a/gallery_dl/extractor/flickr.py +++ b/gallery_dl/extractor/flickr.py @@ -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):