Skip to content

Commit

Permalink
[reddit] delay RedditAPI initialization (#1813)
Browse files Browse the repository at this point in the history
Move it outside the constructor so that eventual exceptions can get
caught in the expected places.
  • Loading branch information
mikf committed Aug 30, 2021
1 parent 5785462 commit 0a94fe5
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions gallery_dl/extractor/reddit.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,17 +21,14 @@ 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()
Expand Down Expand Up @@ -103,7 +100,7 @@ def items(self):
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 = (
Expand Down

0 comments on commit 0a94fe5

Please sign in to comment.