Reddit: support user galleries and embedded images
This commit is contained in:
@@ -12,7 +12,7 @@ module Source
|
||||
if parsed_url&.full_image_url.present?
|
||||
[parsed_url.full_image_url]
|
||||
elsif data.present?
|
||||
images = [data.dig("media", "resolutions", 0, "url")].compact
|
||||
images = [data.dig("media", "content")].compact
|
||||
images += ordered_gallery_images
|
||||
images.compact.uniq.map { |i| Source::URL.parse(i)&.full_image_url }.compact
|
||||
else
|
||||
@@ -30,7 +30,7 @@ module Source
|
||||
|
||||
def profile_url
|
||||
return nil if artist_name.blank?
|
||||
"https://reddit.com/user/#{artist_name}"
|
||||
"https://www.reddit.com/user/#{artist_name}"
|
||||
end
|
||||
|
||||
def page_url
|
||||
|
||||
@@ -18,11 +18,18 @@ module Source
|
||||
@file = file
|
||||
|
||||
# https://external-preview.redd.it/92G2gkb545UNlA-PywJqM_F-4TT0xngvmf_gb9sFDqk.jpg?auto=webp&s=0f1e3d0603dbaabe1ead7352202d0de1653d76f6
|
||||
# https://external-preview.redd.it/VlT1G4JoqAmP_7DG5UKRCJP8eTRef7dCrRvu2ABm_Xg.png?width=1080&crop=smart&auto=webp&s=d074e9cbfcb2780e6ec0d948daff3cadc91c2a50
|
||||
# https://g.redditmedia.com/f-OWw5C5aVumPS4HXVFhTspgzgQB4S77mO-6ad0rzpg.gif?fm=mp4&mp4-fragmented=false&s=ed3d767bf3b0360a50ddd7f503d46225
|
||||
# https://i.redditmedia.com/9cYFBDQ3QsqWnF9v7EhW5uOcQNHz1Ak9_E1zVNeSLek.png?s=6fee1bb56e7d926847dc3ece01a1ffd4
|
||||
in *rest if image_url?
|
||||
# pass
|
||||
|
||||
# https://www.reddit.com/user/blank_page_drawings/comments/nfjz0d/a_sleepy_orc/
|
||||
in _, "reddit.com", ("user" | "u"), username, "comments", work_id, title
|
||||
@username = username
|
||||
@work_id = work_id
|
||||
@title = title
|
||||
|
||||
# https://www.reddit.com/user/xSlimes
|
||||
# https://www.reddit.com/u/Valshier
|
||||
in _, "reddit.com", ("user" | "u"), username
|
||||
@@ -66,6 +73,8 @@ module Source
|
||||
def page_url
|
||||
if subreddit.present? && work_id.present? && title.present?
|
||||
"https://www.reddit.com/r/#{subreddit}/comments/#{work_id}/#{title}"
|
||||
elsif username.present? && work_id.present? && title.present?
|
||||
"https://www.reddit.com/user/#{username}/comments/#{work_id}/#{title}"
|
||||
elsif subreddit.present? && work_id.present?
|
||||
"https://www.reddit.com/r/#{subreddit}/comments/#{work_id}"
|
||||
elsif work_id.present?
|
||||
|
||||
@@ -12,18 +12,35 @@ module Sources
|
||||
"https://i.redd.it/oc5y8k06ryq81.png",
|
||||
],
|
||||
artist_name: "Darksin31",
|
||||
profile_url: "https://reddit.com/user/Darksin31",
|
||||
profile_url: "https://www.reddit.com/user/Darksin31",
|
||||
page_url: "https://www.reddit.com/r/arknights/comments/ttyccp/maria_nearl_versus_the_leftarmed_knight_dankestsin/",
|
||||
artist_commentary_title: "Maria Nearl Versus the Left-Armed Knight (@dankestsin)"
|
||||
)
|
||||
end
|
||||
|
||||
context "A reddit post with username instead of subreddit" do
|
||||
strategy_should_work(
|
||||
"https://www.reddit.com/user/blank_page_drawings/comments/nfjz0d/a_sleepy_orc/",
|
||||
image_urls: ["https://i.redd.it/ruh00hxilxz61.png"],
|
||||
page_url: "https://www.reddit.com/user/blank_page_drawings/comments/nfjz0d/a_sleepy_orc/",
|
||||
artist_commentary_title: "A sleepy orc",
|
||||
profile_url: "https://www.reddit.com/user/blank_page_drawings"
|
||||
)
|
||||
end
|
||||
|
||||
context "A reddit post with an external image" do
|
||||
strategy_should_work(
|
||||
"https://www.reddit.com/r/baramanga/comments/n9cgs3/you_can_now_find_me_on_twitter_too_blankpage/",
|
||||
image_urls: ["https://external-preview.redd.it/VlT1G4JoqAmP_7DG5UKRCJP8eTRef7dCrRvu2ABm_Xg.png?auto=webp&s=6510f9f0a69563988aed7af04f750f92fc35f629"]
|
||||
)
|
||||
end
|
||||
|
||||
context "A crosspost" do
|
||||
strategy_should_work(
|
||||
"https://www.reddit.com/gallery/yc0b8g",
|
||||
image_urls: ["https://i.redd.it/eao0je8wzlv91.jpg"],
|
||||
page_url: "https://www.reddit.com/r/furrymemes/comments/ybr04z/_/",
|
||||
profile_url: "https://reddit.com/user/lightmare69",
|
||||
profile_url: "https://www.reddit.com/user/lightmare69",
|
||||
artist_name: "lightmare69",
|
||||
artist_commentary_title: "\u{1FAF5}😐"
|
||||
)
|
||||
@@ -33,7 +50,7 @@ module Sources
|
||||
strategy_should_work(
|
||||
"https://www.reddit.com/r/Genshin_Impact/comments/u9zilq/cookie_shinobu",
|
||||
image_urls: ["https://i.redd.it/bxh5xkp088v81.jpg"],
|
||||
profile_url: "https://reddit.com/user/onethingidkwhy",
|
||||
profile_url: "https://www.reddit.com/user/onethingidkwhy",
|
||||
artist_name: "onethingidkwhy",
|
||||
artist_commentary_title: "cookie shinobu"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user