deviantart: take artist name from url when unavailable from API.

In some cases we can't get the artist name from the API, either because
we can't do the API call because the url doesn't contain a deviation id,
or because the work is deleted:

* http://fc08.deviantart.net/files/f/2007/120/c/9/cool_like_me_by_47ness.jpg (work: http://fav.me/dwcohb)
* https://pre00.deviantart.net/423b/th/pre/i/2017/281/e/0/mindflayer_girl01_by_nickbeja-dbpxdt8.png (work: http://fav.me/dbpxd58)

Switch to taking the artist name from the url (when present) to deal
with these cases. Fixes the artist finder and the artist url normalizer
to work in this situation.
This commit is contained in:
evazion
2018-09-02 22:53:24 -05:00
parent 8f87fb90d9
commit e37844303d
2 changed files with 39 additions and 11 deletions

View File

@@ -15,14 +15,21 @@ module Sources
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)
assert_equal("aeror404", @site.artist_name)
assert_equal("https://www.deviantart.com/aeror404", @site.profile_url)
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")
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)
assert_equal("nickbeja", @site.artist_name)
assert_equal("https://www.deviantart.com/nickbeja", @site.profile_url)
assert_equal([@artist], @site.artists)
assert_nothing_raised { @site.to_h }
end
end
@@ -79,6 +86,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")
end
context "without a referer" do
@@ -90,6 +98,7 @@ module Sources
assert_equal("https://www.deviantart.com/47ness", @site.profile_url)
assert_equal("", @site.page_url)
assert_equal(@site.image_url, @site.canonical_url)
assert_equal([@artist], @site.artists)
assert_nothing_raised { @site.to_h }
end
end
@@ -103,6 +112,7 @@ module Sources
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)
assert_equal(@site.page_url, @site.canonical_url)
assert_equal([@artist], @site.artists)
assert_nothing_raised { @site.to_h }
end
end
@@ -112,6 +122,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")
end
context "without a referer" do
@@ -123,6 +134,7 @@ module Sources
assert_equal("", @site.profile_url)
assert_equal("", @site.page_url)
assert_equal(@site.image_url, @site.canonical_url)
assert_equal([], @site.artists)
assert_nothing_raised { @site.to_h }
end
end
@@ -136,6 +148,7 @@ module Sources
assert_equal("https://www.deviantart.com/edsfox", @site.profile_url)
assert_equal("https://www.deviantart.com/edsfox/art/Silverhawks-Quicksilver-126872896", @site.page_url)
assert_equal(@site.page_url, @site.canonical_url)
assert_equal([@artist], @site.artists)
assert_nothing_raised { @site.to_h }
end
end