diff options
Diffstat (limited to 'gallery_dl/extractor/reddit.py')
| -rw-r--r-- | gallery_dl/extractor/reddit.py | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/gallery_dl/extractor/reddit.py b/gallery_dl/extractor/reddit.py index 273ac05..8953edd 100644 --- a/gallery_dl/extractor/reddit.py +++ b/gallery_dl/extractor/reddit.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2017-2020 Mike Fährmann +# Copyright 2017-2021 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -21,25 +21,20 @@ class RedditExtractor(Extractor): archive_fmt = "{filename}" cookiedomain = None - def __init__(self, match): - Extractor.__init__(self, match) - self.api = RedditAPI(self) - self.max_depth = self.config("recursion", 0) - def items(self): + self.api = RedditAPI(self) match_submission = RedditSubmissionExtractor.pattern.match match_subreddit = RedditSubredditExtractor.pattern.match match_user = RedditUserExtractor.pattern.match parentdir = self.config("parent-directory") + max_depth = self.config("recursion", 0) videos = self.config("videos", True) submissions = self.submissions() visited = set() depth = 0 - yield Message.Version, 1 - while True: extra = [] @@ -105,7 +100,7 @@ class RedditExtractor(Extractor): elif not match_user(url) and not match_subreddit(url): yield Message.Queue, text.unescape(url), data - if not extra or depth == self.max_depth: + if not extra or depth == max_depth: return depth += 1 submissions = ( @@ -257,34 +252,35 @@ class RedditImageExtractor(Extractor): def items(self): data = text.nameext_from_url(self.url) - yield Message.Version, 1 yield Message.Directory, data yield Message.Url, self.url, data 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.") - - self.client_id = client_id - self.headers = {"User-Agent": user_agent} + 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")} - 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) |
