Skip to content

Commit

Permalink
[reddit] add 'home' extractor (#2614)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed May 26, 2022
1 parent b51f5fd commit d4e9d51
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/supportedsites.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ Consider all sites to be NSFW unless otherwise known.
<tr>
<td>Reddit</td>
<td>https://www.reddit.com/</td>
<td>individual Images, Submissions, Subreddits, User Profiles</td>
<td>Home Feed, individual Images, Submissions, Subreddits, User Profiles</td>
<td><a href="https://github.com/mikf/gallery-dl#oauth">OAuth</a></td>
</tr>
<tr>
Expand Down
20 changes: 17 additions & 3 deletions gallery_dl/extractor/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def _extract_gallery(self, submission):
class RedditSubredditExtractor(RedditExtractor):
"""Extractor for URLs from subreddits on reddit.com"""
subcategory = "subreddit"
pattern = (r"(?:https?://)?(?:\w+\.)?reddit\.com/r/"
r"([^/?#]+(?:/([a-z]+))?)/?(?:\?([^#]*))?(?:$|#)")
pattern = (r"(?:https?://)?(?:\w+\.)?reddit\.com"
r"(/r/[^/?#]+(?:/([a-z]+))?)/?(?:\?([^#]*))?(?:$|#)")
test = (
("https://www.reddit.com/r/lavaporn/", {
"range": "1-20",
Expand All @@ -168,6 +168,20 @@ def submissions(self):
return self.api.submissions_subreddit(self.subreddit, self.params)


class RedditHomeExtractor(RedditSubredditExtractor):
"""Extractor for submissions from your home feed on reddit.com"""
subcategory = "home"
pattern = (r"(?:https?://)?(?:\w+\.)?reddit\.com"
r"((?:/([a-z]+))?)/?(?:\?([^#]*))?(?:$|#)")
test = (
("https://www.reddit.com/", {
"range": "1-20",
"count": ">= 20",
}),
("https://old.reddit.com/top/?sort=top&t=month"),
)


class RedditUserExtractor(RedditExtractor):
"""Extractor for URLs from posts by a reddit user"""
subcategory = "user"
Expand Down Expand Up @@ -321,7 +335,7 @@ def submission(self, submission_id):

def submissions_subreddit(self, subreddit, params):
"""Collect all (submission, comments)-tuples of a subreddit"""
endpoint = "/r/" + subreddit + "/.json"
endpoint = subreddit + "/.json"
params["limit"] = 100
return self._pagination(endpoint, params)

Expand Down
3 changes: 3 additions & 0 deletions scripts/supportedsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@
"sketch": "Sketch",
"work": "individual Images",
},
"reddit": {
"home": "Home Feed",
},
"sankaku": {
"books": "Book Searches",
},
Expand Down

0 comments on commit d4e9d51

Please sign in to comment.