evazion
2019-08-06 12:04:05 -05:00
parent a8896b664d
commit 7f482dc35b
3 changed files with 40 additions and 14 deletions

View File

@@ -19,6 +19,7 @@
# * http://pre06.deviantart.net/8497/th/pre/f/2009/173/c/c/cc9686111dcffffffb5fcfaf0cf069fb.jpg
#
# * https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg/v1/fill/w_786,h_1017,q_70,strp/silverhawks_quicksilver_by_edsfox_d23jbr4-pre.jpg
# * https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/fe7ab27f-7530-4252-99ef-2baaf81b36fd/dddf6pe-1a4a091c-768c-4395-9465-5d33899be1eb.png/v1/fill/w_800,h_1130,q_80,strp/stay_hydrated_and_in_the_shade_by_raikoart_dddf6pe-fullview.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7ImhlaWdodCI6Ijw9MTEzMCIsInBhdGgiOiJcL2ZcL2ZlN2FiMjdmLTc1MzAtNDI1Mi05OWVmLTJiYWFmODFiMzZmZFwvZGRkZjZwZS0xYTRhMDkxYy03NjhjLTQzOTUtOTQ2NS01ZDMzODk5YmUxZWIucG5nIiwid2lkdGgiOiI8PTgwMCJ9XV0sImF1ZCI6WyJ1cm46c2VydmljZTppbWFnZS5vcGVyYXRpb25zIl19.J0W4k-iV6Mg8Kt_5Lr_L_JbBq4lyr7aCausWWJ_Fsbw
#
# Page URLs:
#
@@ -113,6 +114,18 @@ module Sources
end
end
def page_url_from_image_url
artist, title, id = artist_name_from_url, title_from_url, deviation_id
if artist.present? && title.present? && id.present?
"https://www.deviantart.com/#{artist}/art/#{title}-#{id}"
elsif id.present?
"https://deviantart.com/deviation/#{id}"
else
nil
end
end
def profile_url
return "" if artist_name.blank?
"https://www.deviantart.com/#{artist_name.downcase}"
@@ -212,6 +225,16 @@ module Sources
end
end
def self.title_from_url(url)
if url =~ ASSET || url =~ PATH_ART || url =~ PATH_PROFILE
$~[:title].to_s.titleize.strip.squeeze(" ").tr(" ", "-").presence
elsif url !~ RESERVED_SUBDOMAINS && (url =~ SUBDOMAIN_ART || url =~ SUBDOMAIN_PROFILE)
$~[:title].to_s.titleize.strip.squeeze(" ").tr(" ", "-").presence
else
nil
end
end
def deviation_id
self.class.deviation_id_from_url(url) || self.class.deviation_id_from_url(referer_url)
end
@@ -220,6 +243,10 @@ module Sources
self.class.artist_name_from_url(url) || self.class.artist_name_from_url(referer_url)
end
def title_from_url
self.class.title_from_url(url) || self.class.title_from_url(referer_url)
end
def api_url
return nil if deviation_id.blank?
"https://www.deviantart.com/deviation/#{deviation_id}"

View File

