Fix #4293: ArtStation: use 4k images.
Also fixes #4290 (Image replacements: undefined method hostname for nil:NilClass)
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#
|
||||
# * https://cdna.artstation.com/p/assets/images/images/005/804/224/large/titapa-khemakavat-sa-dui-srevere.jpg?1493887236
|
||||
# * https://cdnb.artstation.com/p/assets/images/images/014/410/217/smaller_square/bart-osz-bartosz1812041.jpg?1543866276
|
||||
# * https://cdna.artstation.com/p/assets/images/images/007/253/680/4k/ina-wong-demon-girl-done-ttd-comp.jpg?1504793833
|
||||
|
||||
module Sources::Strategies
|
||||
class ArtStation < Base
|
||||
@@ -25,7 +26,7 @@ module Sources::Strategies
|
||||
ARTIST3 = %r{\Ahttps?://www\.artstation\.com/(?<artist_name>[a-z0-9-]+)/?\z}i
|
||||
ARTIST = Regexp.union(ARTIST1, ARTIST2, ARTIST3)
|
||||
|
||||
ASSET = %r!\Ahttps?://cdn\w*\.artstation\.com/p/assets/images/images/\d+/\d+/\d+/(?:medium|small|large)/!i
|
||||
ASSET = %r!\Ahttps?://cdn\w*\.artstation\.com/p/assets/images/images/(?<id>\d+/\d+/\d+)/(?<size>[^/]+)/(?<filename>.+)\z!i
|
||||
|
||||
attr_reader :json
|
||||
|
||||
@@ -38,7 +39,7 @@ module Sources::Strategies
|
||||
end
|
||||
|
||||
def image_urls
|
||||
@image_urls ||= image_urls_sub.map { |asset| original_asset_url(asset) }
|
||||
@image_urls ||= image_urls_sub.map { |asset| largest_asset_url(asset) }
|
||||
end
|
||||
|
||||
def page_url
|
||||
@@ -114,27 +115,17 @@ module Sources::Strategies
|
||||
end
|
||||
memoize :api_response
|
||||
|
||||
# Returns the original representation of the asset, if it exists. Otherwise
|
||||
# return the url.
|
||||
def original_asset_url(x)
|
||||
if x =~ ASSET
|
||||
# example: https://cdnb3.artstation.com/p/assets/images/images/003/716/071/large/aoi-ogata-hate-city.jpg?1476754974
|
||||
original_url = x.sub(%r!/(?:medium|small|large)/!, "/original/")
|
||||
def largest_asset_url(url)
|
||||
return url unless url =~ ASSET
|
||||
|
||||
if http_exists?(original_url, headers)
|
||||
return original_url
|
||||
end
|
||||
urls = [
|
||||
"https://cdn.artstation.com/p/assets/images/images/#{$~[:id]}/original/#{$~[:filename]}",
|
||||
"https://cdn.artstation.com/p/assets/images/images/#{$~[:id]}/4k/#{$~[:filename]}",
|
||||
"https://cdn.artstation.com/p/assets/images/images/#{$~[:id]}/large/#{$~[:filename]}",
|
||||
]
|
||||
|
||||
if x =~ /medium|small/
|
||||
large_url = x.sub(%r!/(?:medium|small)/!, "/large/")
|
||||
|
||||
if http_exists?(large_url, headers)
|
||||
return large_url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return x
|
||||
largest_url = urls.find { |url| http_exists?(url, headers) }
|
||||
largest_url || url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ module Downloads
|
||||
|
||||
should "download the large image instead" do
|
||||
file, strategy = @download.download!
|
||||
assert_equal(517_706, ::File.size(file.path))
|
||||
assert_equal(1_550_269, ::File.size(file.path))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ module Downloads
|
||||
|
||||
should "not try to download the original" do
|
||||
file, strategy = @download.download!
|
||||
assert_equal(449_047, ::File.size(file.path))
|
||||
assert_equal(382_837, ::File.size(file.path))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,11 +32,11 @@ module Downloads
|
||||
end
|
||||
|
||||
should "return the original file, not the polished file" do
|
||||
assert_downloaded(517_706, @asset) # polished size: 502_052
|
||||
assert_downloaded(1_550_269, @asset)
|
||||
end
|
||||
|
||||
should "return the original filesize, not the polished filesize" do
|
||||
assert_equal(517_706, Downloads::File.new(@asset).size)
|
||||
assert_equal(1_550_269, Downloads::File.new(@asset).size)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -49,7 +49,7 @@ module Downloads
|
||||
should "download the original image instead" do
|
||||
file, strategy = @download.download!
|
||||
|
||||
assert_equal(237_651, ::File.size(file.path))
|
||||
assert_equal(218_603, ::File.size(file.path))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ module Sources
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://cdna.artstation.com/p/assets/images/images/000/705/368/large/jey-rain-one1.jpg", @site.image_url.sub(/\?\d+/, ""))
|
||||
assert_equal("https://cdn.artstation.com/p/assets/images/images/000/705/368/4k/jey-rain-one1.jpg", @site.image_url.sub(/\?\d+/, ""))
|
||||
end
|
||||
|
||||
should "get the canonical url" do
|
||||
@@ -39,7 +39,7 @@ module Sources
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
url = "https://cdna.artstation.com/p/assets/images/images/006/066/534/large/yinan-cui-reika.jpg?1495781565"
|
||||
url = "https://cdn.artstation.com/p/assets/images/images/006/066/534/4k/yinan-cui-reika.jpg?1495781565"
|
||||
assert_equal(url, @site.image_url)
|
||||
end
|
||||
|
||||
@@ -72,7 +72,7 @@ module Sources
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
url = "https://cdna.artstation.com/p/assets/images/images/000/144/922/large/cassio-yoshiyaki-cody2backup2-yoshiyaki.jpg?1406314198"
|
||||
url = "https://cdn.artstation.com/p/assets/images/images/000/144/922/4k/cassio-yoshiyaki-cody2backup2-yoshiyaki.jpg?1406314198"
|
||||
assert_equal(url, @site.image_url)
|
||||
end
|
||||
|
||||
@@ -82,7 +82,7 @@ module Sources
|
||||
end
|
||||
end
|
||||
|
||||
context "The source site for a http://cdna.artstation.com/p/assets/... url" do
|
||||
context "The source site for a http://cdn.artstation.com/p/assets/... url" do
|
||||
setup do
|
||||
@url = "https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg"
|
||||
@ref = "https://www.artstation.com/artwork/4BWW2"
|
||||
@@ -92,7 +92,7 @@ module Sources
|
||||
should "work" do
|
||||
site = Sources::Strategies.find(@url, @ref)
|
||||
|
||||
assert_equal(@url, site.image_url)
|
||||
assert_equal("https://cdn.artstation.com/p/assets/images/images/006/029/978/4k/amama-l-z.jpg", site.image_url)
|
||||
assert_equal("https://amama.artstation.com/projects/4BWW2", site.page_url)
|
||||
assert_equal("https://amama.artstation.com/projects/4BWW2", site.canonical_url)
|
||||
assert_equal("https://www.artstation.com/amama", site.profile_url)
|
||||
@@ -105,7 +105,7 @@ module Sources
|
||||
should "work" do
|
||||
site = Sources::Strategies.find(@url)
|
||||
|
||||
assert_equal(@url, site.image_url)
|
||||
assert_equal("https://cdn.artstation.com/p/assets/images/images/006/029/978/4k/amama-l-z.jpg", site.image_url)
|
||||
assert_nil(site.page_url)
|
||||
assert_nil(site.profile_url)
|
||||
assert_nil(site.artist_name)
|
||||
@@ -115,13 +115,24 @@ module Sources
|
||||
end
|
||||
end
|
||||
|
||||
context "A 4k asset url" do
|
||||
context "without a referer" do
|
||||
should "work" do
|
||||
site = Sources::Strategies.find("https://cdna.artstation.com/p/assets/images/images/007/253/680/4k/ina-wong-demon-girl-done-ttd-comp.jpg?1504793833")
|
||||
|
||||
assert_equal("https://cdn.artstation.com/p/assets/images/images/007/253/680/4k/ina-wong-demon-girl-done-ttd-comp.jpg?1504793833", site.image_url)
|
||||
assert_nothing_raised { site.to_h }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "The source site for an ArtStation gallery" do
|
||||
setup do
|
||||
@site = Sources::Strategies.find("https://www.artstation.com/artwork/BDxrA")
|
||||
end
|
||||
|
||||
should "get only image urls, not video urls" do
|
||||
urls = %w[https://cdnb.artstation.com/p/assets/images/images/006/037/253/large/astri-lohne-sjursen-eva.jpg?1495573664]
|
||||
urls = %w[https://cdn.artstation.com/p/assets/images/images/006/037/253/4k/astri-lohne-sjursen-eva.jpg?1495573664]
|
||||
assert_equal(urls, @site.image_urls)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user