From 2fd8e9bc14de2c3e323d35e66beb4a3450dd530f Mon Sep 17 00:00:00 2001 From: nonamethanks Date: Sat, 4 Jun 2022 20:26:14 +0200 Subject: [PATCH] Deviantart: fix regression in 3a0a32b98adcb6c110180d3ad5f530a9ad3743e4 --- app/logical/source/extractor/deviant_art.rb | 10 ++++++---- test/unit/sources/deviant_art_test.rb | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/logical/source/extractor/deviant_art.rb b/app/logical/source/extractor/deviant_art.rb index 49565f339..d9c0f9441 100644 --- a/app/logical/source/extractor/deviant_art.rb +++ b/app/logical/source/extractor/deviant_art.rb @@ -38,10 +38,7 @@ module Source def extract_largest(src) if src =~ %r{\Ahttps://images-wixmp-} sample, separator, * = src.partition("/v1/") - if separator.blank? - src = src.sub(%r{(/f/[a-f0-9-]+/[a-f0-9-]+)}, '/intermediary\1') unless src =~ /\.gif\?/ - src - else + if separator.present? # :^) https://i.imgur.com/KG5bVRU.png # shamelessly aped from: # https://github.com/mikf/gallery-dl/blob/7990fe84f11271bc8e4079db6b0248dbeb79474a/gallery_dl/extractor/deviantart.py#L293 @@ -49,6 +46,11 @@ module Source data = {sub: "urn:app:", iss: "urn:app:", obj: [[{path: "/f/#{f_value}"}]], aud: ["urn:service:file.download"]} token = Base64.encode64(JSON.generate(data)).gsub("=", "").gsub("\n", "") "#{sample}?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.#{token}." + elsif deviation_id && deviation_id.to_i <= 790_677_560 && src !~ /\.gif\?/ + src = src.sub(%r{(/f/[a-f0-9-]+/[a-f0-9-]+)}, '/intermediary\1') + src.sub(%r{/v1/(fit|fill)/.*\z}i, "") + else + src end else src = src.sub(%r{\Ahttps?://orig\d+\.deviantart\.net}i, "http://origin-orig.deviantart.net") diff --git a/test/unit/sources/deviant_art_test.rb b/test/unit/sources/deviant_art_test.rb index 548feb336..ab6f7a71f 100644 --- a/test/unit/sources/deviant_art_test.rb +++ b/test/unit/sources/deviant_art_test.rb @@ -42,6 +42,13 @@ module Sources ) end + context "A deviantart post with the intermediary version giving 404" do + strategy_should_work( + "https://www.deviantart.com/gregmks/art/Rhino-Castle-811778248", + image_urls: [%r{\Ahttps://images-wixmp-ed30a86b8c4ca887773594c2\.wixmp\.com/f/8c03bd02-63bf-407e-9c3e-c3fd21ab4bd5/ddfb83s-64c3b1fd-a554-498c-87dd-7ce83721a3d0\.jpg\?token=}] + ) + end + context "A deviantart origin-orig image" do desc = <<-EOS.strip_heredoc.chomp blah blah