@@ -363,20 +363,6 @@ class Post < ApplicationRecord
base_36_id = base_10_id.to_s(36)
"https://twitpic.com/#{base_36_id}"
# http://orig12.deviantart.net/9b69/f/2017/023/7/c/illustration___tokyo_encount_oei__by_melisaongmiqin-dawi58s.png
# http://pre15.deviantart.net/81de/th/pre/f/2015/063/5/f/inha_by_inhaestudios-d8kfzm5.jpg
# http://th00.deviantart.net/fs71/PRE/f/2014/065/3/b/goruto_by_xyelkiltrox-d797tit.png
# http://th04.deviantart.net/fs70/300W/f/2009/364/4/d/Alphes_Mimic___Rika_by_Juriesute.png
# http://fc02.deviantart.net/fs48/f/2009/186/2/c/Animation_by_epe_tohri.swf
# http://fc08.deviantart.net/files/f/2007/120/c/9/Cool_Like_Me_by_47ness.jpg
# http://fc08.deviantart.net/images3/i/2004/088/8/f/Blackrose_for_MuzicFreq.jpg
# http://img04.deviantart.net/720b/i/2003/37/9/6/princess_peach.jpg
when %r{\Ahttps?://(?:(?:fc|th|pre|orig|img|prnt)\d{2}|origin-orig)\.deviantart\.net/.+/(?<title>[a-z0-9_]+)_by_(?<artist>[a-z0-9_]+)-d(?<id>[a-z0-9]+)\.}i
artist = $~[:artist].dasherize
title = $~[:title].titleize.strip.squeeze(" ").tr(" ", "-")
id = $~[:id].to_i(36)
"https://www.deviantart.com/#{artist}/art/#{title}-#{id}"
# http://prnt00.deviantart.net/9b74/b/2016/101/4/468a9d89f52a835d4f6f1c8caca0dfb2-pnjfbh.jpg
# http://fc00.deviantart.net/fs71/f/2013/234/d/8/d84e05f26f0695b1153e9dab3a962f16-d6j8jl9.jpg
# http://th04.deviantart.net/fs71/PRE/f/2013/337/3/5/35081351f62b432f84eaeddeb4693caf-d6wlrqs.jpg
@@ -385,6 +371,9 @@ class Post < ApplicationRecord
id = $~[:id].to_i(36)
"https://deviantart.com/deviation/#{id}"
when Sources::Strategies::DeviantArt::ASSET
Sources::Strategies::DeviantArt.new(source).page_url_from_image_url || source
when %r{\Ahttp://www\.karabako\.net/images(?:ub)?/karabako_(\d+)(?:_\d+)?\.}i
"http://www.karabako.net/post/view/#{$1}"

View File

@@ -17,6 +17,7 @@ module Sources
assert_equal(@site.image_url, @site.canonical_url)
assert_equal("aeror404", @site.artist_name)
assert_equal("https://www.deviantart.com/aeror404", @site.profile_url)
assert_equal("https://www.deviantart.com/aeror404/art/Holiday-Elincia-424551484", @site.page_url_from_image_url)
end
end
@@ -29,6 +30,7 @@ module Sources
assert_equal(@site.image_url, @site.canonical_url)
assert_equal("nickbeja", @site.artist_name)
assert_equal("https://www.deviantart.com/nickbeja", @site.profile_url)
assert_equal("https://www.deviantart.com/nickbeja/art/Mindflayer-Girl01-708675884", @site.page_url_from_image_url)
assert_equal([@artist], @site.artists)
assert_nothing_raised { @site.to_h }
end
@@ -40,6 +42,7 @@ module Sources
assert_match(%r!^https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dbj81lr-3306feb1-87dc-4d25-9a4c-da8d2973a8b7.jpg!, @site.image_urls[0])
assert_equal("https://www.deviantart.com/noizave/art/test-no-download-697415967", @site.canonical_url)
assert_equal("https://www.deviantart.com/noizave/art/Test-No-Download-697415967", @site.page_url_from_image_url)
end
end
@@ -59,6 +62,7 @@ module Sources
assert_equal("hideyoshi", @site.artist_name)
assert_equal("https://www.deviantart.com/hideyoshi", @site.profile_url)
assert_equal("http://origin-orig.deviantart.net/9e1f/f/2016/265/3/5/legend_of_galactic_heroes_by_hideyoshi-daihpha.jpg", @site.image_url)
assert_equal("https://www.deviantart.com/hideyoshi/art/Legend-Of-Galactic-Heroes-635721022", @site.page_url_from_image_url)
assert_equal(@site.image_url, @site.canonical_url)
end
end
@@ -69,6 +73,7 @@ module Sources
assert_equal(@site.url, @site.image_url)
assert_equal("https://www.deviantart.com/noizave/art/test-post-please-ignore-685436408", @site.page_url)
assert_equal("https://www.deviantart.com/noizave/art/Test-Post-Please-Ignore-685436408", @site.page_url_from_image_url)
assert_equal(@site.image_url, @site.canonical_url)
assert_equal("noizave", @site.artist_name)
assert_equal("https://www.deviantart.com/noizave", @site.profile_url)
@@ -81,6 +86,7 @@ module Sources
should "return the full size image url" do
@site = Sources::Strategies.find("https://img00.deviantart.net/a233/i/2017/160/5/1/test_post_please_ignore_by_noizave-dbc3a48.png")
assert_equal("http://origin-orig.deviantart.net/7b5b/f/2017/160/c/5/test_post_please_ignore_by_noizave-dbc3a48.png", @site.image_url)
assert_equal("https://www.deviantart.com/noizave/art/Test-Post-Please-Ignore-685436408", @site.page_url_from_image_url)
end
end
@@ -88,6 +94,7 @@ module Sources
should "return the full size image url" do
@site = Sources::Strategies.find("http://th00.deviantart.net/fs71/PRE/f/2014/065/3/b/goruto_by_xyelkiltrox-d797tit.png")
assert_equal("http://origin-orig.deviantart.net/0f1e/f/2014/065/3/b/goruto_by_xyelkiltrox-d797tit.png", @site.image_url)
assert_equal("https://www.deviantart.com/xyelkiltrox/art/Goruto-438744629", @site.page_url_from_image_url)
end
end
@@ -98,6 +105,7 @@ module Sources
assert_equal("mikoto-chan", @site.artist_name)
assert_equal([@artist], @site.artists)
assert_nil(@site.page_url_from_image_url)
end
end
@@ -116,6 +124,7 @@ module Sources
assert_equal("47ness", @site.artist_name)
assert_equal("https://www.deviantart.com/47ness", @site.profile_url)
assert_equal("", @site.page_url)
assert_nil(@site.page_url_from_image_url)
assert_equal(@site.image_url, @site.canonical_url)
assert_equal([@artist], @site.artists)
assert_nothing_raised { @site.to_h }
@@ -152,6 +161,7 @@ module Sources
assert_equal("", @site.artist_name)
assert_equal("", @site.profile_url)
assert_equal("", @site.page_url)
assert_nil(@site.page_url_from_image_url)
assert_equal(@site.image_url, @site.canonical_url)
assert_equal([], @site.artists)
assert_nothing_raised { @site.to_h }