Merge branch 'artstation'
This commit is contained in:
@@ -10,7 +10,7 @@ module Sources
|
||||
:artist_commentary_desc, :rewrite_thumbnails, :illust_id_from_url, :to => :strategy
|
||||
|
||||
def self.strategies
|
||||
[Strategies::PixivWhitecube, Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie, Strategies::Twitter, Strategies::Tumblr]
|
||||
[Strategies::PixivWhitecube, Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::ArtStation, Strategies::Nijie, Strategies::Twitter, Strategies::Tumblr]
|
||||
end
|
||||
|
||||
def initialize(url, options = {})
|
||||
|
||||
50
app/logical/sources/strategies/art_station.rb
Normal file
50
app/logical/sources/strategies/art_station.rb
Normal file
@@ -0,0 +1,50 @@
|
||||
module Sources::Strategies
|
||||
class ArtStation < Base
|
||||
attr_reader :json, :image_urls
|
||||
|
||||
def self.url_match?(url)
|
||||
url =~ %r!^https?://\w+\.artstation\.com/artwork/[a-z0-9]+!i
|
||||
end
|
||||
|
||||
def referer_url
|
||||
end
|
||||
|
||||
def tags
|
||||
json["categories"].map {|x| x["name"].downcase.tr(" ", "_")}
|
||||
end
|
||||
|
||||
def site_name
|
||||
"ArtStation"
|
||||
end
|
||||
|
||||
def api_url
|
||||
url.sub(%r!^https?://\w+\.!, "https://www.").sub(%r!/artwork/!, "/projects/") + ".json"
|
||||
end
|
||||
|
||||
def image_url
|
||||
image_urls.first
|
||||
end
|
||||
|
||||
def get
|
||||
uri = URI.parse(api_url)
|
||||
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.is_a?(URI::HTTPS)) do |http|
|
||||
resp = http.request_get(uri.request_uri)
|
||||
image_url_rewriter = Downloads::RewriteStrategies::ArtStation.new
|
||||
if resp.is_a?(Net::HTTPSuccess)
|
||||
@json = JSON.parse(resp.body)
|
||||
@artist_name = json["user"]["username"]
|
||||
@profile_url = json["user"]["permalink"]
|
||||
@image_urls = json["assets"].map do |x|
|
||||
y, _, _ = image_url_rewriter.rewrite(x["image_url"], nil)
|
||||
y
|
||||
end
|
||||
@tags = json["categories"].map {|x| x["name"].downcase.tr(" ", "_")} if json["categories"]
|
||||
@artist_commentary_title = json["title"]
|
||||
@artist_commentary_desc = ActionView::Base.full_sanitizer.sanitize(json["description"])
|
||||
else
|
||||
raise "HTTP error code: #{resp.code} #{resp.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
33
test/unit/sources/art_station_test.rb
Normal file
33
test/unit/sources/art_station_test.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
require 'test_helper'
|
||||
|
||||
module Sources
|
||||
class ArtStationTest < ActiveSupport::TestCase
|
||||
context "The source site for an art station artwork page" do
|
||||
setup do
|
||||
@site = Sources::Site.new("https://jeyrain.artstation.com/artwork/04XA4")
|
||||
@site.get
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal("https://cdna.artstation.com/p/assets/images/images/000/705/368/original/jey-rain-one1.jpg", @site.image_url.sub(/\?\d+/, ""))
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
assert_equal("https://www.artstation.com/artist/jeyrain", @site.profile_url)
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
assert_equal("jeyrain", @site.artist_name)
|
||||
end
|
||||
|
||||
should "get the tags" do
|
||||
assert_equal([], @site.tags)
|
||||
end
|
||||
|
||||
should "get the artist commentary" do
|
||||
assert_equal("pink", @site.artist_commentary_title)
|
||||
assert_equal("", @site.artist_commentary_desc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user