Fix #3654: Deviantart commentaries fail fetching.

This commit is contained in:
evazion
2018-04-18 18:26:39 -05:00
parent 9cafffd20a
commit c4ae2bd2fa
2 changed files with 19 additions and 6 deletions

View File

@@ -58,11 +58,12 @@ module Sources
end
def artist_name
api_metadata.dig(:author, :username)
api_metadata.dig(:author, :username).try(&:downcase)
end
def profile_url
"https://#{artist_name.downcase}.deviantart.com"
return "" if uuid.nil?
"https://#{artist_name}.deviantart.com"
end
def image_url
@@ -118,8 +119,10 @@ module Sources
end
def page
resp = HTTParty.get(normalized_url, Danbooru.config.httparty_options)
Nokogiri::HTML(resp.body)
options = Danbooru.config.httparty_options.deep_merge(format: :plain, headers: { "Accept-Encoding" => "gzip" })
resp = HTTParty.get(normalized_url, **options)
body = Zlib.gunzip(resp.body)
Nokogiri::HTML(body)
end
# Scrape UUID from <meta property="da:appurl" content="DeviantArt://deviation/12F08C5D-A3A4-338C-2F1A-7E4E268C0E8B">

View File

@@ -20,6 +20,16 @@ module Sources
end
end
context "The source for a DeviantArt image url" do
should "fetch the source data" do
@site = Sources::Site.new("https://pre00.deviantart.net/b5e6/th/pre/f/2016/265/3/5/legend_of_galactic_heroes_by_hideyoshi-daihpha.jpg")
assert_equal("hideyoshi", @site.artist_name)
assert_equal("https://hideyoshi.deviantart.com", @site.profile_url)
assert_equal("https://orig00.deviantart.net/9e1f/f/2016/265/3/5/legend_of_galactic_heroes_by_hideyoshi-daihpha.jpg", @site.image_url)
end
end
context "The source for an DeviantArt artwork page" do
setup do
@site = Sources::Site.new("http://noizave.deviantart.com/art/test-post-please-ignore-685436408")
@@ -27,7 +37,7 @@ 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)
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)
end
should "get the profile" do
@@ -86,7 +96,7 @@ 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)
assert_match(%r!https?://origin-orig\.deviantart\.net/cb25/f/2017/160/1/9/hidden_work_by_noizave-dbc3r29\.png!, @site.image_url)
end
end