[reddit] delay RedditAPI initialization (#1813)

Move it outside the constructor so that eventual exceptions can get
caught in the expected places.
This commit is contained in:
Mike Fährmann
2021-08-30 22:39:40 +02:00
parent 57854624a1
commit 0a94fe5774

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- 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 # 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 # it under the terms of the GNU General Public License version 2 as
@@ -21,17 +21,14 @@ class RedditExtractor(Extractor):
archive_fmt = "{filename}" archive_fmt = "{filename}"
cookiedomain = None cookiedomain = None
def __init__(self, match):
Extractor.__init__(self, match)
self.api = RedditAPI(self)
self.max_depth = self.config("recursion", 0)
def items(self): def items(self):
self.api = RedditAPI(self)
match_submission = RedditSubmissionExtractor.pattern.match match_submission = RedditSubmissionExtractor.pattern.match
match_subreddit = RedditSubredditExtractor.pattern.match match_subreddit = RedditSubredditExtractor.pattern.match
match_user = RedditUserExtractor.pattern.match match_user = RedditUserExtractor.pattern.match
parentdir = self.config("parent-directory") parentdir = self.config("parent-directory")
max_depth = self.config("recursion", 0)
videos = self.config("videos", True) videos = self.config("videos", True)
submissions = self.submissions() submissions = self.submissions()
@@ -103,7 +100,7 @@ class RedditExtractor(Extractor):
elif not match_user(url) and not match_subreddit(url): elif not match_user(url) and not match_subreddit(url):
yield Message.Queue, text.unescape(url), data yield Message.Queue, text.unescape(url), data
if not extra or depth == self.max_depth: if not extra or depth == max_depth:
return return
depth += 1 depth += 1
submissions = ( submissions = (