From 8cd7759682fecca04b12550bacd9ce0d9e594552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Mon, 30 Aug 2021 23:29:02 +0200 Subject: [PATCH] [reddit] cleanup ReddeitAPI.__init__ (#1813) - remove warning about 'client-id'/'user-agent' mismatch - only use 'user-agent' from config for custom 'client-id' --- gallery_dl/extractor/reddit.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/gallery_dl/extractor/reddit.py b/gallery_dl/extractor/reddit.py index dcb182ae..8953eddc 100644 --- a/gallery_dl/extractor/reddit.py +++ b/gallery_dl/extractor/reddit.py @@ -257,28 +257,30 @@ class RedditImageExtractor(Extractor): class RedditAPI(): - """Minimal interface for the reddit API""" + """Interface for the Reddit API + + Ref: https://www.reddit.com/dev/api/ + """ CLIENT_ID = "6N9uN0krSDE-ig" USER_AGENT = "Python:gallery-dl:0.8.4 (by /u/mikf1)" def __init__(self, extractor): self.extractor = extractor - self.comments = text.parse_int(extractor.config("comments", 0)) - self.morecomments = extractor.config("morecomments", False) self.log = extractor.log - client_id = extractor.config("client-id", self.CLIENT_ID) - user_agent = extractor.config("user-agent", self.USER_AGENT) + config = extractor.config + self.comments = text.parse_int(config("comments", 0)) + self.morecomments = config("morecomments", False) - if (client_id == self.CLIENT_ID) ^ (user_agent == self.USER_AGENT): - raise exception.StopExtraction( - "Conflicting values for 'client-id' and 'user-agent': " - "overwrite either both or none of them.") + client_id = config("client-id") + if client_id is None: + self.client_id = self.CLIENT_ID + self.headers = {"User-Agent": self.USER_AGENT} + else: + self.client_id = client_id + self.headers = {"User-Agent": config("user-agent")} - self.client_id = client_id - self.headers = {"User-Agent": user_agent} - - token = extractor.config("refresh-token") + token = config("refresh-token") if token is None or token == "cache": key = "#" + self.client_id self.refresh_token = _refresh_token_cache(key)