From cc0c2cca570796b2ebe5c9aaff7cf8b276089064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 14 Jan 2018 18:55:42 +0100 Subject: [PATCH] [reddit] add extractor for reddit-hosted images (closes #68) --- docs/supportedsites.rst | 2 +- gallery_dl/extractor/common.py | 2 +- gallery_dl/extractor/reddit.py | 32 +++++++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/docs/supportedsites.rst b/docs/supportedsites.rst index 889b7eae..89b8cd13 100644 --- a/docs/supportedsites.rst +++ b/docs/supportedsites.rst @@ -61,7 +61,7 @@ PowerManga https://powermanga.org/ Chapters, Manga Pure Mashiro http://reader.puremashiro.moe/ Chapters, Manga Read Comic Online http://readcomiconline.to/ Comic-Issues, Comics RebeccaBlackTech https://rbt.asia/ Threads -Reddit https://reddit.com/ Submissions, Subreddits Optional (OAuth) +Reddit https://reddit.com/ individual Images, Submissions, Subreddits Optional (OAuth) Rule 34 https://rule34.xxx/ Posts, Tag-Searches Safebooru https://safebooru.org/ Posts, Tag-Searches Sankaku Channel https://chan.sankakucomplex.com/ Pools, Posts, Tag-Searches Optional diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 8d00be97..36037387 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -27,7 +27,7 @@ class Extractor(): subcategory = "" categorytransfer = False directory_fmt = ["{category}"] - filename_fmt = "{filename}" + filename_fmt = "{name}.{extension}" cookiedomain = "" def __init__(self): diff --git a/gallery_dl/extractor/reddit.py b/gallery_dl/extractor/reddit.py index bc553c41..89a7e834 100644 --- a/gallery_dl/extractor/reddit.py +++ b/gallery_dl/extractor/reddit.py @@ -32,7 +32,8 @@ class RedditExtractor(Extractor): depth = 0 yield Message.Version, 1 - with extractor.blacklist(("reddit",) + util.SPECIAL_EXTRACTORS): + with extractor.blacklist( + util.SPECIAL_EXTRACTORS, [RedditSubredditExtractor]): while True: extra = [] for url in self._urls(submissions): @@ -101,6 +102,35 @@ class RedditSubmissionExtractor(RedditExtractor): return (self.api.submission(self.submission_id),) +class RedditImageExtractor(Extractor): + """Extractor for reddit-hosted images""" + category = "reddit" + subcategory = "image" + pattern = [r"(?:https?://)?i\.redd(?:\.it|ituploads\.com)" + r"/[^/?&#]+(?:\?[^#]*)?"] + test = [ + ("https://i.redd.it/upjtjcx2npzz.jpg", { + "url": "0de614900feef103e580b632190458c0b62b641a", + "content": "cc9a68cf286708d5ce23c68e79cd9cf7826db6a3", + }), + (("https://i.reddituploads.com/0f44f1b1fca2461f957c713d9592617d" + "?fit=max&h=1536&w=1536&s=e96ce7846b3c8e1f921d2ce2671fb5e2"), { + "url": "f24f25efcedaddeec802e46c60d77ef975dc52a5", + "content": "d13c3b5f7e39b454fa21b33d7d6b0e0f07126849", + }), + ] + + def __init__(self, match): + Extractor.__init__(self) + self.url = match.group(0) + + 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""" CLIENT_ID = "6N9uN0krSDE-ig"