From 9c0928457add9899dfe9e5f327b91b411fc3492e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 20 Dec 2019 16:49:44 +0100 Subject: [PATCH] =?UTF-8?q?[reddit]=20fix=20errors=20with=20't1=5F?= =?UTF-8?q?=E2=80=A6'=20submissions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gallery_dl/extractor/reddit.py | 43 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/gallery_dl/extractor/reddit.py b/gallery_dl/extractor/reddit.py index ecce0032..a9c709ca 100644 --- a/gallery_dl/extractor/reddit.py +++ b/gallery_dl/extractor/reddit.py @@ -60,14 +60,16 @@ class RedditExtractor(Extractor): def _urls(self, submissions): for submission, comments in submissions: - self._visited.add(submission["id"]) - if not submission["is_self"]: - yield submission["url"], submission + if submission: + self._visited.add(submission["id"]) - for url in text.extract_iter( - submission["selftext_html"] or "", ' href="', '"'): - yield url, submission + if not submission["is_self"]: + yield submission["url"], submission + + for url in text.extract_iter( + submission["selftext_html"] or "", ' href="', '"'): + yield url, submission if comments: for comment in comments: @@ -298,17 +300,24 @@ class RedditAPI(): while True: data = self._call(endpoint, params)["data"] - for submission in data["children"]: - submission = submission["data"] - if (date_min <= submission["created_utc"] <= date_max and - id_min <= self._decode(submission["id"]) <= id_max): - if submission["num_comments"] and self.comments: - try: - yield self.submission(submission["id"]) - except exception.AuthorizationError: - pass - else: - yield submission, None + for child in data["children"]: + kind = child["kind"] + post = child["data"] + + if (date_min <= post["created_utc"] <= date_max and + id_min <= self._decode(post["id"]) <= id_max): + + if kind == "t3": + if post["num_comments"] and self.comments: + try: + yield self.submission(post["id"]) + except exception.AuthorizationError: + pass + else: + yield post, None + + elif kind == "t1" and self.comments: + yield None, (post,) if not data["after"]: return