Merge pull request #5285 from nonamethanks/tests
Rewrite the tests for various source strategies
This commit is contained in:
@@ -15,7 +15,7 @@ class MastodonApiClient
|
||||
def json
|
||||
return {} if id.blank? || access_token.blank?
|
||||
JSON.parse(access_token.get("/api/v1/statuses/#{id}").body)
|
||||
rescue
|
||||
rescue JSON::ParserError
|
||||
{}
|
||||
end
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class Source::Extractor
|
||||
|
||||
def tags
|
||||
api_response[:tags].to_a.map do |tag|
|
||||
[tag, "https://www.artstation.com/search?q=" + CGI.escape(tag)]
|
||||
[tag, "https://www.artstation.com/search?q=#{CGI.escape(tag)}"]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -94,7 +94,7 @@ class Source::Extractor
|
||||
image_sizes = %w[original 4k large medium small]
|
||||
urls = image_sizes.map { |size| parsed_url.full_image_url(size) }
|
||||
|
||||
chosen_url = urls.find { |url| http_exists?(url) }
|
||||
chosen_url = urls.find { |u| http_exists?(u) }
|
||||
chosen_url || url
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,7 +52,7 @@ class Source::Extractor
|
||||
end
|
||||
|
||||
def artist_name
|
||||
api_response.account_name
|
||||
api_response.account_name || artist_name_from_url
|
||||
end
|
||||
|
||||
def artist_name_from_url
|
||||
@@ -60,7 +60,7 @@ class Source::Extractor
|
||||
end
|
||||
|
||||
def other_names
|
||||
[api_response.display_name]
|
||||
[api_response.display_name].compact
|
||||
end
|
||||
|
||||
def account_id
|
||||
|
||||
@@ -2,35 +2,17 @@ require 'test_helper'
|
||||
|
||||
module Sources
|
||||
class ArtStationTest < ActiveSupport::TestCase
|
||||
context "The source site for an art station artwork page" do
|
||||
setup do
|
||||
@site = Source::Extractor.find("https://www.artstation.com/artwork/04XA4")
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal(["https://cdn.artstation.com/p/assets/images/images/000/705/368/4k/jey-rain-one1.jpg?1443931773"], @site.image_urls)
|
||||
end
|
||||
|
||||
should "get the page url" do
|
||||
assert_equal("https://jeyrain.artstation.com/projects/04XA4", @site.page_url)
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
assert_equal("https://www.artstation.com/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.dtext_artist_commentary_desc)
|
||||
end
|
||||
context "An ArtStation /artwork/:id URL" do
|
||||
strategy_should_work(
|
||||
"https://www.artstation.com/artwork/04XA4",
|
||||
image_urls: ["https://cdn.artstation.com/p/assets/images/images/000/705/368/4k/jey-rain-one1.jpg?1443931773"],
|
||||
page_url: "https://jeyrain.artstation.com/projects/04XA4",
|
||||
profile_url: "https://www.artstation.com/jeyrain",
|
||||
artist_name: "jeyrain",
|
||||
tags: [],
|
||||
artist_commentary_title: "pink",
|
||||
dtext_artist_commentary_desc: ""
|
||||
)
|
||||
end
|
||||
|
||||
context "An ArtStation /projects/ URL" do
|
||||
@@ -43,94 +25,56 @@ module Sources
|
||||
tags: %w[gantz Reika],
|
||||
artist_commentary_title: "Reika ",
|
||||
dtext_artist_commentary_desc: "From Gantz.",
|
||||
download_size: 210_899,
|
||||
download_size: 210_899
|
||||
)
|
||||
end
|
||||
|
||||
context "The source site for a www.artstation.com/artwork/$slug page" do
|
||||
setup do
|
||||
@site = Source::Extractor.find("https://www.artstation.com/artwork/cody-from-sf")
|
||||
context "An ArtStation /artwork/$slug page" do
|
||||
strategy_should_work(
|
||||
"https://www.artstation.com/artwork/cody-from-sf",
|
||||
image_urls: ["https://cdn.artstation.com/p/assets/images/images/000/144/922/4k/cassio-yoshiyaki-cody2backup2-yoshiyaki.jpg?1406314198"],
|
||||
tags: ["Street Fighter", "Cody", "SF"]
|
||||
)
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
url = "https://cdn.artstation.com/p/assets/images/images/000/144/922/4k/cassio-yoshiyaki-cody2backup2-yoshiyaki.jpg?1406314198"
|
||||
assert_equal([url], @site.image_urls)
|
||||
context "A http://cdn.artstation.com/p/assets/... url" do
|
||||
strategy_should_work(
|
||||
"https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg",
|
||||
image_urls: ["https://cdn.artstation.com/p/assets/images/images/006/029/978/4k/amama-l-z.jpg"],
|
||||
page_url: nil,
|
||||
profile_url: nil
|
||||
)
|
||||
end
|
||||
|
||||
should "get the tags" do
|
||||
assert_equal(["Street Fighter", "Cody", "SF"].sort, @site.tags.map(&:first).sort)
|
||||
assert_equal(["street_fighter", "cody", "sf"].sort, @site.normalized_tags.sort)
|
||||
end
|
||||
context "A http://cdn.artstation.com/p/assets/... url with referrer" do
|
||||
strategy_should_work(
|
||||
"https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg",
|
||||
image_urls: ["https://cdn.artstation.com/p/assets/images/images/006/029/978/4k/amama-l-z.jpg"],
|
||||
referer: "https://www.artstation.com/artwork/4BWW2",
|
||||
page_url: "https://amama.artstation.com/projects/4BWW2",
|
||||
profile_url: "https://www.artstation.com/amama",
|
||||
artist_name: "amama"
|
||||
)
|
||||
end
|
||||
|
||||
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"
|
||||
context "An ArtStation cover url" do
|
||||
strategy_should_work(
|
||||
"https://cdna.artstation.com/p/assets/covers/images/007/262/828/large/monica-kyrie-1.jpg?1504865060",
|
||||
image_urls: ["https://cdn.artstation.com/p/assets/covers/images/007/262/828/original/monica-kyrie-1.jpg?1504865060"]
|
||||
)
|
||||
end
|
||||
|
||||
context "with a referer" do
|
||||
should "work" do
|
||||
site = Source::Extractor.find(@url, @ref)
|
||||
|
||||
assert_equal(["https://cdn.artstation.com/p/assets/images/images/006/029/978/4k/amama-l-z.jpg"], site.image_urls)
|
||||
assert_equal("https://amama.artstation.com/projects/4BWW2", site.page_url)
|
||||
assert_equal("https://www.artstation.com/amama", site.profile_url)
|
||||
assert_equal("amama", site.artist_name)
|
||||
assert_nothing_raised { site.to_h }
|
||||
end
|
||||
context "An ArtStation post with images and youtube links" do
|
||||
strategy_should_work(
|
||||
"https://www.artstation.com/artwork/BDxrA",
|
||||
image_urls: ["https://cdn.artstation.com/p/assets/images/images/006/037/253/4k/astri-lohne-sjursen-eva.jpg?1495573664"]
|
||||
)
|
||||
end
|
||||
|
||||
context "without a referer" do
|
||||
should "work" do
|
||||
site = Source::Extractor.find(@url)
|
||||
|
||||
assert_equal(["https://cdn.artstation.com/p/assets/images/images/006/029/978/4k/amama-l-z.jpg"], site.image_urls)
|
||||
assert_nil(site.page_url)
|
||||
assert_nil(site.profile_url)
|
||||
assert_nil(site.artist_name)
|
||||
assert_equal([], site.tags)
|
||||
assert_nothing_raised { site.to_h }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "A 4k asset url" do
|
||||
context "without a referer" do
|
||||
should "work" do
|
||||
site = Source::Extractor.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_urls)
|
||||
assert_nothing_raised { site.to_h }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "A cover url" do
|
||||
should "work" do
|
||||
url = "https://cdna.artstation.com/p/assets/covers/images/007/262/828/large/monica-kyrie-1.jpg?1504865060"
|
||||
site = Source::Extractor.find(url)
|
||||
|
||||
assert_equal(["https://cdn.artstation.com/p/assets/covers/images/007/262/828/original/monica-kyrie-1.jpg?1504865060"], site.image_urls)
|
||||
end
|
||||
end
|
||||
|
||||
context "The source site for an ArtStation gallery" do
|
||||
setup do
|
||||
@site = Source::Extractor.find("https://www.artstation.com/artwork/BDxrA")
|
||||
end
|
||||
|
||||
should "get only image urls, not video urls" do
|
||||
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
|
||||
|
||||
context "A work that includes video clips" do
|
||||
should_eventually "include the video clips in the image urls" do
|
||||
@source = Source::Extractor.find("https://www.artstation.com/artwork/0nP1e8")
|
||||
|
||||
assert_equal(%w[
|
||||
context "An ArtStation post with images and videos" do
|
||||
strategy_should_work( # XXX Broken by Cloudflare captcha
|
||||
"https://www.artstation.com/artwork/0nP1e8",
|
||||
image_urls: %w[
|
||||
https://cdn.artstation.com/p/assets/images/images/040/979/418/original/yusuf-umar-workout-10mb.gif?1630425406
|
||||
https://cdn.artstation.com/p/assets/images/images/040/979/435/4k/yusuf-umar-1.jpg?1630425420
|
||||
https://cdn.artstation.com/p/assets/images/images/040/979/470/4k/yusuf-umar-2.jpg?1630425483
|
||||
@@ -140,34 +84,33 @@ module Sources
|
||||
https://cdn.artstation.com/p/assets/images/images/040/980/932/4k/yusuf-umar-tpose.jpg?1630427748
|
||||
https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4
|
||||
https://cdn-animation.artstation.com/p/video_sources/000/466/623/workout-clay.mp4
|
||||
], @source.image_urls)
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
should "work for the video itself" do
|
||||
@source = Source::Extractor.find("https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4")
|
||||
|
||||
assert_equal(["https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4"], @source.image_urls)
|
||||
end
|
||||
context "An ArtStation video url" do
|
||||
strategy_should_work(
|
||||
"https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4",
|
||||
image_urls: ["https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4"]
|
||||
)
|
||||
end
|
||||
|
||||
context "A work that has been deleted" do
|
||||
should "work" do
|
||||
url = "https://fiship.artstation.com/projects/x8n8XT"
|
||||
site = Source::Extractor.find(url)
|
||||
|
||||
assert_equal("fiship", site.artist_name)
|
||||
assert_equal("https://www.artstation.com/fiship", site.profile_url)
|
||||
assert_equal(url, site.page_url)
|
||||
assert_equal([], site.image_urls)
|
||||
assert_nothing_raised { site.to_h }
|
||||
end
|
||||
context "A deleted ArtStation url" do
|
||||
strategy_should_work(
|
||||
"https://fiship.artstation.com/projects/x8n8XT",
|
||||
deleted: true,
|
||||
image_urls: [],
|
||||
artist_name: "fiship",
|
||||
profile_url: "https://www.artstation.com/fiship",
|
||||
page_url: "https://fiship.artstation.com/projects/x8n8XT"
|
||||
)
|
||||
end
|
||||
|
||||
context "A /small/ ArtStation image URL" do
|
||||
strategy_should_work(
|
||||
"https://cdnb3.artstation.com/p/assets/images/images/003/716/071/small/aoi-ogata-hate-city.jpg?1476754974",
|
||||
image_urls: ["https://cdn.artstation.com/p/assets/images/images/003/716/071/4k/aoi-ogata-hate-city.jpg?1476754974"],
|
||||
download_size: 1_816_628,
|
||||
download_size: 1_816_628
|
||||
)
|
||||
end
|
||||
|
||||
@@ -175,7 +118,7 @@ module Sources
|
||||
strategy_should_work(
|
||||
"https://cdnb.artstation.com/p/assets/images/images/003/716/071/large/aoi-ogata-hate-city.jpg?1476754974",
|
||||
image_urls: ["https://cdn.artstation.com/p/assets/images/images/003/716/071/4k/aoi-ogata-hate-city.jpg?1476754974"],
|
||||
download_size: 1_816_628,
|
||||
download_size: 1_816_628
|
||||
)
|
||||
end
|
||||
|
||||
@@ -183,18 +126,22 @@ module Sources
|
||||
strategy_should_work(
|
||||
"https://cdna.artstation.com/p/assets/images/images/004/730/278/large/mendel-oh-dragonll.jpg",
|
||||
image_urls: ["https://cdn.artstation.com/p/assets/images/images/004/730/278/4k/mendel-oh-dragonll.jpg"],
|
||||
download_size: 452_985,
|
||||
download_size: 452_985
|
||||
)
|
||||
end
|
||||
|
||||
should "work for artists with underscores in their name" do
|
||||
site = Source::Extractor.find("https://hosi_na.artstation.com/projects/3oEk3B")
|
||||
assert_equal("hosi_na", site.artist_name)
|
||||
context "An ArtStation url with underscores in the artist name" do
|
||||
strategy_should_work(
|
||||
"https://hosi_na.artstation.com/projects/3oEk3B",
|
||||
artist_name: "hosi_na"
|
||||
)
|
||||
end
|
||||
|
||||
should "work for artists with dashes in their name" do
|
||||
site = Source::Extractor.find("https://sa-dui.artstation.com/projects/DVERn")
|
||||
assert_equal("sa-dui", site.artist_name)
|
||||
context "An ArtStation url with dashes in the artist name" do
|
||||
strategy_should_work(
|
||||
"https://sa-dui.artstation.com/projects/DVERn",
|
||||
artist_name: "sa-dui"
|
||||
)
|
||||
end
|
||||
|
||||
should "Parse ArtStation URLs correctly" do
|
||||
@@ -212,9 +159,9 @@ module Sources
|
||||
assert(Source::URL.profile_url?("https://artstation.com/artist/sa-dui"))
|
||||
assert(Source::URL.profile_url?("https://anubis1982918.artstation.com"))
|
||||
|
||||
refute(Source::URL.profile_url?("https://anubis1982918.artstation.com/projects/qPVGP"))
|
||||
refute(Source::URL.profile_url?("https://www.artstation.com"))
|
||||
refute(Source::URL.profile_url?("https://artstation.com"))
|
||||
assert_not(Source::URL.profile_url?("https://anubis1982918.artstation.com/projects/qPVGP"))
|
||||
assert_not(Source::URL.profile_url?("https://www.artstation.com"))
|
||||
assert_not(Source::URL.profile_url?("https://artstation.com"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,145 +3,91 @@ require 'test_helper'
|
||||
module Sources
|
||||
class FanboxTest < ActiveSupport::TestCase
|
||||
context "A free Pixiv Fanbox post" do
|
||||
setup do
|
||||
@post1 = Source::Extractor.find("https://yanmi0308.fanbox.cc/posts/1141325")
|
||||
@post2 = Source::Extractor.find("https://chanxco.fanbox.cc/posts/209386")
|
||||
@post3 = Source::Extractor.find("https://downloads.fanbox.cc/images/post/209386/w/1200/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg")
|
||||
|
||||
assert_nothing_raised { @post1.to_h }
|
||||
assert_nothing_raised { @post2.to_h }
|
||||
assert_nothing_raised { @post3.to_h }
|
||||
end
|
||||
|
||||
should "get the image urls" do
|
||||
# "images" in api response
|
||||
images1 = %w[
|
||||
strategy_should_work(
|
||||
"https://yanmi0308.fanbox.cc/posts/1141325",
|
||||
image_urls: %w[
|
||||
https://downloads.fanbox.cc/images/post/1141325/q7GaJ0A9J5Uz8kvEAUizHJoN.png
|
||||
https://downloads.fanbox.cc/images/post/1141325/LMJz0sAig5h9D3rPZGCEGniZ.png
|
||||
https://downloads.fanbox.cc/images/post/1141325/dRSz380Uf3N8s4pT2ADEXBco.png
|
||||
https://downloads.fanbox.cc/images/post/1141325/h48L2mbm39qqNUB1abLAvzvg.png
|
||||
]
|
||||
assert_equal(images1, @post1.image_urls)
|
||||
],
|
||||
artist_commentary_title: "栗山やんみ(デザイン)",
|
||||
artist_commentary_desc: "˗ˋˏ Special Thanks ˎˊ˗ (敬称略)\n\n🎨キャラクターデザイン\n特急みかん https://twitter.com/tokkyuumikan\n\n🤖3Dモデリング\n(仮) https://twitter.com/Admiral_TMP\n\n⚙プログラミング\n神無月ユズカ https://twitter.com/Kannaduki_Yzk\n\n🎧OP・EDミュージック\n卓球少年 https://twitter.com/takkyuu_s\n\n📻BGM\nC https://twitter.com/nica2c\n\n🖌ロゴデザイン\nてづかもり https://twitter.com/tezkamori\n\n🎨SDキャラクター\nAZU。 https://twitter.com/tokitou_aaa",
|
||||
page_url: "https://yanmi0308.fanbox.cc/posts/1141325",
|
||||
profile_url: "https://yanmi0308.fanbox.cc",
|
||||
download_size: 431_225,
|
||||
tags: [
|
||||
["栗山やんみ", "https://fanbox.cc/tags/栗山やんみ"], ["VTuber", "https://fanbox.cc/tags/VTuber"], ["三面図", "https://fanbox.cc/tags/三面図"],
|
||||
["イラスト", "https://fanbox.cc/tags/イラスト"], ["ロゴデザイン", "https://fanbox.cc/tags/ロゴデザイン"], ["モデリング", "https://fanbox.cc/tags/モデリング"],
|
||||
],
|
||||
artist_name: "yanmi0308",
|
||||
display_name: "栗山やんみ"
|
||||
)
|
||||
end
|
||||
|
||||
# "imageMapi" in api response (embedded pics)
|
||||
images2 = %w[
|
||||
context "A free Pixiv Fanbox post with embedded pics" do
|
||||
strategy_should_work(
|
||||
"https://chanxco.fanbox.cc/posts/209386",
|
||||
image_urls: %w[
|
||||
https://downloads.fanbox.cc/images/post/209386/Q8rZ0iMHpcmJDACEzNGjTj9E.jpeg
|
||||
https://downloads.fanbox.cc/images/post/209386/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg
|
||||
https://downloads.fanbox.cc/images/post/209386/AGGWF0JxytFcNL2ybPKBaqp7.jpeg
|
||||
]
|
||||
assert_equal(images2, @post2.image_urls)
|
||||
],
|
||||
artist_commentary_title: "水着BBちゃん+アラフィフ+ライダーさん",
|
||||
artist_commentary_desc: "今週のらくがきまとめ\n\nhttps://downloads.fanbox.cc/images/post/209386/Q8rZ0iMHpcmJDACEzNGjTj9E.jpeg\n水着BBちゃん\n第一再臨もなかなかセクシー\nhttps://downloads.fanbox.cc/images/post/209386/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg\nアラフィフ\n男キャラも描いていこうと練習中\n新宿での軽いキャラも好き\nhttps://downloads.fanbox.cc/images/post/209386/AGGWF0JxytFcNL2ybPKBaqp7.jpeg\nライダーさん\nつい眼鏡も描いてしまう\n\n#FGO\n",
|
||||
page_url: "https://chanxco.fanbox.cc/posts/209386",
|
||||
profile_url: "https://chanxco.fanbox.cc",
|
||||
download_size: 245_678,
|
||||
artist_name: "chanxco",
|
||||
display_name: "CHANxCO"
|
||||
)
|
||||
end
|
||||
|
||||
should "get the commentary" do
|
||||
# Normal commentary
|
||||
assert_equal("栗山やんみ(デザイン)", @post1.artist_commentary_title)
|
||||
|
||||
body1 = "˗ˋˏ Special Thanks ˎˊ˗ (敬称略)\n\n🎨キャラクターデザイン\n特急みかん https://twitter.com/tokkyuumikan\n\n🤖3Dモデリング\n(仮) https://twitter.com/Admiral_TMP\n\n⚙プログラミング\n神無月ユズカ https://twitter.com/Kannaduki_Yzk\n\n🎧OP・EDミュージック\n卓球少年 https://twitter.com/takkyuu_s\n\n📻BGM\nC https://twitter.com/nica2c\n\n🖌ロゴデザイン\nてづかもり https://twitter.com/tezkamori\n\n🎨SDキャラクター\nAZU。 https://twitter.com/tokitou_aaa"
|
||||
assert_equal(body1, @post1.artist_commentary_desc)
|
||||
|
||||
# With embedded pics
|
||||
assert_equal("水着BBちゃん+アラフィフ+ライダーさん", @post2.artist_commentary_title)
|
||||
assert_equal("水着BBちゃん+アラフィフ+ライダーさん", @post3.artist_commentary_title)
|
||||
|
||||
body2 = "今週のらくがきまとめ\n\nhttps://downloads.fanbox.cc/images/post/209386/Q8rZ0iMHpcmJDACEzNGjTj9E.jpeg\n水着BBちゃん\n第一再臨もなかなかセクシー\nhttps://downloads.fanbox.cc/images/post/209386/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg\nアラフィフ\n男キャラも描いていこうと練習中\n新宿での軽いキャラも好き\nhttps://downloads.fanbox.cc/images/post/209386/AGGWF0JxytFcNL2ybPKBaqp7.jpeg\nライダーさん\nつい眼鏡も描いてしまう\n\n#FGO\n"
|
||||
assert_equal(body2, @post2.artist_commentary_desc)
|
||||
assert_equal(body2, @post3.artist_commentary_desc)
|
||||
context "A Pixiv Fanbox sample" do
|
||||
strategy_should_work(
|
||||
"https://downloads.fanbox.cc/images/post/209386/w/1200/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg",
|
||||
image_urls: ["https://downloads.fanbox.cc/images/post/209386/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg"],
|
||||
artist_commentary_title: "水着BBちゃん+アラフィフ+ライダーさん",
|
||||
artist_commentary_desc: "今週のらくがきまとめ\n\nhttps://downloads.fanbox.cc/images/post/209386/Q8rZ0iMHpcmJDACEzNGjTj9E.jpeg\n水着BBちゃん\n第一再臨もなかなかセクシー\nhttps://downloads.fanbox.cc/images/post/209386/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg\nアラフィフ\n男キャラも描いていこうと練習中\n新宿での軽いキャラも好き\nhttps://downloads.fanbox.cc/images/post/209386/AGGWF0JxytFcNL2ybPKBaqp7.jpeg\nライダーさん\nつい眼鏡も描いてしまう\n\n#FGO\n",
|
||||
page_url: "https://chanxco.fanbox.cc/posts/209386",
|
||||
profile_url: "https://chanxco.fanbox.cc",
|
||||
download_size: 320_056,
|
||||
artist_name: "chanxco",
|
||||
display_name: "CHANxCO"
|
||||
)
|
||||
end
|
||||
|
||||
should "get the right page url" do
|
||||
assert_equal("https://yanmi0308.fanbox.cc/posts/1141325", @post1.page_url)
|
||||
assert_equal("https://chanxco.fanbox.cc/posts/209386", @post2.page_url)
|
||||
assert_equal("https://chanxco.fanbox.cc/posts/209386", @post3.page_url)
|
||||
end
|
||||
|
||||
should "correctly download the right image" do
|
||||
assert_downloaded(431_225, @post1.image_urls[0])
|
||||
assert_downloaded(753_048, @post1.image_urls[1])
|
||||
assert_downloaded(589_327, @post1.image_urls[2])
|
||||
assert_downloaded(178_739, @post1.image_urls[3])
|
||||
|
||||
assert_downloaded(245_678, @post2.image_urls[0])
|
||||
assert_downloaded(320_056, @post2.image_urls[1])
|
||||
assert_downloaded(666_681, @post2.image_urls[2])
|
||||
|
||||
assert_downloaded(320_056, @post3.image_urls.sole)
|
||||
end
|
||||
|
||||
should "get the tags" do
|
||||
tags = [
|
||||
["栗山やんみ", "https://fanbox.cc/tags/栗山やんみ"], ["VTuber", "https://fanbox.cc/tags/VTuber"], ["三面図", "https://fanbox.cc/tags/三面図"],
|
||||
["イラスト", "https://fanbox.cc/tags/イラスト"], ["ロゴデザイン", "https://fanbox.cc/tags/ロゴデザイン"], ["モデリング", "https://fanbox.cc/tags/モデリング"]
|
||||
]
|
||||
assert_equal(tags, @post1.tags)
|
||||
end
|
||||
|
||||
should "find the correct artist" do
|
||||
@artist1 = FactoryBot.create(:artist, name: "yanmi", url_string: @post1.url)
|
||||
@artist2 = FactoryBot.create(:artist, name: "chanxco", url_string: @post2.url)
|
||||
assert_equal([@artist1], @post1.artists)
|
||||
assert_equal([@artist2], @post2.artists)
|
||||
assert_equal([@artist2], @post3.artists)
|
||||
end
|
||||
|
||||
should "find the right artist names" do
|
||||
assert_equal("yanmi0308", @post1.artist_name)
|
||||
assert_equal("栗山やんみ", @post1.display_name)
|
||||
assert_equal("chanxco", @post2.artist_name)
|
||||
assert_equal("CHANxCO", @post2.display_name)
|
||||
assert_equal(@post2.artist_name, @post3.artist_name)
|
||||
assert_equal(@post2.display_name, @post3.display_name)
|
||||
end
|
||||
end
|
||||
|
||||
context "an age-restricted fanbox post" do
|
||||
should "work" do
|
||||
@source = Source::Extractor.find("https://mfr.fanbox.cc/posts/1306390")
|
||||
|
||||
assert_nothing_raised { @source.to_h }
|
||||
assert_equal("mfr", @source.artist_name)
|
||||
assert_equal(["https://downloads.fanbox.cc/images/post/1306390/VOXblkyvltL5fRhMoR7RdSkk.png"], @source.image_urls)
|
||||
end
|
||||
end
|
||||
|
||||
context "A link in the old format" do
|
||||
should "still work" do
|
||||
post = Source::Extractor.find("https://www.pixiv.net/fanbox/creator/1566167/post/39714")
|
||||
assert_nothing_raised { post.to_h }
|
||||
assert_equal("https://omu001.fanbox.cc", post.profile_url)
|
||||
assert_equal("https://omu001.fanbox.cc/posts/39714", post.page_url)
|
||||
artist = FactoryBot.create(:artist, name: "omu", url_string: "https://omu001.fanbox.cc")
|
||||
assert_equal([artist], post.artists)
|
||||
end
|
||||
context "An age-restricted Fanbox post" do
|
||||
strategy_should_work(
|
||||
"https://mfr.fanbox.cc/posts/1306390",
|
||||
image_urls: ["https://downloads.fanbox.cc/images/post/1306390/VOXblkyvltL5fRhMoR7RdSkk.png"],
|
||||
artist_name: "mfr",
|
||||
artist_commentary_desc: "これからセックスしまーす♪と言ってるシーン(・ω・`)\nhttps://downloads.fanbox.cc/images/post/1306390/VOXblkyvltL5fRhMoR7RdSkk.png\n※海苔強化して再アップしました( 'A`;)\n",
|
||||
profile_url: "https://mfr.fanbox.cc"
|
||||
)
|
||||
end
|
||||
|
||||
context "A cover image" do
|
||||
should "still work" do
|
||||
post = Source::Extractor.find("https://pixiv.pximg.net/c/1620x580_90_a2_g5/fanbox/public/images/creator/1566167/cover/QqxYtuWdy4XWQx1ZLIqr4wvA.jpeg")
|
||||
assert_nothing_raised { post.to_h }
|
||||
assert_downloaded(750_484, post.image_urls.sole)
|
||||
assert_equal("https://omu001.fanbox.cc", post.profile_url)
|
||||
assert_equal(post.profile_url, post.page_url)
|
||||
artist = FactoryBot.create(:artist, name: "omu", url_string: "https://omu001.fanbox.cc")
|
||||
assert_equal([artist], post.artists)
|
||||
end
|
||||
strategy_should_work(
|
||||
"https://pixiv.pximg.net/c/1620x580_90_a2_g5/fanbox/public/images/creator/1566167/cover/QqxYtuWdy4XWQx1ZLIqr4wvA.jpeg",
|
||||
download_size: 750_484,
|
||||
profile_url: "https://omu001.fanbox.cc"
|
||||
)
|
||||
end
|
||||
|
||||
context "A dead profile picture from the old domain" do
|
||||
should "still find the artist" do
|
||||
post = Source::Extractor.find("https://pixiv.pximg.net/c/400x400_90_a2_g5/fanbox/public/images/creator/1566167/profile/Ix6bnJmTaOAFZhXHLbWyIY1e.jpeg")
|
||||
assert_equal("https://omu001.fanbox.cc", post.profile_url)
|
||||
artist = FactoryBot.create(:artist, name: "omu", url_string: "https://omu001.fanbox.cc")
|
||||
assert_equal([artist], post.artists)
|
||||
end
|
||||
context "A post in the old pixiv format" do
|
||||
strategy_should_work(
|
||||
"https://www.pixiv.net/fanbox/creator/1566167/post/39714",
|
||||
page_url: "https://omu001.fanbox.cc/posts/39714",
|
||||
profile_url: "https://omu001.fanbox.cc"
|
||||
)
|
||||
end
|
||||
|
||||
context "A deleted /fanbox/creator/:id profile url" do
|
||||
should "not raise an exception" do
|
||||
source = Source::Extractor.find("https://www.pixiv.net/fanbox/creator/40684196")
|
||||
|
||||
assert_equal("https://www.pixiv.net/fanbox/creator/40684196", source.profile_url)
|
||||
assert_nothing_raised { source.to_h }
|
||||
end
|
||||
context "A dead profile picture in the old pixiv format" do
|
||||
strategy_should_work(
|
||||
"https://pixiv.pximg.net/c/400x400_90_a2_g5/fanbox/public/images/creator/29999491/profile/Ew6fOhLGPvmUcwU6FyH8JAMX.jpeg",
|
||||
profile_url: "https://deaver0211.fanbox.cc"
|
||||
)
|
||||
end
|
||||
|
||||
should "Parse Fanbox URLs correctly" do
|
||||
@@ -158,8 +104,8 @@ module Sources
|
||||
assert(Source::URL.profile_url?("https://www.pixiv.net/fanbox/creator/1566167"))
|
||||
assert(Source::URL.profile_url?("https://www.pixiv.net/fanbox/member.php?user_id=3410642"))
|
||||
assert(Source::URL.profile_url?("https://omu001.fanbox.cc"))
|
||||
refute(Source::URL.profile_url?("https://www.fanbox.cc"))
|
||||
refute(Source::URL.profile_url?("https://fanbox.cc"))
|
||||
assert_not(Source::URL.profile_url?("https://www.fanbox.cc"))
|
||||
assert_not(Source::URL.profile_url?("https://fanbox.cc"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,99 +2,60 @@ require 'test_helper'
|
||||
|
||||
module Sources
|
||||
class HentaiFoundryTest < ActiveSupport::TestCase
|
||||
context "The source for a hentai foundry picture" do
|
||||
setup do
|
||||
@image_1 = Source::Extractor.find("https://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda")
|
||||
@image_2 = Source::Extractor.find("https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png")
|
||||
context "A hentai-foundry post" do
|
||||
strategy_should_work(
|
||||
"https://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda",
|
||||
image_urls: ["https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png"],
|
||||
artist_name: "Afrobull",
|
||||
artist_commentary_title: "kuroeda",
|
||||
profile_url: "https://www.hentai-foundry.com/user/Afrobull",
|
||||
download_size: 1_349_887,
|
||||
tags: [["elf", "https://www.hentai-foundry.com/pictures/tagged/elf"]]
|
||||
)
|
||||
end
|
||||
|
||||
should "get the illustration id" do
|
||||
assert_equal("795025", @image_1.illust_id)
|
||||
assert_equal("795025", @image_2.illust_id)
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
assert_equal("Afrobull", @image_1.artist_name)
|
||||
assert_equal("Afrobull", @image_2.artist_name)
|
||||
end
|
||||
|
||||
should "get the artist commentary title" do
|
||||
assert_equal("kuroeda", @image_1.artist_commentary_title)
|
||||
assert_equal("kuroeda", @image_2.artist_commentary_title)
|
||||
end
|
||||
|
||||
should "get profile url" do
|
||||
assert_equal("https://www.hentai-foundry.com/user/Afrobull", @image_1.profile_url)
|
||||
assert_equal("https://www.hentai-foundry.com/user/Afrobull", @image_2.profile_url)
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal(["https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png"], @image_1.image_urls)
|
||||
assert_equal(["https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png"], @image_2.image_urls)
|
||||
end
|
||||
|
||||
should "download an image" do
|
||||
assert_downloaded(1_349_887, @image_1.image_urls.sole)
|
||||
assert_downloaded(1_349_887, @image_2.image_urls.sole)
|
||||
end
|
||||
|
||||
should "get the tags" do
|
||||
assert_equal([["elf", "https://www.hentai-foundry.com/pictures/tagged/elf"]], @image_1.tags)
|
||||
assert_equal([["elf", "https://www.hentai-foundry.com/pictures/tagged/elf"]], @image_2.tags)
|
||||
end
|
||||
|
||||
should "find the correct artist" do
|
||||
@artist = FactoryBot.create(:artist, name: "Afrobull", url_string: @image_1.url)
|
||||
assert_equal([@artist], @image_1.artists)
|
||||
assert_equal([@artist], @image_2.artists)
|
||||
end
|
||||
end
|
||||
|
||||
context "An artist profile url" do
|
||||
setup do
|
||||
@site = Source::Extractor.find("https://www.hentai-foundry.com/user/Afrobull/profile")
|
||||
end
|
||||
|
||||
should "get the profile url" do
|
||||
assert_equal("https://www.hentai-foundry.com/user/Afrobull", @site.profile_url)
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
assert_equal("Afrobull", @site.artist_name)
|
||||
end
|
||||
context "A hentai-foundry picture" do
|
||||
strategy_should_work(
|
||||
"https://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda",
|
||||
image_urls: ["https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png"],
|
||||
artist_name: "Afrobull",
|
||||
artist_commentary_title: "kuroeda",
|
||||
profile_url: "https://www.hentai-foundry.com/user/Afrobull",
|
||||
download_size: 1_349_887,
|
||||
tags: [["elf", "https://www.hentai-foundry.com/pictures/tagged/elf"]]
|
||||
)
|
||||
end
|
||||
|
||||
context "A deleted picture" do
|
||||
setup do
|
||||
@image = Source::Extractor.find("https://www.hentai-foundry.com/pictures/user/faustsketcher/279498")
|
||||
@artist = FactoryBot.create(:artist, name: "faustsketcher", url_string: @image.url)
|
||||
strategy_should_work(
|
||||
"https://www.hentai-foundry.com/pictures/user/faustsketcher/279498",
|
||||
image_urls: [],
|
||||
artist_name: "faustsketcher",
|
||||
profile_url: "https://www.hentai-foundry.com/user/faustsketcher",
|
||||
deleted: true
|
||||
)
|
||||
end
|
||||
|
||||
should "still find the artist name" do
|
||||
assert_equal("faustsketcher", @image.artist_name)
|
||||
assert_equal("https://www.hentai-foundry.com/user/faustsketcher", @image.profile_url)
|
||||
assert_equal([@artist], @image.artists)
|
||||
end
|
||||
context "An old image url" do
|
||||
strategy_should_work(
|
||||
"http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg",
|
||||
image_urls: ["https://pictures.hentai-foundry.com/a/AnimeFlux/219123/AnimeFlux-219123-Mobile_Suit_Equestria_rainbow_run.jpg"],
|
||||
page_url: "https://www.hentai-foundry.com/pictures/user/AnimeFlux/219123",
|
||||
profile_url: "https://www.hentai-foundry.com/user/AnimeFlux"
|
||||
)
|
||||
end
|
||||
|
||||
context "generating page urls" do
|
||||
should "work" do
|
||||
source1 = "http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg"
|
||||
source2 = "http://pictures.hentai-foundry.com/a/AnimeFlux/219123/Mobile-Suit-Equestria-rainbow-run.jpg"
|
||||
source3 = "http://www.hentai-foundry.com/pictures/user/Ganassa/457176/LOL-Swimsuit---Caitlyn-reworked-nude-ver."
|
||||
|
||||
assert_equal("https://www.hentai-foundry.com/pictures/user/AnimeFlux/219123", Source::URL.page_url(source1))
|
||||
assert_equal("https://www.hentai-foundry.com/pictures/user/AnimeFlux/219123", Source::URL.page_url(source2))
|
||||
assert_equal("https://www.hentai-foundry.com/pictures/user/Ganassa/457176", Source::URL.page_url(source3))
|
||||
assert_nil(Source::URL.page_url("https://pictures.hentai-foundry.com/a/AnimeFlux"))
|
||||
end
|
||||
context "An image url without the extension" do
|
||||
strategy_should_work(
|
||||
"http://www.hentai-foundry.com/pictures/user/Ganassa/457176/LOL-Swimsuit---Caitlyn-reworked-nude-ver.",
|
||||
image_urls: ["https://pictures.hentai-foundry.com/g/Ganassa/457176/Ganassa-457176-LOL_Swimsuit_-_Caitlyn_reworked_nude_ver..jpg"],
|
||||
page_url: "https://www.hentai-foundry.com/pictures/user/Ganassa/457176",
|
||||
profile_url: "https://www.hentai-foundry.com/user/Ganassa"
|
||||
)
|
||||
end
|
||||
|
||||
context "a post with a deeply nested commentary" do
|
||||
should "work" do
|
||||
@source = Source::Extractor.find("https://hentai-foundry.com/pictures/user/LumiNyu/867562/Mona-patreon-winner")
|
||||
assert_nothing_raised { @source.to_h }
|
||||
end
|
||||
context "A post with deeply nested commentary" do
|
||||
strategy_should_work("https://hentai-foundry.com/pictures/user/LumiNyu/867562/Mona-patreon-winner")
|
||||
end
|
||||
|
||||
should "Parse HentaiFoundry URLs correctly" do
|
||||
|
||||
@@ -2,75 +2,23 @@ require 'test_helper'
|
||||
|
||||
module Sources
|
||||
class MastodonTest < ActiveSupport::TestCase
|
||||
context "The source site for a https://pawoo.net/web/status/$id url" do
|
||||
context "For Pawoo," do
|
||||
setup do
|
||||
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
|
||||
@site = Source::Extractor.find("https://pawoo.net/web/statuses/1202176")
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
assert_equal("https://pawoo.net/@9ed00e924818", @site.profile_url)
|
||||
context "a https://pawoo.net/web/status/$id url" do
|
||||
strategy_should_work(
|
||||
"https://pawoo.net/web/statuses/1202176",
|
||||
image_urls: ["https://img.pawoo.net/media_attachments/files/000/128/953/original/4c0a06087b03343f.png"],
|
||||
profile_url: "https://pawoo.net/@9ed00e924818",
|
||||
artist_name: "9ed00e924818",
|
||||
dtext_artist_commentary_desc: "a mind forever voyaging through strange seas of thought alone"
|
||||
)
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
assert_equal("9ed00e924818", @site.artist_name)
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal(["https://img.pawoo.net/media_attachments/files/000/128/953/original/4c0a06087b03343f.png"], @site.image_urls)
|
||||
end
|
||||
|
||||
should "get the commentary" do
|
||||
desc = '<p>a mind forever voyaging through strange seas of thought alone <a href="https://pawoo.net/media/9hJzXvwxVl1CezW0ecM" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="ellipsis">pawoo.net/media/9hJzXvwxVl1Cez</span><span class="invisible">W0ecM</span></a></p>'
|
||||
assert_equal(desc, @site.artist_commentary_desc)
|
||||
end
|
||||
|
||||
should "get the dtext-ified commentary" do
|
||||
desc = 'a mind forever voyaging through strange seas of thought alone'
|
||||
assert_equal(desc, @site.dtext_artist_commentary_desc)
|
||||
end
|
||||
end
|
||||
|
||||
context "The source site for a https://pawoo.net/$user/$id url" do
|
||||
setup do
|
||||
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
|
||||
@site = Source::Extractor.find("https://pawoo.net/@evazion/19451018")
|
||||
end
|
||||
|
||||
should "get the profile" do
|
||||
profiles = %w[https://pawoo.net/@evazion https://pawoo.net/web/accounts/47806]
|
||||
assert_equal(profiles.first, @site.profile_url)
|
||||
assert_equal(profiles, @site.profile_urls)
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
assert_equal("evazion", @site.artist_name)
|
||||
end
|
||||
|
||||
should "get the image urls" do
|
||||
urls = %w[
|
||||
https://img.pawoo.net/media_attachments/files/001/297/997/original/c4272a09570757c2.png
|
||||
https://img.pawoo.net/media_attachments/files/001/298/028/original/55a6fd252778454b.mp4
|
||||
https://img.pawoo.net/media_attachments/files/001/298/081/original/2588ee9ba808f38f.webm
|
||||
https://img.pawoo.net/media_attachments/files/001/298/084/original/media.mp4
|
||||
]
|
||||
|
||||
assert_equal(urls, @site.image_urls)
|
||||
end
|
||||
|
||||
should "get the tags" do
|
||||
assert_equal(%w[foo bar baz], @site.tags.map(&:first))
|
||||
end
|
||||
|
||||
should "get the commentary" do
|
||||
desc = "<p>test post please ignore</p><p>blah blah blah</p><p>this is a test 🍕</p><p><a href=\"https://pawoo.net/tags/foo\" class=\"mention hashtag\" rel=\"tag\">#<span>foo</span></a> <a href=\"https://pawoo.net/tags/bar\" class=\"mention hashtag\" rel=\"tag\">#<span>bar</span></a> <a href=\"https://pawoo.net/tags/baz\" class=\"mention hashtag\" rel=\"tag\">#<span>baz</span></a></p>"
|
||||
|
||||
assert_nil(@site.artist_commentary_title)
|
||||
assert_equal(desc, @site.artist_commentary_desc)
|
||||
end
|
||||
|
||||
should "get the dtext-ified commentary" do
|
||||
desc = <<-DESC.strip_heredoc.chomp
|
||||
context "a https://pawoo.net/$user/$id url" do
|
||||
desc = <<~DESC.chomp
|
||||
test post please ignore
|
||||
|
||||
blah blah blah
|
||||
@@ -80,45 +28,72 @@ module Sources
|
||||
"#foo":[https://pawoo.net/tags/foo] "#bar":[https://pawoo.net/tags/bar] "#baz":[https://pawoo.net/tags/baz]
|
||||
DESC
|
||||
|
||||
assert_equal(desc, @site.dtext_artist_commentary_desc)
|
||||
strategy_should_work(
|
||||
"https://pawoo.net/@evazion/19451018",
|
||||
image_urls: %w[
|
||||
https://img.pawoo.net/media_attachments/files/001/297/997/original/c4272a09570757c2.png
|
||||
https://img.pawoo.net/media_attachments/files/001/298/028/original/55a6fd252778454b.mp4
|
||||
https://img.pawoo.net/media_attachments/files/001/298/081/original/2588ee9ba808f38f.webm
|
||||
https://img.pawoo.net/media_attachments/files/001/298/084/original/media.mp4
|
||||
],
|
||||
profile_urls: %w[https://pawoo.net/@evazion https://pawoo.net/web/accounts/47806],
|
||||
artist_name: "evazion",
|
||||
tags: %w[foo bar baz],
|
||||
dtext_artist_commentary_desc: desc
|
||||
)
|
||||
end
|
||||
|
||||
context "a https://img.pawoo.net/ url" do
|
||||
strategy_should_work(
|
||||
"https://img.pawoo.net/media_attachments/files/001/298/028/original/55a6fd252778454b.mp4",
|
||||
image_urls: ["https://img.pawoo.net/media_attachments/files/001/298/028/original/55a6fd252778454b.mp4"],
|
||||
download_size: 59_950,
|
||||
referer: "https://pawoo.net/@evazion/19451018",
|
||||
page_url: "https://pawoo.net/@evazion/19451018"
|
||||
)
|
||||
end
|
||||
|
||||
context "a deleted or invalid source" do
|
||||
strategy_should_work(
|
||||
"https://pawoo.net/@nonamethankswashere/12345678901234567890",
|
||||
profile_url: "https://pawoo.net/@nonamethankswashere",
|
||||
artist_name: "nonamethankswashere",
|
||||
deleted: true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "The source site for a https://img.pawoo.net/ url" do
|
||||
setup do
|
||||
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
|
||||
@url = "https://img.pawoo.net/media_attachments/files/001/298/028/original/55a6fd252778454b.mp4"
|
||||
@ref = "https://pawoo.net/@evazion/19451018"
|
||||
@site = Source::Extractor.find(@url, @ref)
|
||||
end
|
||||
|
||||
should "fetch the source data" do
|
||||
assert_equal("evazion", @site.artist_name)
|
||||
end
|
||||
|
||||
should "correctly get the page url" do
|
||||
assert_equal(@ref, @site.page_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "A baraag url" do
|
||||
context "For Baraag," do
|
||||
setup do
|
||||
skip "Baraag keys not set" unless Danbooru.config.baraag_client_id
|
||||
@url = "https://baraag.net/@bardbot/105732813175612920"
|
||||
@site1 = Source::Extractor.find(@url)
|
||||
|
||||
@img = "https://baraag.net/system/media_attachments/files/105/803/948/862/719/091/original/54e1cb7ca33ec449.png"
|
||||
@ref = "https://baraag.net/@Nakamura/105803949565505009"
|
||||
@site2 = Source::Extractor.find(@img, @ref)
|
||||
end
|
||||
|
||||
should "work" do
|
||||
assert_equal("https://baraag.net/@bardbot", @site1.profile_url)
|
||||
assert_equal(["https://baraag.net/system/media_attachments/files/105/732/803/241/495/700/original/556e1eb7f5ca610f.png"], @site1.image_urls)
|
||||
assert_equal("bardbot", @site1.artist_name)
|
||||
assert_equal("🍌", @site1.dtext_artist_commentary_desc)
|
||||
context "a baraag.net/$user/$id url" do
|
||||
strategy_should_work(
|
||||
"https://baraag.net/@bardbot/105732813175612920",
|
||||
image_urls: ["https://baraag.net/system/media_attachments/files/105/732/803/241/495/700/original/556e1eb7f5ca610f.png"],
|
||||
download_size: 573_353,
|
||||
profile_url: "https://baraag.net/@bardbot",
|
||||
artist_name: "bardbot",
|
||||
dtext_artist_commentary_desc: "🍌"
|
||||
)
|
||||
end
|
||||
|
||||
assert_equal([@img], @site2.image_urls)
|
||||
context "a baraag image url" do
|
||||
strategy_should_work(
|
||||
"https://baraag.net/system/media_attachments/files/105/803/948/862/719/091/original/54e1cb7ca33ec449.png",
|
||||
image_urls: ["https://baraag.net/system/media_attachments/files/105/803/948/862/719/091/original/54e1cb7ca33ec449.png"],
|
||||
download_size: 363_261
|
||||
)
|
||||
end
|
||||
|
||||
context "a deleted or invalid source" do
|
||||
strategy_should_work(
|
||||
"https://baraag.net/@nonamethankswashere/12345678901234567890",
|
||||
profile_url: "https://baraag.net/@nonamethankswashere",
|
||||
artist_name: "nonamethankswashere",
|
||||
deleted: true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -136,23 +111,6 @@ module Sources
|
||||
end
|
||||
end
|
||||
|
||||
context "A deleted or invalid source" do
|
||||
setup do
|
||||
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
|
||||
|
||||
@site1 = Source::Extractor.find("https://pawoo.net/@nantokakun/105643037682139899") # 404
|
||||
@site2 = Source::Extractor.find("https://img.pawoo.net/media_attachments/files/001/297/997/original/c4272a09570757c2.png")
|
||||
|
||||
assert_nothing_raised { @site1.to_h }
|
||||
assert_nothing_raised { @site2.to_h }
|
||||
end
|
||||
|
||||
should "still find the artist" do
|
||||
@artist = FactoryBot.create(:artist, name: "nantokakun", url_string: "https://pawoo.net/@nantokakun")
|
||||
assert_equal([@artist], @site1.artists)
|
||||
end
|
||||
end
|
||||
|
||||
should "Parse Pawoo URLs correctly" do
|
||||
assert(Source::URL.image_url?("https://img.pawoo.net/media_attachments/files/001/297/997/small/c4272a09570757c2.png"))
|
||||
assert(Source::URL.image_url?("https://pawoo.net/media/lU2uV7C1MMQSb1czwvg"))
|
||||
|
||||
@@ -2,111 +2,105 @@ require "test_helper"
|
||||
|
||||
module Sources
|
||||
class MoebooruTest < ActiveSupport::TestCase
|
||||
def assert_source_data_equals(url, referer = nil, site_name: nil, image_url: nil, page_url: nil, size: nil, tags: [], profile_url: nil, **params)
|
||||
site = Source::Extractor.find(url, referer)
|
||||
|
||||
assert_equal(site_name, site.site_name)
|
||||
assert_equal([image_url], site.image_urls)
|
||||
assert_equal(page_url, site.page_url) if page_url.present?
|
||||
assert_equal(tags.sort, site.tags.map(&:first).sort)
|
||||
assert_equal(profile_url.to_s, site.profile_url.to_s)
|
||||
assert_nothing_raised { site.to_h }
|
||||
context "For Yande.re," do
|
||||
context "a post" do
|
||||
strategy_should_work(
|
||||
"https://yande.re/post/show/482880",
|
||||
image_urls: ["https://files.yande.re/image/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880.jpg"],
|
||||
download_size: 362_554,
|
||||
tags: ["bayashiko", "journey_to_the_west", "sun_wukong"],
|
||||
page_url: "https://yande.re/post/show/482880",
|
||||
profile_url: "https://twitter.com/apononori"
|
||||
)
|
||||
end
|
||||
|
||||
context "Yande.re:" do
|
||||
context "A 'https://yande.re/jpeg/:hash/:file.jpg' jpeg sample url" do
|
||||
should "download the original file" do
|
||||
@source = "https://yande.re/jpeg/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092%20hatsune_miku%20tid%20vocaloid.jpg"
|
||||
@rewrite = "https://files.yande.re/image/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092.png"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(1_050_117, @source)
|
||||
end
|
||||
context "a https://yande.re/sample/:hash/:file.jpg" do
|
||||
strategy_should_work(
|
||||
"https://files.yande.re/sample/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880%20sample%20bayashiko%20journey_to_the_west%20sun_wukong.jpg",
|
||||
image_urls: ["https://files.yande.re/image/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880.jpg"],
|
||||
download_size: 362_554,
|
||||
tags: ["bayashiko", "journey_to_the_west", "sun_wukong"],
|
||||
page_url: "https://yande.re/post/show/482880",
|
||||
profile_url: "https://twitter.com/apononori"
|
||||
)
|
||||
end
|
||||
|
||||
context "Fetching data for an active yande.re .jpg post" do
|
||||
should "work" do
|
||||
@samp = "https://files.yande.re/sample/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880%20sample%20bayashiko%20journey_to_the_west%20sun_wukong.jpg"
|
||||
@full = "https://files.yande.re/image/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880.jpg"
|
||||
@page = "https://yande.re/post/show/482880"
|
||||
@tags = ["bayashiko", "journey_to_the_west", "sun_wukong"]
|
||||
@size = 362_554
|
||||
@profile_url = "https://twitter.com/apononori"
|
||||
@data = { site_name: "Yande.re", image_url: @full, page_url: @page, size: @size, tags: @tags, profile_url: @profile_url }
|
||||
|
||||
assert_source_data_equals(@samp, **@data)
|
||||
assert_source_data_equals(@full, **@data)
|
||||
assert_source_data_equals(@page, **@data)
|
||||
end
|
||||
context "a 'https://yande.re/jpeg/:hash/:file.jpg' jpeg sample url" do
|
||||
strategy_should_work(
|
||||
"https://yande.re/jpeg/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092%20hatsune_miku%20tid%20vocaloid.jpg",
|
||||
image_urls: ["https://files.yande.re/image/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092.png"],
|
||||
download_size: 1_050_117
|
||||
)
|
||||
end
|
||||
|
||||
context "Fetching data for a deleted yande.re .png post with the post id" do
|
||||
should "work" do
|
||||
@samp = "https://files.yande.re/sample/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018%20detexted%20misaki_kurehito%20saenai_heroine_no_sodatekata%20sawamura_spencer_eriri%20thighhighs.jpg"
|
||||
@jpeg = "https://files.yande.re/sample/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018%20detexted%20misaki_kurehito%20saenai_heroine_no_sodatekata%20sawamura_spencer_eriri%20thighhighs.jpg"
|
||||
@full = "https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018.png"
|
||||
@page = "https://yande.re/post/show/398018"
|
||||
@tags = ["misaki_kurehito", "saenai_heroine_no_sodatekata", "sawamura_spencer_eriri", "detexted", "thighhighs"]
|
||||
@size = 9_118_998
|
||||
@data = { site_name: "Yande.re", image_url: @full, page_url: @page, size: @size, tags: @tags, profile_url: nil }
|
||||
|
||||
assert_source_data_equals(@samp, **@data)
|
||||
assert_source_data_equals(@jpeg, **@data)
|
||||
assert_source_data_equals(@full, **@data)
|
||||
assert_source_data_equals(@page, **@data)
|
||||
end
|
||||
context "a deleted yande.re post with the post id" do
|
||||
strategy_should_work(
|
||||
"https://files.yande.re/sample/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018%20detexted%20misaki_kurehito%20saenai_heroine_no_sodatekata%20sawamura_spencer_eriri%20thighhighs.jpg",
|
||||
image_urls: ["https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018.png"],
|
||||
page_url: "https://yande.re/post/show/398018",
|
||||
tags: ["misaki_kurehito", "saenai_heroine_no_sodatekata", "sawamura_spencer_eriri", "detexted", "thighhighs"],
|
||||
download_size: 9_118_998
|
||||
)
|
||||
end
|
||||
|
||||
context "Fetching data for a deleted yande.re .png post without the post id" do
|
||||
should "work" do
|
||||
@samp = "https://files.yande.re/sample/fb27a7ea6c48b2ef76fe915e378b9098.jpg"
|
||||
@jpeg = "https://files.yande.re/jpeg/fb27a7ea6c48b2ef76fe915e378b9098.jpg"
|
||||
@full = "https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098.png"
|
||||
@tags = []
|
||||
@size = 9_118_998
|
||||
@data = { site_name: "Yande.re", image_url: @full, page_url: @page, size: @size, tags: @tags, profile_url: nil }
|
||||
|
||||
assert_source_data_equals(@samp, **@data)
|
||||
assert_source_data_equals(@jpeg, **@data)
|
||||
assert_source_data_equals(@full, **@data)
|
||||
end
|
||||
context "a deleted yande.re post without the post id" do
|
||||
strategy_should_work(
|
||||
"https://files.yande.re/jpeg/fb27a7ea6c48b2ef76fe915e378b9098.jpg",
|
||||
image_urls: ["https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098.png"],
|
||||
download_size: 9_118_998
|
||||
)
|
||||
end
|
||||
|
||||
context "When the referer URL is SauceNao" do
|
||||
should "ignore the referer" do
|
||||
@url = "https://yande.re/post/show/469929"
|
||||
@ref = "https://saucenao.com/"
|
||||
|
||||
assert_source_data_equals(@url, @ref,
|
||||
site_name: "Yande.re",
|
||||
image_url: "https://files.yande.re/image/36b031b266605d89aed2b62d479e64b1/yande.re%20469929.jpg",
|
||||
context "a yande.re post with a saucenao referer" do
|
||||
strategy_should_work(
|
||||
"https://yande.re/post/show/469929",
|
||||
referer: "https://saucenao.com",
|
||||
image_urls: ["https://files.yande.re/image/36b031b266605d89aed2b62d479e64b1/yande.re%20469929.jpg"],
|
||||
page_url: "https://yande.re/post/show/469929",
|
||||
tags: %w[anchovy bandages darjeeling girls_und_panzer katyusha kay_(girls_und_panzer) mika_(girls_und_panzer) nishi_kinuyo nishizumi_maho nishizumi_miho shimada_arisu uniform],
|
||||
tags: %w[anchovy bandages darjeeling girls_und_panzer katyusha kay_(girls_und_panzer) mika_(girls_und_panzer) nishi_kinuyo nishizumi_maho nishizumi_miho shimada_arisu uniform]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "For konachan.com," do
|
||||
context "a sample url" do
|
||||
strategy_should_work(
|
||||
"https://konachan.com/sample/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916%20sample.jpg",
|
||||
image_urls: ["https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png"],
|
||||
download_size: 8_167_593,
|
||||
tags: %w[anthropomorphism bed blonde_hair bow brown_eyes doll girls_frontline hara_shoutarou hoodie long_hair pantyhose scar skirt twintails ump-45_(girls_frontline) ump-9_(girls_frontline)],
|
||||
profile_url: "https://www.pixiv.net/users/22528152"
|
||||
)
|
||||
end
|
||||
|
||||
context "Konachan.com:" do
|
||||
context "Fetching data for an active konachan.com .png post" do
|
||||
should "work" do
|
||||
@samp = "https://konachan.com/sample/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916%20sample.jpg"
|
||||
@jpeg = "https://konachan.com/jpeg/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916%20anthropomorphism%20bed%20blonde_hair%20bow%20brown_eyes%20doll%20girls_frontline%20hara_shoutarou%20hoodie%20long_hair%20pantyhose%20scar%20skirt%20twintails.jpg"
|
||||
@full = "https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png"
|
||||
@page = "https://konachan.com/post/show/270916"
|
||||
@size = 8_167_593
|
||||
@tags = %w[
|
||||
anthropomorphism bed blonde_hair bow brown_eyes doll
|
||||
girls_frontline hara_shoutarou hoodie long_hair pantyhose scar skirt
|
||||
twintails ump-45_(girls_frontline) ump-9_(girls_frontline)
|
||||
]
|
||||
@profile_url = "https://www.pixiv.net/users/22528152"
|
||||
|
||||
@data = { site_name: "Konachan", image_url: @full, page_url: @page, size: @size, tags: @tags, profile_url: @profile_url }
|
||||
assert_source_data_equals(@samp, **@data)
|
||||
assert_source_data_equals(@jpeg, **@data)
|
||||
assert_source_data_equals(@full, **@data)
|
||||
assert_source_data_equals(@page, **@data)
|
||||
context "a jpeg url" do
|
||||
strategy_should_work(
|
||||
"https://konachan.com/jpeg/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916%20anthropomorphism%20bed%20blonde_hair%20bow%20brown_eyes%20doll%20girls_frontline%20hara_shoutarou%20hoodie%20long_hair%20pantyhose%20scar%20skirt%20twintails.jpg",
|
||||
image_urls: ["https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png"],
|
||||
download_size: 8_167_593,
|
||||
tags: %w[anthropomorphism bed blonde_hair bow brown_eyes doll girls_frontline hara_shoutarou hoodie long_hair pantyhose scar skirt twintails ump-45_(girls_frontline) ump-9_(girls_frontline)],
|
||||
profile_url: "https://www.pixiv.net/users/22528152"
|
||||
)
|
||||
end
|
||||
|
||||
context "a full-size image url" do
|
||||
strategy_should_work(
|
||||
"https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png",
|
||||
image_urls: ["https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png"],
|
||||
download_size: 8_167_593,
|
||||
tags: %w[anthropomorphism bed blonde_hair bow brown_eyes doll girls_frontline hara_shoutarou hoodie long_hair pantyhose scar skirt twintails ump-45_(girls_frontline) ump-9_(girls_frontline)],
|
||||
profile_url: "https://www.pixiv.net/users/22528152"
|
||||
)
|
||||
end
|
||||
|
||||
context "a post url" do
|
||||
strategy_should_work(
|
||||
"https://konachan.com/post/show/270916",
|
||||
image_urls: ["https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png"],
|
||||
download_size: 8_167_593,
|
||||
tags: %w[anthropomorphism bed blonde_hair bow brown_eyes doll girls_frontline hara_shoutarou hoodie long_hair pantyhose scar skirt twintails ump-45_(girls_frontline) ump-9_(girls_frontline)],
|
||||
profile_url: "https://www.pixiv.net/users/22528152"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,100 +2,55 @@ require 'test_helper'
|
||||
|
||||
module Sources
|
||||
class NewgroundsTest < ActiveSupport::TestCase
|
||||
context "The source for a newgrounds picture" do
|
||||
setup do
|
||||
@url = "https://www.newgrounds.com/art/view/hcnone/sephiroth"
|
||||
@image_url = "https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234"
|
||||
@image_1 = Source::Extractor.find(@url)
|
||||
@image_2 = Source::Extractor.find(@image_url)
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
assert_equal("hcnone", @image_1.artist_name)
|
||||
assert_equal("hcnone", @image_2.artist_name)
|
||||
end
|
||||
|
||||
should "get the artist commentary title" do
|
||||
assert_equal("Sephiroth", @image_1.artist_commentary_title)
|
||||
assert_equal("Sephiroth", @image_2.artist_commentary_title)
|
||||
end
|
||||
|
||||
should "get profile url" do
|
||||
assert_equal("https://hcnone.newgrounds.com", @image_1.profile_url)
|
||||
assert_equal("https://hcnone.newgrounds.com", @image_2.profile_url)
|
||||
end
|
||||
|
||||
should "get the image urls" do
|
||||
assert_equal([@image_url], @image_1.image_urls)
|
||||
assert_equal([@image_url], @image_2.image_urls)
|
||||
end
|
||||
|
||||
should "get the page url" do
|
||||
assert_equal(@url, @image_1.page_url)
|
||||
assert_equal(@url, @image_2.page_url)
|
||||
end
|
||||
|
||||
should "download an image" do
|
||||
assert_downloaded(4224, @image_1.image_urls.sole)
|
||||
assert_downloaded(4224, @image_2.image_urls.sole)
|
||||
end
|
||||
|
||||
should "get the tags" do
|
||||
tags = [
|
||||
context "A newgrounds post url" do
|
||||
strategy_should_work(
|
||||
"https://www.newgrounds.com/art/view/hcnone/sephiroth",
|
||||
image_urls: ["https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234"],
|
||||
page_url: "https://www.newgrounds.com/art/view/hcnone/sephiroth",
|
||||
download_size: 4_224,
|
||||
artist_name: "hcnone",
|
||||
profile_url: "https://hcnone.newgrounds.com",
|
||||
artist_commentary_title: "Sephiroth",
|
||||
tags: [
|
||||
%w[sephiroth https://www.newgrounds.com/search/conduct/art?match=tags&tags=sephiroth],
|
||||
%w[supersmashbros https://www.newgrounds.com/search/conduct/art?match=tags&tags=supersmashbros],
|
||||
]
|
||||
|
||||
assert_equal(tags, @image_1.tags)
|
||||
assert_equal(tags, @image_2.tags)
|
||||
)
|
||||
end
|
||||
|
||||
should "find the right artist" do
|
||||
artist_1 = create(:artist, name: "hcnone1", url_string: "https://hcnone.newgrounds.com/art")
|
||||
artist_2 = create(:artist, name: "hcnone2", url_string: "https://www.newgrounds.com/art/view/hcnone/sephiroth")
|
||||
artist_3 = create(:artist, name: "bad_artist", url_string: "https://www.newgrounds.com/art")
|
||||
|
||||
assert_equal([artist_1, artist_2], @image_1.artists)
|
||||
assert_equal([artist_1, artist_2], @image_2.artists)
|
||||
|
||||
assert_not_equal([artist_3], @image_1.artists)
|
||||
end
|
||||
context "A newgrounds image url" do
|
||||
strategy_should_work(
|
||||
"https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234",
|
||||
image_urls: ["https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234"],
|
||||
page_url: "https://www.newgrounds.com/art/view/hcnone/sephiroth",
|
||||
download_size: 4_224,
|
||||
artist_name: "hcnone",
|
||||
profile_url: "https://hcnone.newgrounds.com",
|
||||
artist_commentary_title: "Sephiroth",
|
||||
tags: [
|
||||
%w[sephiroth https://www.newgrounds.com/search/conduct/art?match=tags&tags=sephiroth],
|
||||
%w[supersmashbros https://www.newgrounds.com/search/conduct/art?match=tags&tags=supersmashbros],
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
context "A multi-image Newgrounds post" do
|
||||
should "get all the images" do
|
||||
source = Source::Extractor.find("https://www.newgrounds.com/art/view/natthelich/weaver")
|
||||
image_urls = [
|
||||
context "A multi-image post" do
|
||||
strategy_should_work(
|
||||
"https://www.newgrounds.com/art/view/natthelich/weaver",
|
||||
image_urls: [
|
||||
"https://art.ngfiles.com/images/1520000/1520217_natthelich_weaver.jpg?f1606365031",
|
||||
"https://art.ngfiles.com/comments/199000/iu_199826_7115981.jpg",
|
||||
]
|
||||
|
||||
assert_equal(image_urls, source.image_urls)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
context "A deleted or not existing picture" do
|
||||
setup do
|
||||
@fake_1 = Source::Extractor.find("https://www.newgrounds.com/art/view/ThisUser/DoesNotExist")
|
||||
@artist_1 = create(:artist, name: "thisuser", url_string: "https://thisuser.newgrounds.com")
|
||||
|
||||
@fake_2 = Source::Extractor.find("https://www.newgrounds.com/art/view/natthelich/nopicture")
|
||||
@artist_2 = create(:artist, name: "natthelich", url_string: "https://natthelich.newgrounds.com")
|
||||
|
||||
@fake_3 = Source::Extractor.find("https://www.newgrounds.com/art/view/theolebrave/sensitive-pochaco")
|
||||
@artist_3 = create(:artist, name: "taffytoad", url_string: "https://taffytoad.newgrounds.com")
|
||||
end
|
||||
|
||||
should "still find the artist name" do
|
||||
assert_equal("thisuser", @fake_1.artist_name)
|
||||
assert_equal([@artist_1], @fake_1.artists)
|
||||
assert_equal("https://thisuser.newgrounds.com", @fake_1.profile_url)
|
||||
|
||||
assert_equal("natthelich", @fake_2.artist_name)
|
||||
assert_equal([@artist_2], @fake_2.artists)
|
||||
|
||||
assert_equal([@artist_3], @fake_3.artists)
|
||||
end
|
||||
context "A deleted or non-existing post" do
|
||||
strategy_should_work(
|
||||
"https://www.newgrounds.com/art/view/natthelich/nopicture",
|
||||
deleted: true,
|
||||
profile_url: "https://natthelich.newgrounds.com",
|
||||
artist_name: "natthelich"
|
||||
)
|
||||
end
|
||||
|
||||
context "A www.newgrounds.com/dump/item URL" do
|
||||
@@ -103,23 +58,15 @@ module Sources
|
||||
"https://www.newgrounds.com/dump/item/a1f417d20f5eaef31e26ac3c4956b3d4",
|
||||
image_urls: [],
|
||||
artist_name: nil,
|
||||
profile_url: nil,
|
||||
profile_url: nil
|
||||
)
|
||||
end
|
||||
|
||||
context "A post with links to other illustrations in the commentary" do
|
||||
should "not include the links in the commentary" do
|
||||
@source = Source::Extractor.find("https://www.newgrounds.com/art/view/boxofwant/annie-hughes-1")
|
||||
|
||||
assert_equal(<<~EOS.chomp, @source.artist_commentary_desc)
|
||||
<div class="padded-top ql-body " id="author_comments"><p>Commission of Annie Hughes, the mom from The Iron Giant, for <a href="https://twitter.com/ManStawberry" target="_blank" rel="noopener noreferrer nofollow">@ManStawberry</a>.</p><p><br></p>
|
||||
</div>
|
||||
EOS
|
||||
|
||||
assert_equal(<<~EOS.chomp, @source.dtext_artist_commentary_desc)
|
||||
Commission of Annie Hughes, the mom from The Iron Giant, for "@ManStawberry":[https://twitter.com/ManStawberry].
|
||||
EOS
|
||||
end
|
||||
context "A post with links to other illustrations not belonging to the commentary" do
|
||||
strategy_should_work(
|
||||
"https://www.newgrounds.com/art/view/boxofwant/annie-hughes-1",
|
||||
dtext_artist_commentary_desc: 'Commission of Annie Hughes, the mom from The Iron Giant, for "@ManStawberry":[https://twitter.com/ManStawberry].'
|
||||
)
|
||||
end
|
||||
|
||||
should "Parse Newgrounds URLs correctly" do
|
||||
@@ -133,8 +80,8 @@ module Sources
|
||||
assert(Source::URL.page_url?("https://www.newgrounds.com/portal/view/830293"))
|
||||
|
||||
assert(Source::URL.profile_url?("https://natthelich.newgrounds.com"))
|
||||
refute(Source::URL.profile_url?("https://www.newgrounds.com"))
|
||||
refute(Source::URL.profile_url?("https://newgrounds.com"))
|
||||
assert_not(Source::URL.profile_url?("https://www.newgrounds.com"))
|
||||
assert_not(Source::URL.profile_url?("https://newgrounds.com"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,83 +2,62 @@ require 'test_helper'
|
||||
|
||||
module Sources
|
||||
class PixivSketchTest < ActiveSupport::TestCase
|
||||
context "A Pixiv Sketch source" do
|
||||
should "work for a post with a single image" do
|
||||
source = Source::Extractor.find("https://sketch.pixiv.net/items/5835314698645024323")
|
||||
|
||||
assert_equal("Pixiv Sketch", source.site_name)
|
||||
assert_equal(["https://img-sketch.pixiv.net/uploads/medium/file/9986983/8431631593768139653.jpg"], source.image_urls)
|
||||
assert_equal("https://sketch.pixiv.net/items/5835314698645024323", source.page_url)
|
||||
assert_equal("https://sketch.pixiv.net/@user_ejkv8372", source.profile_url)
|
||||
assert_equal(["https://sketch.pixiv.net/@user_ejkv8372", "https://www.pixiv.net/users/44772126"], source.profile_urls)
|
||||
assert_equal("user_ejkv8372", source.artist_name)
|
||||
assert_equal(["user_ejkv8372", "サコ"], source.other_names)
|
||||
assert_equal("🍻シャンクスとミホーク誕生日おめでとう🍻(過去絵) ", source.artist_commentary_desc)
|
||||
assert_equal([], source.tags.map(&:first))
|
||||
assert_nothing_raised { source.to_h }
|
||||
context "A Pixiv Sketch post" do
|
||||
strategy_should_work(
|
||||
"https://sketch.pixiv.net/items/5835314698645024323",
|
||||
image_urls: ["https://img-sketch.pixiv.net/uploads/medium/file/9986983/8431631593768139653.jpg"],
|
||||
page_url: "https://sketch.pixiv.net/items/5835314698645024323",
|
||||
profile_urls: ["https://sketch.pixiv.net/@user_ejkv8372", "https://www.pixiv.net/users/44772126"],
|
||||
profile_url: "https://sketch.pixiv.net/@user_ejkv8372",
|
||||
artist_name: "user_ejkv8372",
|
||||
other_names: ["user_ejkv8372", "サコ"],
|
||||
artist_commentary_desc: "🍻シャンクスとミホーク誕生日おめでとう🍻(過去絵) ",
|
||||
tags: []
|
||||
)
|
||||
end
|
||||
|
||||
should "work for an image url without a referer" do
|
||||
context "A Pixiv Sketch image with referer" do
|
||||
strategy_should_work(
|
||||
"https://img-sketch.pixiv.net/uploads/medium/file/9986983/8431631593768139653.jpg",
|
||||
referer: "https://sketch.pixiv.net/items/5835314698645024323",
|
||||
image_urls: ["https://img-sketch.pixiv.net/uploads/medium/file/9986983/8431631593768139653.jpg"],
|
||||
page_url: "https://sketch.pixiv.net/items/5835314698645024323",
|
||||
profile_urls: ["https://sketch.pixiv.net/@user_ejkv8372", "https://www.pixiv.net/users/44772126"],
|
||||
profile_url: "https://sketch.pixiv.net/@user_ejkv8372",
|
||||
artist_name: "user_ejkv8372",
|
||||
other_names: ["user_ejkv8372", "サコ"],
|
||||
artist_commentary_desc: "🍻シャンクスとミホーク誕生日おめでとう🍻(過去絵) ",
|
||||
tags: []
|
||||
)
|
||||
end
|
||||
|
||||
context "A Pixiv Sketch image without the referer" do
|
||||
# page: https://sketch.pixiv.net/items/8052785510155853613
|
||||
source = Source::Extractor.find("https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg")
|
||||
|
||||
assert_equal(["https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg"], source.image_urls)
|
||||
assert_nil(source.page_url)
|
||||
assert_nil(source.profile_url)
|
||||
assert_equal([], source.profile_urls)
|
||||
assert_nil(source.artist_name)
|
||||
assert_equal([], source.other_names)
|
||||
assert_nil(source.artist_commentary_desc)
|
||||
assert_equal([], source.tags.map(&:first))
|
||||
assert_nothing_raised { source.to_h }
|
||||
strategy_should_work(
|
||||
"https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg",
|
||||
page_url: nil,
|
||||
profile_url: nil,
|
||||
artist_name: nil,
|
||||
tags: [],
|
||||
artist_commentary_desc: nil
|
||||
)
|
||||
end
|
||||
|
||||
should "work for an image url with a referer" do
|
||||
source = Source::Extractor.find("https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg", "https://sketch.pixiv.net/items/8052785510155853613")
|
||||
|
||||
assert_equal("https://sketch.pixiv.net/items/8052785510155853613", source.page_url)
|
||||
assert_equal("https://sketch.pixiv.net/@op-one", source.profile_url)
|
||||
assert_equal(["https://sketch.pixiv.net/@op-one", "https://www.pixiv.net/users/5903369"], source.profile_urls)
|
||||
assert_equal("op-one", source.artist_name)
|
||||
assert_equal(["op-one", "俺P1号"], source.other_names)
|
||||
assert_match(/\A3月3日は「うさぎの日」らしいので/, source.artist_commentary_desc)
|
||||
assert_equal(%w[制作過程 このすば この素晴らしい世界に祝福を セナ バニー 3月3日 巨乳 黒髪巨乳 タイツ], source.tags.map(&:first))
|
||||
assert_nothing_raised { source.to_h }
|
||||
context "A NSFW post" do
|
||||
strategy_should_work(
|
||||
"https://sketch.pixiv.net/items/193462611994864256",
|
||||
image_urls: ["https://img-sketch.pixiv.net/uploads/medium/file/884876/4909517173982299587.jpg"],
|
||||
page_url: "https://sketch.pixiv.net/items/193462611994864256",
|
||||
profile_url: "https://sketch.pixiv.net/@lithla",
|
||||
artist_name: "lithla",
|
||||
other_names: ["lithla", "リリスラウダ"],
|
||||
artist_commentary_desc: "チビッコ露出プレイ ピース",
|
||||
tags: []
|
||||
)
|
||||
end
|
||||
|
||||
should "work for a NSFW post" do
|
||||
source = Source::Extractor.find("https://sketch.pixiv.net/items/193462611994864256")
|
||||
|
||||
assert_equal(["https://img-sketch.pixiv.net/uploads/medium/file/884876/4909517173982299587.jpg"], source.image_urls)
|
||||
assert_equal("https://sketch.pixiv.net/items/193462611994864256", source.page_url)
|
||||
assert_equal("https://sketch.pixiv.net/@lithla", source.profile_url)
|
||||
assert_equal(["https://sketch.pixiv.net/@lithla", "https://www.pixiv.net/users/4957"], source.profile_urls)
|
||||
assert_equal("lithla", source.artist_name)
|
||||
assert_equal(["lithla", "リリスラウダ"], source.other_names)
|
||||
assert_equal("チビッコ露出プレイ ピース", source.artist_commentary_desc)
|
||||
assert_equal([], source.tags.map(&:first))
|
||||
assert_nothing_raised { source.to_h }
|
||||
end
|
||||
|
||||
should "work for a post with a multiple images" do
|
||||
source = Source::Extractor.find("https://sketch.pixiv.net/items/8052785510155853613")
|
||||
|
||||
assert_equal(%w[
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988964/1564052114639195387.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988965/3187185972065199018.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988966/5281789458380074490.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988967/8187710652175488805.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988968/3497441770651131427.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988969/1770110164450415039.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988970/1340350233137289970.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988971/9105451079763734305.jpg
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988972/2641925439408057307.jpg
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg
|
||||
], source.image_urls)
|
||||
assert_equal("https://sketch.pixiv.net/items/8052785510155853613", source.page_url)
|
||||
assert_equal("https://sketch.pixiv.net/@op-one", source.profile_url)
|
||||
assert_equal("op-one", source.artist_name)
|
||||
assert_equal(<<~EOS.normalize_whitespace, source.artist_commentary_desc)
|
||||
context "A post with multiple images" do
|
||||
desc = <<~EOS.normalize_whitespace
|
||||
3月3日は「うさぎの日」らしいので
|
||||
|
||||
|
||||
@@ -127,8 +106,26 @@ module Sources
|
||||
#タイツ
|
||||
EOS
|
||||
|
||||
assert_equal(%w[制作過程 このすば この素晴らしい世界に祝福を セナ バニー 3月3日 巨乳 黒髪巨乳 タイツ], source.tags.map(&:first))
|
||||
assert_nothing_raised { source.to_h }
|
||||
strategy_should_work(
|
||||
"https://sketch.pixiv.net/items/8052785510155853613",
|
||||
image_urls: %w[
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988964/1564052114639195387.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988965/3187185972065199018.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988966/5281789458380074490.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988967/8187710652175488805.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988968/3497441770651131427.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988969/1770110164450415039.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988970/1340350233137289970.png
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988971/9105451079763734305.jpg
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988972/2641925439408057307.jpg
|
||||
https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg
|
||||
],
|
||||
artist_commentary_desc: desc,
|
||||
artist_name: "op-one",
|
||||
page_url: "https://sketch.pixiv.net/items/8052785510155853613",
|
||||
profile_url: "https://sketch.pixiv.net/@op-one",
|
||||
tags: %w[制作過程 このすば この素晴らしい世界に祝福を セナ バニー 3月3日 巨乳 黒髪巨乳 タイツ]
|
||||
)
|
||||
end
|
||||
|
||||
should "Parse Pixiv Sketch URLs correctly" do
|
||||
@@ -140,4 +137,3 @@ module Sources
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,105 +2,75 @@ require "test_helper"
|
||||
|
||||
module Sources
|
||||
class PlurkTest < ActiveSupport::TestCase
|
||||
context "The source for a Plurk picture" do
|
||||
setup do
|
||||
@post_url = "https://www.plurk.com/p/om6zv4"
|
||||
@adult_post_url = "https://www.plurk.com/p/omc64y"
|
||||
@image_url = "https://images.plurk.com/5wj6WD0r6y4rLN0DL3sqag.jpg"
|
||||
@profile_url = "https://www.plurk.com/redeyehare"
|
||||
@post1 = Source::Extractor.find(@post_url)
|
||||
@post2 = Source::Extractor.find(@image_url)
|
||||
@post3 = Source::Extractor.find(@profile_url)
|
||||
@post4 = Source::Extractor.find(@adult_post_url)
|
||||
context "A plurk post" do
|
||||
strategy_should_work(
|
||||
"https://www.plurk.com/p/om6zv4",
|
||||
image_urls: ["https://images.plurk.com/5wj6WD0r6y4rLN0DL3sqag.jpg"],
|
||||
download_size: 627_697,
|
||||
artist_name: "紅眼兔@姑且是個畫圖的",
|
||||
tag_name: "redeyehare",
|
||||
profile_url: "https://www.plurk.com/redeyehare",
|
||||
dtext_artist_commentary_desc: "Trick or Treat!\n很久沒畫萬聖賀圖了,畫一波大的 感覺持續復健中"
|
||||
)
|
||||
end
|
||||
|
||||
should "not raise errors" do
|
||||
assert_nothing_raised { @post1.to_h }
|
||||
assert_nothing_raised { @post2.to_h }
|
||||
assert_nothing_raised { @post3.to_h }
|
||||
assert_nothing_raised { @post4.to_h }
|
||||
end
|
||||
|
||||
should "get the artist name" do
|
||||
assert_equal("紅眼兔@姑且是個畫圖的", @post1.artist_name)
|
||||
assert_equal("redeyehare", @post1.tag_name)
|
||||
assert_equal("BOW99", @post4.tag_name)
|
||||
end
|
||||
|
||||
should "get profile url" do
|
||||
assert_equal(@profile_url, @post1.profile_url)
|
||||
end
|
||||
|
||||
should "get the image url" do
|
||||
assert_equal([@image_url], @post1.image_urls)
|
||||
assert_equal([@image_url], @post2.image_urls)
|
||||
end
|
||||
|
||||
should "get the image urls for an adult post" do
|
||||
images = %w[
|
||||
https://images.plurk.com/yfnumBJqqoQt50Em6xKwf.png
|
||||
https://images.plurk.com/5NaqqO3Yi6bQW1wKXq1Dc2.png
|
||||
https://images.plurk.com/3HzNcbMhCozHPk5YY8j9fI.png
|
||||
https://images.plurk.com/2e0duwn8BpSW9MGuUvbrim.png
|
||||
https://images.plurk.com/1OuiMDp82hYPEUn64CWFFB.png
|
||||
https://images.plurk.com/3F3KzZOabeMYkgTeseEZ0r.png
|
||||
https://images.plurk.com/7onKKTAIXkY4pASszrBys8.png
|
||||
https://images.plurk.com/6aotmjLGbtMLiI3slN7ODv.png
|
||||
https://images.plurk.com/6pzn7jE2nkj9EV7H25L0x1.png
|
||||
https://images.plurk.com/yA8egjDuhy0eNG9yxRj1d.png
|
||||
https://images.plurk.com/55tbTkH3cKTTYkZe9fu1Pv.png
|
||||
https://images.plurk.com/5z64F9uUipJ0fMJWXNGHTw.png
|
||||
https://images.plurk.com/6cwurMe6jymEu6INzmyg74.png
|
||||
https://images.plurk.com/7zyTReS8UVyCFYtU1DJRYt.png
|
||||
https://images.plurk.com/1PiRWGzaXozU15Scx1ZC4T.png
|
||||
https://images.plurk.com/2xzB5qacdLVV75GhaFifaY.png
|
||||
https://images.plurk.com/7uQENFmFNtWSKF0AAQKffr.png
|
||||
https://images.plurk.com/7ChGLokdAezvbEjPCLUr8f.png
|
||||
https://images.plurk.com/3AzjLxynamDGxNDTq4wt5x.png
|
||||
https://images.plurk.com/3SYjvKc3IBbz6ZXWeG1pY8.png
|
||||
https://images.plurk.com/7bk2kYN2fEVV0kiT5qoiuO.png
|
||||
https://images.plurk.com/6mgCwWjSqOfi0BtSg6THcZ.png
|
||||
https://images.plurk.com/3BwtMvr6S13gr96r5TLIFd.png
|
||||
https://images.plurk.com/22CPzkRM71frDR5eRMPthC.png
|
||||
https://images.plurk.com/1IFScoxA7m0FXNu6XirBwa.jpg
|
||||
https://images.plurk.com/5v1ZXQxbS7ocV4BybwbCSs.jpg
|
||||
https://images.plurk.com/4n1og7pg4KP3wRYSKpFzF7.png
|
||||
https://images.plurk.com/5gK1PyPTrVYoeZBr10lEYu.png
|
||||
https://images.plurk.com/3m8YZS3D9vaAH8Lw1LDTix.png
|
||||
https://images.plurk.com/3oy7joPrEFm0Wlo7NplXOl.png
|
||||
https://images.plurk.com/2IBA93ghmCJCJT72mQyLUK.png
|
||||
https://images.plurk.com/16jqEhVqtuLJwnRjpIDRCr.png
|
||||
https://images.plurk.com/7cKzaSigAvKc6DKNxeGmnH.png
|
||||
https://images.plurk.com/ypfkOMsC24hIPGSEWjJ8A.png
|
||||
https://images.plurk.com/5qW11yr06e9u3t5Zt9Jxmm.png
|
||||
https://images.plurk.com/4H5st1xsFDSFgLd7gNXgD8.png
|
||||
https://images.plurk.com/4nf49mWygwQyrYriZ453Qx.png
|
||||
https://images.plurk.com/2Y0TXcYZkni94j7yxxosV9.png
|
||||
https://images.plurk.com/5ih71C9XNJDq88wzKbBdNp.png
|
||||
https://images.plurk.com/UmoZjSHx0Y4NYa3mgKffU.png
|
||||
https://images.plurk.com/4IHGG5mQNw95vqClFEBoOM.png
|
||||
https://images.plurk.com/5J3bRPjGBZV8fDxo7cTwGs.png
|
||||
https://images.plurk.com/3uAjR5oBfe4d6MFThFQ0Gt.png
|
||||
https://images.plurk.com/3fFJ8RN3HkmfcuUdn7OpnQ.png
|
||||
https://images.plurk.com/sxkaWnhmDrCSsUEg6Kn9Y.png
|
||||
https://images.plurk.com/1f3W8JnHlwpt3OlT4ZJhiu.gif
|
||||
https://images.plurk.com/5lNGKqPCf6opXu21f5DdbU.gif
|
||||
context "An adult plurk post" do
|
||||
strategy_should_work(
|
||||
"https://www.plurk.com/p/omc64y",
|
||||
profile_url: "https://www.plurk.com/BOW99",
|
||||
artist_name: "BOW🔞",
|
||||
tag_name: "BOW99",
|
||||
dtext_artist_commentary_desc: "[十月號]",
|
||||
image_urls: [
|
||||
"https://images.plurk.com/yfnumBJqqoQt50Em6xKwf.png",
|
||||
"https://images.plurk.com/5NaqqO3Yi6bQW1wKXq1Dc2.png",
|
||||
"https://images.plurk.com/3HzNcbMhCozHPk5YY8j9fI.png",
|
||||
"https://images.plurk.com/2e0duwn8BpSW9MGuUvbrim.png",
|
||||
"https://images.plurk.com/1OuiMDp82hYPEUn64CWFFB.png",
|
||||
"https://images.plurk.com/3F3KzZOabeMYkgTeseEZ0r.png",
|
||||
"https://images.plurk.com/7onKKTAIXkY4pASszrBys8.png",
|
||||
"https://images.plurk.com/6aotmjLGbtMLiI3slN7ODv.png",
|
||||
"https://images.plurk.com/6pzn7jE2nkj9EV7H25L0x1.png",
|
||||
"https://images.plurk.com/yA8egjDuhy0eNG9yxRj1d.png",
|
||||
"https://images.plurk.com/55tbTkH3cKTTYkZe9fu1Pv.png",
|
||||
"https://images.plurk.com/5z64F9uUipJ0fMJWXNGHTw.png",
|
||||
"https://images.plurk.com/6cwurMe6jymEu6INzmyg74.png",
|
||||
"https://images.plurk.com/7zyTReS8UVyCFYtU1DJRYt.png",
|
||||
"https://images.plurk.com/1PiRWGzaXozU15Scx1ZC4T.png",
|
||||
"https://images.plurk.com/2xzB5qacdLVV75GhaFifaY.png",
|
||||
"https://images.plurk.com/7uQENFmFNtWSKF0AAQKffr.png",
|
||||
"https://images.plurk.com/7ChGLokdAezvbEjPCLUr8f.png",
|
||||
"https://images.plurk.com/3AzjLxynamDGxNDTq4wt5x.png",
|
||||
"https://images.plurk.com/3SYjvKc3IBbz6ZXWeG1pY8.png",
|
||||
"https://images.plurk.com/7bk2kYN2fEVV0kiT5qoiuO.png",
|
||||
"https://images.plurk.com/6mgCwWjSqOfi0BtSg6THcZ.png",
|
||||
"https://images.plurk.com/3BwtMvr6S13gr96r5TLIFd.png",
|
||||
"https://images.plurk.com/22CPzkRM71frDR5eRMPthC.png",
|
||||
"https://images.plurk.com/1IFScoxA7m0FXNu6XirBwa.jpg",
|
||||
"https://images.plurk.com/5v1ZXQxbS7ocV4BybwbCSs.jpg",
|
||||
"https://images.plurk.com/4n1og7pg4KP3wRYSKpFzF7.png",
|
||||
"https://images.plurk.com/5gK1PyPTrVYoeZBr10lEYu.png",
|
||||
"https://images.plurk.com/3m8YZS3D9vaAH8Lw1LDTix.png",
|
||||
"https://images.plurk.com/3oy7joPrEFm0Wlo7NplXOl.png",
|
||||
"https://images.plurk.com/2IBA93ghmCJCJT72mQyLUK.png",
|
||||
"https://images.plurk.com/16jqEhVqtuLJwnRjpIDRCr.png",
|
||||
"https://images.plurk.com/7cKzaSigAvKc6DKNxeGmnH.png",
|
||||
"https://images.plurk.com/ypfkOMsC24hIPGSEWjJ8A.png",
|
||||
"https://images.plurk.com/5qW11yr06e9u3t5Zt9Jxmm.png",
|
||||
"https://images.plurk.com/4H5st1xsFDSFgLd7gNXgD8.png",
|
||||
"https://images.plurk.com/4nf49mWygwQyrYriZ453Qx.png",
|
||||
"https://images.plurk.com/2Y0TXcYZkni94j7yxxosV9.png",
|
||||
"https://images.plurk.com/5ih71C9XNJDq88wzKbBdNp.png",
|
||||
"https://images.plurk.com/UmoZjSHx0Y4NYa3mgKffU.png",
|
||||
"https://images.plurk.com/4IHGG5mQNw95vqClFEBoOM.png",
|
||||
"https://images.plurk.com/5J3bRPjGBZV8fDxo7cTwGs.png",
|
||||
"https://images.plurk.com/3uAjR5oBfe4d6MFThFQ0Gt.png",
|
||||
"https://images.plurk.com/3fFJ8RN3HkmfcuUdn7OpnQ.png",
|
||||
"https://images.plurk.com/sxkaWnhmDrCSsUEg6Kn9Y.png",
|
||||
"https://images.plurk.com/1f3W8JnHlwpt3OlT4ZJhiu.gif",
|
||||
"https://images.plurk.com/5lNGKqPCf6opXu21f5DdbU.gif",
|
||||
]
|
||||
|
||||
assert_equal(images, @post4.image_urls)
|
||||
end
|
||||
|
||||
should "download an image" do
|
||||
assert_downloaded(627_697, @post1.image_urls.sole)
|
||||
assert_downloaded(627_697, @post2.image_urls.sole)
|
||||
end
|
||||
|
||||
should "find the correct artist" do
|
||||
@artist = FactoryBot.create(:artist, name: "redeyehare", url_string: @profile_url)
|
||||
assert_equal([@artist], @post1.artists)
|
||||
@adult_artist = FactoryBot.create(:artist, name: "bow", url_string: "https://www.plurk.com/BOW99")
|
||||
assert_equal([@adult_artist], @post4.artists)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
should "Parse Plurk URLs correctly" do
|
||||
|
||||
@@ -7,48 +7,39 @@ module Sources
|
||||
skip "DeviantArt API keys not set" unless Danbooru.config.deviantart_client_id.present?
|
||||
end
|
||||
|
||||
context "A https://sta.sh/:id page url" do
|
||||
should "work" do
|
||||
@site = Source::Extractor.find("https://sta.sh/0wxs31o7nn2")
|
||||
|
||||
assert_equal("noizave", @site.artist_name)
|
||||
assert_equal("https://www.deviantart.com/noizave", @site.profile_url)
|
||||
|
||||
assert_equal("A pepe", @site.artist_commentary_title)
|
||||
assert_equal("This is a test.", @site.artist_commentary_desc)
|
||||
|
||||
assert_equal("https://sta.sh/0wxs31o7nn2", @site.page_url)
|
||||
assert_match("https://wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dcmga0s-a345a815-2436-4ab5-8941-492011e1bff6.png", @site.image_urls.sole)
|
||||
end
|
||||
context "A https://sta.sh/:id url" do
|
||||
strategy_should_work(
|
||||
"https://sta.sh/0wxs31o7nn2",
|
||||
image_urls: ["https://wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dcmga0s-a345a815-2436-4ab5-8941-492011e1bff6.png"],
|
||||
page_url: "https://sta.sh/0wxs31o7nn2",
|
||||
artist_name: "noizave",
|
||||
profile_url: "https://www.deviantart.com/noizave",
|
||||
artist_commentary_title: "A pepe",
|
||||
artist_commentary_desc: "This is a test."
|
||||
)
|
||||
end
|
||||
|
||||
context "A https://orig00.deviantart.net/* image url" do
|
||||
context "with a https://sta.sh/:id referer" do
|
||||
should "work" do
|
||||
@site = Source::Extractor.find("https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png", "https://sta.sh/0wxs31o7nn2")
|
||||
|
||||
assert_equal("noizave", @site.artist_name)
|
||||
assert_equal("https://www.deviantart.com/noizave", @site.profile_url)
|
||||
|
||||
assert_equal("A pepe", @site.artist_commentary_title)
|
||||
assert_equal("This is a test.", @site.artist_commentary_desc)
|
||||
|
||||
assert_equal("https://sta.sh/0wxs31o7nn2", @site.page_url)
|
||||
assert_match("https://wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dcmga0s-a345a815-2436-4ab5-8941-492011e1bff6.png", @site.image_urls.sole)
|
||||
end
|
||||
context "A https://orig00.deviantart.net/* image url with a https://sta.sh/:id referer" do
|
||||
strategy_should_work(
|
||||
"https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png",
|
||||
image_urls: [" https://wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dcmga0s-a345a815-2436-4ab5-8941-492011e1bff6.png"],
|
||||
referer: "https://sta.sh/0wxs31o7nn2",
|
||||
page_url: "https://sta.sh/0wxs31o7nn2",
|
||||
artist_name: "noizave",
|
||||
profile_url: "https://www.deviantart.com/noizave",
|
||||
artist_commentary_title: "A pepe",
|
||||
artist_commentary_desc: "This is a test."
|
||||
)
|
||||
end
|
||||
|
||||
context "without a referer" do
|
||||
should "use the base deviantart strategy" do
|
||||
@site = Source::Extractor.find("https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png")
|
||||
|
||||
context "A https://orig00.deviantart.net/* image url without the referer" do
|
||||
strategy_should_work(
|
||||
"https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png",
|
||||
# if all we have is the image url, then we can't tell that this is really a sta.sh image.
|
||||
assert_equal("Deviant Art", @site.site_name)
|
||||
|
||||
site_name: "Deviant Art",
|
||||
# this is the wrong page, but there's no way to know the correct sta.sh page without the referer.
|
||||
assert_equal("https://www.deviantart.com/noizave/art/A-Pepe-763305148", @site.page_url)
|
||||
end
|
||||
end
|
||||
page_url: "https://www.deviantart.com/noizave/art/A-Pepe-763305148"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user