Merge pull request #3124 from evazion/fix-artstation-sources
Multiple ArtStation fixes
This commit is contained in:
@@ -57,7 +57,7 @@ module Downloads
|
|||||||
def after_download(src)
|
def after_download(src)
|
||||||
src = fix_twitter_sources(src)
|
src = fix_twitter_sources(src)
|
||||||
if options[:referer_url].present?
|
if options[:referer_url].present?
|
||||||
src = set_source_to_referer(src)
|
src = set_source_to_referer(src, options[:referer_url])
|
||||||
end
|
end
|
||||||
src
|
src
|
||||||
end
|
end
|
||||||
@@ -137,12 +137,13 @@ module Downloads
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_source_to_referer(src)
|
def set_source_to_referer(src, referer)
|
||||||
if Sources::Strategies::Nijie.url_match?(src) ||
|
if Sources::Strategies::Nijie.url_match?(src) ||
|
||||||
Sources::Strategies::Twitter.url_match?(src) ||
|
Sources::Strategies::Twitter.url_match?(src) ||
|
||||||
Sources::Strategies::Tumblr.url_match?(src) ||
|
Sources::Strategies::Tumblr.url_match?(src) ||
|
||||||
Sources::Strategies::Pawoo.url_match?(src)
|
Sources::Strategies::Pawoo.url_match?(src) ||
|
||||||
strategy = Sources::Site.new(src, :referer_url => options[:referer_url])
|
Sources::Strategies::ArtStation.url_match?(src) || Sources::Strategies::ArtStation.url_match?(referer)
|
||||||
|
strategy = Sources::Site.new(src, :referer_url => referer)
|
||||||
strategy.referer_url
|
strategy.referer_url
|
||||||
else
|
else
|
||||||
src
|
src
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ module Sources
|
|||||||
[Strategies::PixivWhitecube, Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::ArtStation, Strategies::Nijie, Strategies::Twitter, Strategies::Tumblr, Strategies::Pawoo]
|
[Strategies::PixivWhitecube, Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::ArtStation, Strategies::Nijie, Strategies::Twitter, Strategies::Tumblr, Strategies::Pawoo]
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(url, options = {})
|
def initialize(url, referer_url: nil)
|
||||||
@url = url
|
@url = url
|
||||||
|
|
||||||
Site.strategies.each do |strategy|
|
Site.strategies.each do |strategy|
|
||||||
if strategy.url_match?(url)
|
if strategy.url_match?(url) || strategy.url_match?(referer_url)
|
||||||
@strategy = strategy.new(url, options[:referer_url])
|
@strategy = strategy.new(url, referer_url)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ module Sources::Strategies
|
|||||||
self.project_id(url).present?
|
self.project_id(url).present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# https://www.artstation.com/artwork/04XA4"
|
||||||
|
# https://dantewontdie.artstation.com/projects/YZK5q"
|
||||||
|
# https://www.artstation.com/artwork/cody-from-sf"
|
||||||
def self.project_id(url)
|
def self.project_id(url)
|
||||||
if url =~ %r!\Ahttps?://\w+\.artstation\.com/(?:artwork|projects)/(?<project_id>[a-z0-9]+)\z!i
|
if url =~ %r!\Ahttps?://\w+\.artstation\.com/(?:artwork|projects)/(?<project_id>[a-z0-9-]+)\z!i
|
||||||
$~[:project_id]
|
$~[:project_id]
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
@@ -51,7 +54,8 @@ module Sources::Strategies
|
|||||||
@json = JSON.parse(resp.body)
|
@json = JSON.parse(resp.body)
|
||||||
@artist_name = json["user"]["username"]
|
@artist_name = json["user"]["username"]
|
||||||
@profile_url = json["user"]["permalink"]
|
@profile_url = json["user"]["permalink"]
|
||||||
@image_urls = json["assets"].map do |x|
|
images = json["assets"].select { |asset| asset["asset_type"] == "image" }
|
||||||
|
@image_urls = images.map do |x|
|
||||||
y, _, _ = image_url_rewriter.rewrite(x["image_url"], nil)
|
y, _, _ = image_url_rewriter.rewrite(x["image_url"], nil)
|
||||||
y
|
y
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -529,6 +529,11 @@ class Post < ActiveRecord::Base
|
|||||||
when %r{\Ahttps?://(?:ayase\.|yuno\.|files\.)?yande\.re/(?:image|jpeg|sample)/(?<md5>[a-z0-9]{32})(?:/yande\.re.*|/?\.(?:jpg|png))\Z}i
|
when %r{\Ahttps?://(?:ayase\.|yuno\.|files\.)?yande\.re/(?:image|jpeg|sample)/(?<md5>[a-z0-9]{32})(?:/yande\.re.*|/?\.(?:jpg|png))\Z}i
|
||||||
"https://yande.re/post?tags=md5:#{$~[:md5]}"
|
"https://yande.re/post?tags=md5:#{$~[:md5]}"
|
||||||
|
|
||||||
|
# https://gfee_li.artstation.com/projects/XPGOD
|
||||||
|
# https://gfee_li.artstation.com/projects/asuka-7
|
||||||
|
when %r{\Ahttps?://\w+\.artstation.com/(?:artwork|projects)/(?<project_id>[a-z0-9-]+)\z/}i
|
||||||
|
"https://www.artstation.com/artwork/#{$~[:project_id]}"
|
||||||
|
|
||||||
when %r{\Ahttps?://(?:o|image-proxy-origin)\.twimg\.com/\d/proxy\.jpg\?t=(\w+)&}i
|
when %r{\Ahttps?://(?:o|image-proxy-origin)\.twimg\.com/\d/proxy\.jpg\?t=(\w+)&}i
|
||||||
str = Base64.decode64($1)
|
str = Base64.decode64($1)
|
||||||
url = URI.extract(str, ['http', 'https'])
|
url = URI.extract(str, ['http', 'https'])
|
||||||
|
|||||||
@@ -58,5 +58,42 @@ module Sources
|
|||||||
assert_equal("From Gantz.", @site.artist_commentary_desc)
|
assert_equal("From Gantz.", @site.artist_commentary_desc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "The source site for a www.artstation.com/artwork/$slug page" do
|
||||||
|
setup do
|
||||||
|
@site = Sources::Site.new("https://www.artstation.com/artwork/cody-from-sf")
|
||||||
|
@site.get
|
||||||
|
end
|
||||||
|
|
||||||
|
should "get the image url" do
|
||||||
|
url = "https://cdna.artstation.com/p/assets/images/images/000/144/922/original/cassio-yoshiyaki-cody2backup2-yoshiyaki.jpg?1406314198"
|
||||||
|
assert_equal(url, @site.image_url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "The source site for a http://cdna.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"
|
||||||
|
@site = Sources::Site.new(@url, referer_url: @ref)
|
||||||
|
@site.get
|
||||||
|
end
|
||||||
|
|
||||||
|
should "fetch the source data" do
|
||||||
|
assert_equal("amama", @site.artist_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "The source site for an ArtStation gallery" do
|
||||||
|
setup do
|
||||||
|
@site = Sources::Site.new("https://www.artstation.com/artwork/BDxrA")
|
||||||
|
@site.get
|
||||||
|
end
|
||||||
|
|
||||||
|
should "get only image urls, not video urls" do
|
||||||
|
urls = %w[https://cdnb.artstation.com/p/assets/images/images/006/037/253/original/astri-lohne-sjursen-eva.jpg?1495573664]
|
||||||
|
assert_equal(urls, @site.image_urls)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user