Fix #4144: Deviantart Eclipse update broke strategy.

This commit is contained in:
evazion
2019-08-28 23:40:29 -05:00
parent eb94bf366b
commit eba6440b8b
10 changed files with 131 additions and 342 deletions

View File

@@ -230,7 +230,6 @@ class ArtistTest < ActiveSupport::TestCase
context "when finding deviantart artists" do
setup do
skip "DeviantArt API keys not set" unless Danbooru.config.deviantart_client_id.present?
FactoryBot.create(:artist, :name => "artgerm", :url_string => "http://artgerm.deviantart.com/")
FactoryBot.create(:artist, :name => "trixia", :url_string => "http://trixdraws.deviantart.com/")
end

View File

@@ -1,19 +0,0 @@
require 'test_helper'
module Downloads
class DeviantArtTest < ActiveSupport::TestCase
context "a download for a deviant art html page" do
setup do
skip "DeviantArt API keys not set" unless Danbooru.config.deviantart_client_id.present?
@source = "https://www.deviantart.com/aeror404/art/Holiday-Elincia-424551484"
@download = Downloads::File.new(@source)
@tempfile, strategy = @download.download!
end
should "work" do
assert_equal(877987, ::File.size(@tempfile.path))
end
end
end
end

View File

@@ -2,29 +2,29 @@ require 'test_helper'
module Sources
class DeviantArtTest < ActiveSupport::TestCase
def setup
super
skip "DeviantArt API keys not set" unless Danbooru.config.deviantart_client_id.present?
end
context "A path-based artist url" do
context "A page url" do
setup do
@site = Sources::Strategies.find("https://www.deviantart.com/aeror404/art/Holiday-Elincia-424551484")
end
should "work" do
assert_equal(["http://origin-orig.deviantart.net/d533/f/2014/004/8/d/holiday_elincia_by_aeror404-d70rm0s.jpg"], @site.image_urls)
assert_equal(@site.image_url, @site.canonical_url)
# http://origin-orig.deviantart.net/d533/f/2014/004/8/d/holiday_elincia_by_aeror404-d70rm0s.jpg (md5: a7651a6586b95c62fd593dd34bb13618, size: 877987)
assert_match(%r!\Ahttps://api-da.wixmp.com/_api/download/file\?downloadToken=!, @site.image_url)
assert_downloaded(877_987, @site.image_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)
assert_equal("https://www.deviantart.com/aeror404/art/Holiday-Elincia-424551484", @site.page_url_from_image_url)
assert_equal("https://www.deviantart.com/aeror404/art/Holiday-Elincia-424551484", @site.canonical_url)
assert_equal("Holiday Elincia", @site.artist_commentary_title)
end
end
context "The source for a deleted DeviantArt image URL" do
should "work" do
@site = Sources::Strategies.find("https://pre00.deviantart.net/423b/th/pre/i/2017/281/e/0/mindflayer_girl01_by_nickbeja-dbpxdt8.png")
@artist = FactoryBot.create(:artist, name: "nickbeja", url_string: "https://nickbeja.deviantart.com")
@artist = create(:artist, name: "nickbeja", url_string: "https://nickbeja.deviantart.com")
assert_equal("https://pre00.deviantart.net/423b/th/pre/i/2017/281/e/0/mindflayer_girl01_by_nickbeja-dbpxdt8.png", @site.image_url)
assert_equal(@site.image_url, @site.canonical_url)
@@ -40,9 +40,17 @@ module Sources
should "get the image url" do
@site = Sources::Strategies.find("https://noizave.deviantart.com/art/test-no-download-697415967")
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)
# https://img00.deviantart.net/56ee/i/2017/219/2/3/test__no_download_by_noizave-dbj81lr.jpg (md5: 25a03b5a6744b6b914a13b3cd50e3c2c, size: 37638)
# orig file: https://danbooru.donmai.us/posts/463438 (md5: eb97244675e47dbd77ffcd2d7e15aeab, size: 59401)
assert_match("https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dbj81lr-3306feb1-87dc-4d25-9a4c-da8d2973a8b7.jpg", @site.image_url)
assert_downloaded(40_036, @site.image_url)
assert_equal("noizave", @site.artist_name)
assert_equal("https://www.deviantart.com/noizave", @site.profile_url)
assert_equal("test, no download", @site.artist_commentary_title)
assert_equal("https://www.deviantart.com/noizave/art/test-no-download-697415967", @site.page_url)
assert_equal("https://www.deviantart.com/noizave/art/Test-No-Download-697415967", @site.page_url_from_image_url)
assert_equal("https://www.deviantart.com/noizave/art/test-no-download-697415967", @site.canonical_url)
end
end
@@ -50,8 +58,15 @@ module Sources
should "get the download image url" do
@site = Sources::Strategies.find("https://www.deviantart.com/len1/art/All-that-Glitters-II-774592781")
assert_equal(["http://origin-orig.deviantart.net/a713/f/2018/333/3/6/all_that_glitters_ii_by_len1-dct67m5.jpg"], @site.image_urls)
assert_equal(@site.image_url, @site.canonical_url)
# http://origin-orig.deviantart.net/a713/f/2018/333/3/6/all_that_glitters_ii_by_len1-dct67m5.jpg (md5: d16bb8620600334caa029ebb9bc426a6, size: 1402017)
assert_match(%r!\Ahttps://api-da.wixmp.com/_api/download/file\?downloadToken=!, @site.image_url)
assert_downloaded(1402017, @site.image_url)
assert_equal("len1", @site.artist_name)
assert_equal("https://www.deviantart.com/len1", @site.profile_url)
assert_equal("All that Glitters II", @site.artist_commentary_title)
assert_equal("https://www.deviantart.com/len1/art/All-that-Glitters-II-774592781", @site.page_url)
assert_equal("https://www.deviantart.com/len1/art/All-that-Glitters-II-774592781", @site.canonical_url)
end
end
@@ -59,11 +74,16 @@ module Sources
should "fetch the source data" do
@site = Sources::Strategies.find("https://pre00.deviantart.net/b5e6/th/pre/f/2016/265/3/5/legend_of_galactic_heroes_by_hideyoshi-daihpha.jpg")
# http://origin-orig.deviantart.net/9e1f/f/2016/265/3/5/legend_of_galactic_heroes_by_hideyoshi-daihpha.jpg (md5: 4cfec3d50ebbb924077cc5c90e705d4e, size: 906621)
assert_match(%r!\Ahttps://api-da.wixmp.com/_api/download/file\?downloadToken=!, @site.image_url)
assert_downloaded(906_621, @site.image_url)
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)
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)
assert_equal("https://www.deviantart.com/hideyoshi/art/Legend-of-Galactic-Heroes-635721022", @site.canonical_url)
assert_equal(%w[barbarossa bay brunhild flare hangar odin planet ship spaceship sun sunset brünhild legendsofgalacticheroes].sort, @site.tags.map(&:first).sort)
end
end
@@ -71,10 +91,14 @@ module Sources
should "work" do
@site = Sources::Strategies.find("http://origin-orig.deviantart.net/7b5b/f/2017/160/c/5/test_post_please_ignore_by_noizave-dbc3a48.png")
assert_equal(@site.url, @site.image_url)
# md5: 9dec050536dbdb09ab63cb9c5a48f8b7
assert_match(%r!\Ahttps://api-da.wixmp.com/_api/download/file\?downloadToken=!, @site.image_url)
assert_downloaded(3619, @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("https://www.deviantart.com/noizave/art/test-post-please-ignore-685436408", @site.canonical_url)
assert_equal("noizave", @site.artist_name)
assert_equal("https://www.deviantart.com/noizave", @site.profile_url)
assert_equal(%w[bar baz foo], @site.tags.map(&:first))
@@ -85,7 +109,10 @@ module Sources
context "The source for a img00.deviantart.net sample image url" do
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_match(%r!\Ahttps://api-da.wixmp.com/_api/download/file\?downloadToken=!, @site.image_url)
assert_downloaded(3619, @site.image_url)
assert_equal("https://www.deviantart.com/noizave/art/Test-Post-Please-Ignore-685436408", @site.page_url_from_image_url)
end
end
@@ -93,7 +120,11 @@ module Sources
context "The source for a th00.deviantart.net/*/PRE/* thumbnail url" do
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)
# http://origin-orig.deviantart.net/0f1e/f/2014/065/3/b/goruto_by_xyelkiltrox-d797tit.png (md5: d779f5a7da29ec90d777a8db38d07994, size: 3391584)
assert_match(%r!\Ahttps://api-da.wixmp.com/_api/download/file\?downloadToken=!, @site.image_url)
assert_downloaded(3_391_584, @site.image_url)
assert_equal("https://www.deviantart.com/xyelkiltrox/art/Goruto-438744629", @site.page_url_from_image_url)
end
end
@@ -101,7 +132,7 @@ module Sources
context "A source for a *.deviantart.net/*/:title_by_:artist.jpg url artist name containing underscores" do
should "find the correct artist" do
@site = Sources::Strategies.find("https://orig00.deviantart.net/4274/f/2010/230/8/a/pkmn_king_and_queen_by_mikoto_chan.jpg")
@artist = FactoryBot.create(:artist, name: "mikoto-chan", url_string: "https://www.deviantart.com/mikoto-chan")
@artist = create(:artist, name: "mikoto-chan", url_string: "https://www.deviantart.com/mikoto-chan")
assert_equal("mikoto-chan", @site.artist_name)
assert_equal([@artist], @site.artists)
@@ -113,7 +144,7 @@ module Sources
setup do
@url = "http://fc08.deviantart.net/files/f/2007/120/c/9/cool_like_me_by_47ness.jpg"
@ref = "https://47ness.deviantart.com/art/Cool-Like-Me-54339311"
@artist = FactoryBot.create(:artist, name: "47ness", url_string: "https://www.deviantart.com/47ness")
@artist = create(:artist, name: "47ness", url_string: "https://www.deviantart.com/47ness")
end
context "without a referer" do
@@ -123,7 +154,7 @@ module Sources
assert_equal(@site.url, @site.image_url)
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)
assert_nil(@site.page_url_from_image_url)
assert_equal(@site.image_url, @site.canonical_url)
assert_equal([@artist], @site.artists)
@@ -135,7 +166,10 @@ module Sources
should "work" do
@site = Sources::Strategies.find(@url, @ref)
assert_equal("http://origin-orig.deviantart.net/a418/f/2007/120/c/9/cool_like_me_by_47ness.jpg", @site.image_url)
# http://origin-orig.deviantart.net/a418/f/2007/120/c/9/cool_like_me_by_47ness.jpg (md5: da78e7c192d42470acda7d87ade64849, size: 265496)
assert_match(%r!\Ahttps://api-da.wixmp.com/_api/download/file\?downloadToken=!, @site.image_url)
assert_downloaded(265_496, @site.image_url)
assert_equal("47ness", @site.artist_name)
assert_equal("https://www.deviantart.com/47ness", @site.profile_url)
assert_equal("https://www.deviantart.com/47ness/art/Cool-Like-Me-54339311", @site.page_url)
@@ -150,7 +184,7 @@ module Sources
setup do
@url = "http://pre06.deviantart.net/8497/th/pre/f/2009/173/c/c/cc9686111dcffffffb5fcfaf0cf069fb.jpg"
@ref = "https://www.deviantart.com/edsfox/art/Silverhawks-Quicksilver-126872896"
@artist = FactoryBot.create(:artist, name: "edsfox", url_string: "https://edsfox.deviantart.com")
@artist = create(:artist, name: "edsfox", url_string: "https://edsfox.deviantart.com")
end
context "without a referer" do
@@ -158,9 +192,9 @@ module Sources
@site = Sources::Strategies.find(@url)
assert_equal(@url, @site.image_url)
assert_equal("", @site.artist_name)
assert_equal("", @site.profile_url)
assert_equal("", @site.page_url)
assert_nil(@site.artist_name)
assert_nil(@site.profile_url)
assert_nil(@site.page_url)
assert_nil(@site.page_url_from_image_url)
assert_equal(@site.image_url, @site.canonical_url)
assert_equal([], @site.artists)
@@ -172,7 +206,7 @@ module Sources
should "work" do
@site = Sources::Strategies.find(@url, @ref)
assert_match(%r!^https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg!, @site.image_url)
assert_match(%r!\Ahttps://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg!, @site.image_url)
assert_equal("edsfox", @site.artist_name)
assert_equal("https://www.deviantart.com/edsfox", @site.profile_url)
assert_equal("https://www.deviantart.com/edsfox/art/Silverhawks-Quicksilver-126872896", @site.page_url)
@@ -187,14 +221,14 @@ module Sources
setup do
@url = "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"
@ref = "https://www.deviantart.com/edsfox/art/Silverhawks-Quicksilver-126872896"
@artist = FactoryBot.create(:artist, name: "edsfox", url_string: "https://edsfox.deviantart.com")
@artist = create(:artist, name: "edsfox", url_string: "https://edsfox.deviantart.com")
end
context "with a referer" do
should "work" do
@site = Sources::Strategies.find(@url, @ref)
assert_match(%r!^https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg!, @site.image_url)
assert_match(%r!\Ahttps://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/intermediary/f/8b472d70-a0d6-41b5-9a66-c35687090acc/d23jbr4-8a06af02-70cb-46da-8a96-42a6ba73cdb4.jpg!, @site.image_url)
assert_equal("edsfox", @site.artist_name)
assert_equal("https://www.deviantart.com/edsfox", @site.profile_url)
assert_equal("https://www.deviantart.com/edsfox/art/Silverhawks-Quicksilver-126872896", @site.page_url)
@@ -211,7 +245,9 @@ module Sources
end
should "get the image url" do
assert_match(%r!https?://origin-orig.deviantart.net/7b5b/f/2017/160/c/5/test_post_please_ignore_by_noizave-dbc3a48.png!, @site.image_url)
# https://origin-orig.deviantart.net/7b5b/f/2017/160/c/5/test_post_please_ignore_by_noizave-dbc3a48.png
assert_match(%r!\Ahttps://api-da.wixmp.com/_api/download/file\?downloadToken=!, @site.image_url)
assert_downloaded(3619, @site.image_url)
end
should "get the profile" do
@@ -269,7 +305,9 @@ module Sources
end
should "get the image url" do
assert_match(%r!https?://origin-orig\.deviantart\.net/cb25/f/2017/160/1/9/hidden_work_by_noizave-dbc3r29\.png!, @site.image_url)
# https://origin-orig.deviantart.net/cb25/f/2017/160/1/9/hidden_work_by_noizave-dbc3r29.png
assert_match(%r!\Ahttps://api-da.wixmp.com/_api/download/file\?downloadToken=!, @site.image_url)
assert_downloaded(3619, @site.image_url)
end
end
@@ -284,7 +322,7 @@ module Sources
context "An artist entry with a profile url that is missing the 'www'" do
should "still find the artist" do
@site = Sources::Strategies.find("http://noizave.deviantart.com/art/test-post-please-ignore-685436408")
@artist = FactoryBot.create(:artist, name: "noizave", url_string: "https://deviantart.com/noizave")
@artist = create(:artist, name: "noizave", url_string: "https://deviantart.com/noizave")
assert_equal([@artist], @site.artists)
end

View File

@@ -1,58 +0,0 @@
require 'test_helper'
module Sources
class StashTest < ActiveSupport::TestCase
def setup
super
skip "DeviantArt API keys not set" unless Danbooru.config.deviantart_client_id.present?
end
context "A https://sta.sh/:id page url" do
should "work" do
@site = Sources::Strategies.find("https://sta.sh/0wxs31o7nn2")
assert_equal("noizave", @site.artist_name)
assert_equal("https://www.deviantart.com/noizave", @site.profile_url)
assert_equal("A pepe", @site.artist_commentary_title)
assert_equal("This is a test.", @site.artist_commentary_desc)
assert_equal("https://sta.sh/0wxs31o7nn2", @site.page_url)
assert_equal("https://sta.sh/0wxs31o7nn2", @site.canonical_url)
assert_equal("http://origin-orig.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png", @site.image_url)
assert_equal(["http://origin-orig.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png"], @site.image_urls)
end
end
context "A https://orig00.deviantart.net/* image url" do
context "with a https://sta.sh/:id referer" do
should "work" do
@site = Sources::Strategies.find("https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png", "https://sta.sh/0wxs31o7nn2")
assert_equal("noizave", @site.artist_name)
assert_equal("https://www.deviantart.com/noizave", @site.profile_url)
assert_equal("A pepe", @site.artist_commentary_title)
assert_equal("This is a test.", @site.artist_commentary_desc)
assert_equal("https://sta.sh/0wxs31o7nn2", @site.page_url)
assert_equal("https://sta.sh/0wxs31o7nn2", @site.canonical_url)
assert_equal("http://origin-orig.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png", @site.image_url)
assert_equal(["http://origin-orig.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png"], @site.image_urls)
end
end
context "without a referer" do
should "use the base deviantart strategy" do
@site = Sources::Strategies.find("https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png")
# if all we have is the image url, then we can't tell that this is really a sta.sh image.
assert_equal("Deviant Art", @site.site_name)
# this is the wrong page, but there's no way to know the correct sta.sh page without the referer.
assert_equal("https://www.deviantart.com/deviation/763305148", @site.page_url)
end
end
end
end
end