diff --git a/app/logical/sources/strategies/deviant_art.rb b/app/logical/sources/strategies/deviant_art.rb index d2329a4f4..bde8ec525 100644 --- a/app/logical/sources/strategies/deviant_art.rb +++ b/app/logical/sources/strategies/deviant_art.rb @@ -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 diff --git a/test/unit/sources/deviantart_test.rb b/test/unit/sources/deviantart_test.rb index 2565e1d1b..c5c1a4e66 100644 --- a/test/unit/sources/deviantart_test.rb +++ b/test/unit/sources/deviantart_test.rb @@ -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