Skip to content

Commit

Permalink
Merge pull request #24 from LilSpazJoekp/gallery_url
Browse files Browse the repository at this point in the history
Add support for gallery urls
  • Loading branch information
LilSpazJoekp committed Dec 15, 2020
2 parents b4179e2 + dbc6468 commit e0884d1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Unreleased
**Added**

* Ability to submit image galleries with :meth:`.submit_gallery`.
* Ability to pass a gallery url to :meth:`.Reddit.submission`.
* Ability to specify modmail mute duration.

**Changed**
Expand Down
5 changes: 4 additions & 1 deletion asyncpraw/models/reddit/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,17 +423,20 @@ def id_from_url(url: str) -> str:
* https://redd.it/2gmzqe
* https://reddit.com/comments/2gmzqe/
* https://www.reddit.com/r/redditdev/comments/2gmzqe/praw_https/
* https://www.reddit.com/gallery/2gmzqe
:raises: :class:`.InvalidURL` if URL is not a valid submission URL.
"""
parts = RedditBase._url_parts(url)
if "comments" not in parts:
if "comments" not in parts and "gallery" not in parts:
submission_id = parts[-1]
if "r" in parts:
raise InvalidURL(
url, message="Invalid URL (subreddit, not submission): {}"
)
elif "gallery" in parts:
submission_id = parts[parts.index("gallery") + 1]
else:
submission_id = parts[parts.index("comments") + 1]

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/models/reddit/test_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def test_id_from_url(self):
"https://redd.it/2gmzqe",
"https://redd.it/2gmzqe/",
"http://reddit.com/comments/2gmzqe",
"https://www.reddit.com/r/redditdev/comments/2gmzqe/"
"praw_https_enabled_praw_testing_needed/",
"https://www.reddit.com/r/redditdev/comments/2gmzqe/praw_https_enabled_praw_testing_needed/",
"https://www.reddit.com/gallery/2gmzqe",
]
for url in urls:
assert Submission.id_from_url(url) == "2gmzqe", url
Expand Down

0 comments on commit e0884d1

Please sign in to comment.