Skip to content

Commit

Permalink
merge #6389: [reddit] support user profile share links
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Oct 28, 2024
2 parents 10c076e + 604879d commit 2bbae0e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
14 changes: 6 additions & 8 deletions gallery_dl/extractor/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,16 @@ class RedditRedirectExtractor(Extractor):
category = "reddit"
subcategory = "redirect"
pattern = (r"(?:https?://)?(?:"
r"(?:\w+\.)?reddit\.com/(?:(?:r)/([^/?#]+)))"
r"(?:\w+\.)?reddit\.com/(?:(r|u|user)/([^/?#]+)))"
r"/s/([a-zA-Z0-9]{10})")
example = "https://www.reddit.com/r/SUBREDDIT/s/abc456GHIJ"

def __init__(self, match):
Extractor.__init__(self, match)
self.subreddit = match.group(1)
self.share_url = match.group(2)

def items(self):
url = "https://www.reddit.com/r/" + self.subreddit + "/s/" + \
self.share_url
sub_type, subreddit, share_url = self.groups
if sub_type == "u":
sub_type = "user"
url = "https://www.reddit.com/{}/{}/s/{}".format(
sub_type, subreddit, share_url)
data = {"_extractor": RedditSubmissionExtractor}
response = self.request(url, method="HEAD", allow_redirects=False,
notfound="submission")
Expand Down
16 changes: 16 additions & 0 deletions test/results/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,20 @@
"#pattern" : r"^https://www\.reddit\.com/r/analog/comments/179exao/photographing_the_recent_annular_eclipse_with_a",
},

{
"#url" : "https://www.reddit.com/u/Tailhook91/s/w4yAMbtOYm",
"#comment" : "Mobile share URL, user submission",
"#category": ("", "reddit", "redirect"),
"#class" : reddit.RedditRedirectExtractor,
"#pattern" : r"^https://www.reddit.com/user/Tailhook91/comments/znfxbr/prove_it/",
},

{
"#url" : "https://www.reddit.com/user/Tailhook91/s/w4yAMbtOYm",
"#comment" : "Mobile share URL, user submission",
"#category": ("", "reddit", "redirect"),
"#class" : reddit.RedditRedirectExtractor,
"#pattern" : r"^https://www.reddit.com/user/Tailhook91/comments/znfxbr/prove_it/",
},

)

0 comments on commit 2bbae0e

Please sign in to comment.