Merge pull request #5285 from nonamethanks/tests

Rewrite the tests for various source strategies
This commit is contained in:
N. Oname
2022-10-23 18:05:54 +02:00
committed by GitHub
12 changed files with 610 additions and 900 deletions

View File

@@ -15,7 +15,7 @@ class MastodonApiClient
def json def json
return {} if id.blank? || access_token.blank? return {} if id.blank? || access_token.blank?
JSON.parse(access_token.get("/api/v1/statuses/#{id}").body) JSON.parse(access_token.get("/api/v1/statuses/#{id}").body)
rescue rescue JSON::ParserError
{} {}
end end

View File

@@ -48,7 +48,7 @@ class Source::Extractor
def tags def tags
api_response[:tags].to_a.map do |tag| 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
end end
@@ -94,7 +94,7 @@ class Source::Extractor
image_sizes = %w[original 4k large medium small] image_sizes = %w[original 4k large medium small]
urls = image_sizes.map { |size| parsed_url.full_image_url(size) } 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 chosen_url || url
end end
end end

View File

@@ -52,7 +52,7 @@ class Source::Extractor
end end
def artist_name def artist_name
api_response.account_name api_response.account_name || artist_name_from_url
end end
def artist_name_from_url def artist_name_from_url
@@ -60,7 +60,7 @@ class Source::Extractor
end end
def other_names def other_names
[api_response.display_name] [api_response.display_name].compact
end end
def account_id def account_id

View File

@@ -2,35 +2,17 @@ require 'test_helper'
module Sources module Sources
class ArtStationTest < ActiveSupport::TestCase class ArtStationTest < ActiveSupport::TestCase
context "The source site for an art station artwork page" do context "An ArtStation /artwork/:id URL" do
setup do strategy_should_work(
@site = Source::Extractor.find("https://www.artstation.com/artwork/04XA4") "https://www.artstation.com/artwork/04XA4",
end 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",
should "get the image url" do profile_url: "https://www.artstation.com/jeyrain",
assert_equal(["https://cdn.artstation.com/p/assets/images/images/000/705/368/4k/jey-rain-one1.jpg?1443931773"], @site.image_urls) artist_name: "jeyrain",
end tags: [],
artist_commentary_title: "pink",
should "get the page url" do dtext_artist_commentary_desc: ""
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
end end
context "An ArtStation /projects/ URL" do context "An ArtStation /projects/ URL" do
@@ -43,94 +25,56 @@ module Sources
tags: %w[gantz Reika], tags: %w[gantz Reika],
artist_commentary_title: "Reika ", artist_commentary_title: "Reika ",
dtext_artist_commentary_desc: "From Gantz.", dtext_artist_commentary_desc: "From Gantz.",
download_size: 210_899, download_size: 210_899
) )
end end
context "The source site for a www.artstation.com/artwork/$slug page" do context "An ArtStation /artwork/$slug page" do
setup do strategy_should_work(
@site = Source::Extractor.find("https://www.artstation.com/artwork/cody-from-sf") "https://www.artstation.com/artwork/cody-from-sf",
end 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"]
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)
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
end end
context "The source site for a http://cdn.artstation.com/p/assets/... url" do context "A http://cdn.artstation.com/p/assets/... url" do
setup do strategy_should_work(
@url = "https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg" "https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg",
@ref = "https://www.artstation.com/artwork/4BWW2" image_urls: ["https://cdn.artstation.com/p/assets/images/images/006/029/978/4k/amama-l-z.jpg"],
end page_url: nil,
profile_url: nil
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
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 end
context "A 4k asset url" do context "A http://cdn.artstation.com/p/assets/... url with referrer" do
context "without a referer" do strategy_should_work(
should "work" do "https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg",
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") 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",
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) page_url: "https://amama.artstation.com/projects/4BWW2",
assert_nothing_raised { site.to_h } profile_url: "https://www.artstation.com/amama",
end artist_name: "amama"
end )
end end
context "A cover url" do context "An ArtStation cover url" do
should "work" do strategy_should_work(
url = "https://cdna.artstation.com/p/assets/covers/images/007/262/828/large/monica-kyrie-1.jpg?1504865060" "https://cdna.artstation.com/p/assets/covers/images/007/262/828/large/monica-kyrie-1.jpg?1504865060",
site = Source::Extractor.find(url) image_urls: ["https://cdn.artstation.com/p/assets/covers/images/007/262/828/original/monica-kyrie-1.jpg?1504865060"]
)
assert_equal(["https://cdn.artstation.com/p/assets/covers/images/007/262/828/original/monica-kyrie-1.jpg?1504865060"], site.image_urls)
end
end end
context "The source site for an ArtStation gallery" do context "An ArtStation post with images and youtube links" do
setup do strategy_should_work(
@site = Source::Extractor.find("https://www.artstation.com/artwork/BDxrA") "https://www.artstation.com/artwork/BDxrA",
end image_urls: ["https://cdn.artstation.com/p/assets/images/images/006/037/253/4k/astri-lohne-sjursen-eva.jpg?1495573664"]
)
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 end
context "A work that includes video clips" do context "An ArtStation post with images and videos" do
should_eventually "include the video clips in the image urls" do strategy_should_work( # XXX Broken by Cloudflare captcha
@source = Source::Extractor.find("https://www.artstation.com/artwork/0nP1e8") "https://www.artstation.com/artwork/0nP1e8",
image_urls: %w[
assert_equal(%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/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/435/4k/yusuf-umar-1.jpg?1630425420
https://cdn.artstation.com/p/assets/images/images/040/979/470/4k/yusuf-umar-2.jpg?1630425483 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.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/622/workout.mp4
https://cdn-animation.artstation.com/p/video_sources/000/466/623/workout-clay.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
end end
context "A work that has been deleted" do context "An ArtStation video url" do
should "work" do strategy_should_work(
url = "https://fiship.artstation.com/projects/x8n8XT" "https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4",
site = Source::Extractor.find(url) image_urls: ["https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4"]
)
end
assert_equal("fiship", site.artist_name) context "A deleted ArtStation url" do
assert_equal("https://www.artstation.com/fiship", site.profile_url) strategy_should_work(
assert_equal(url, site.page_url) "https://fiship.artstation.com/projects/x8n8XT",
assert_equal([], site.image_urls) deleted: true,
assert_nothing_raised { site.to_h } image_urls: [],
end artist_name: "fiship",
profile_url: "https://www.artstation.com/fiship",
page_url: "https://fiship.artstation.com/projects/x8n8XT"
)
end end
context "A /small/ ArtStation image URL" do context "A /small/ ArtStation image URL" do
strategy_should_work( strategy_should_work(
"https://cdnb3.artstation.com/p/assets/images/images/003/716/071/small/aoi-ogata-hate-city.jpg?1476754974", "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"], 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 end
@@ -175,7 +118,7 @@ module Sources
strategy_should_work( strategy_should_work(
"https://cdnb.artstation.com/p/assets/images/images/003/716/071/large/aoi-ogata-hate-city.jpg?1476754974", "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"], 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 end
@@ -183,18 +126,22 @@ module Sources
strategy_should_work( strategy_should_work(
"https://cdna.artstation.com/p/assets/images/images/004/730/278/large/mendel-oh-dragonll.jpg", "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"], 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 end
should "work for artists with underscores in their name" do context "An ArtStation url with underscores in the artist name" do
site = Source::Extractor.find("https://hosi_na.artstation.com/projects/3oEk3B") strategy_should_work(
assert_equal("hosi_na", site.artist_name) "https://hosi_na.artstation.com/projects/3oEk3B",
artist_name: "hosi_na"
)
end end
should "work for artists with dashes in their name" do context "An ArtStation url with dashes in the artist name" do
site = Source::Extractor.find("https://sa-dui.artstation.com/projects/DVERn") strategy_should_work(
assert_equal("sa-dui", site.artist_name) "https://sa-dui.artstation.com/projects/DVERn",
artist_name: "sa-dui"
)
end end
should "Parse ArtStation URLs correctly" do 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://artstation.com/artist/sa-dui"))
assert(Source::URL.profile_url?("https://anubis1982918.artstation.com")) assert(Source::URL.profile_url?("https://anubis1982918.artstation.com"))
refute(Source::URL.profile_url?("https://anubis1982918.artstation.com/projects/qPVGP")) assert_not(Source::URL.profile_url?("https://anubis1982918.artstation.com/projects/qPVGP"))
refute(Source::URL.profile_url?("https://www.artstation.com")) assert_not(Source::URL.profile_url?("https://www.artstation.com"))
refute(Source::URL.profile_url?("https://artstation.com")) assert_not(Source::URL.profile_url?("https://artstation.com"))
end end
end end
end end

View File

@@ -3,145 +3,91 @@ require 'test_helper'
module Sources module Sources
class FanboxTest < ActiveSupport::TestCase class FanboxTest < ActiveSupport::TestCase
context "A free Pixiv Fanbox post" do context "A free Pixiv Fanbox post" do
setup do strategy_should_work(
@post1 = Source::Extractor.find("https://yanmi0308.fanbox.cc/posts/1141325") "https://yanmi0308.fanbox.cc/posts/1141325",
@post2 = Source::Extractor.find("https://chanxco.fanbox.cc/posts/209386") image_urls: %w[
@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[
https://downloads.fanbox.cc/images/post/1141325/q7GaJ0A9J5Uz8kvEAUizHJoN.png 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/LMJz0sAig5h9D3rPZGCEGniZ.png
https://downloads.fanbox.cc/images/post/1141325/dRSz380Uf3N8s4pT2ADEXBco.png https://downloads.fanbox.cc/images/post/1141325/dRSz380Uf3N8s4pT2ADEXBco.png
https://downloads.fanbox.cc/images/post/1141325/h48L2mbm39qqNUB1abLAvzvg.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) context "A free Pixiv Fanbox post with embedded pics" do
images2 = %w[ 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/Q8rZ0iMHpcmJDACEzNGjTj9E.jpeg
https://downloads.fanbox.cc/images/post/209386/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg https://downloads.fanbox.cc/images/post/209386/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg
https://downloads.fanbox.cc/images/post/209386/AGGWF0JxytFcNL2ybPKBaqp7.jpeg https://downloads.fanbox.cc/images/post/209386/AGGWF0JxytFcNL2ybPKBaqp7.jpeg
] ],
assert_equal(images2, @post2.image_urls) artist_commentary_title: "水着BBちゃんアラフィフライダーさん",
end 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\nFGO\n",
page_url: "https://chanxco.fanbox.cc/posts/209386",
should "get the commentary" do profile_url: "https://chanxco.fanbox.cc",
# Normal commentary download_size: 245_678,
assert_equal("栗山やんみ(デザイン)", @post1.artist_commentary_title) artist_name: "chanxco",
display_name: "CHANxCO"
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\nFGO\n"
assert_equal(body2, @post2.artist_commentary_desc)
assert_equal(body2, @post3.artist_commentary_desc)
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 end
context "an age-restricted fanbox post" do context "A Pixiv Fanbox sample" do
should "work" do strategy_should_work(
@source = Source::Extractor.find("https://mfr.fanbox.cc/posts/1306390") "https://downloads.fanbox.cc/images/post/209386/w/1200/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg",
image_urls: ["https://downloads.fanbox.cc/images/post/209386/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg"],
assert_nothing_raised { @source.to_h } artist_commentary_title: "水着BBちゃんアラフィフライダーさん",
assert_equal("mfr", @source.artist_name) 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\nFGO\n",
assert_equal(["https://downloads.fanbox.cc/images/post/1306390/VOXblkyvltL5fRhMoR7RdSkk.png"], @source.image_urls) page_url: "https://chanxco.fanbox.cc/posts/209386",
end profile_url: "https://chanxco.fanbox.cc",
download_size: 320_056,
artist_name: "chanxco",
display_name: "CHANxCO"
)
end end
context "A link in the old format" do context "An age-restricted Fanbox post" do
should "still work" do strategy_should_work(
post = Source::Extractor.find("https://www.pixiv.net/fanbox/creator/1566167/post/39714") "https://mfr.fanbox.cc/posts/1306390",
assert_nothing_raised { post.to_h } image_urls: ["https://downloads.fanbox.cc/images/post/1306390/VOXblkyvltL5fRhMoR7RdSkk.png"],
assert_equal("https://omu001.fanbox.cc", post.profile_url) artist_name: "mfr",
assert_equal("https://omu001.fanbox.cc/posts/39714", post.page_url) artist_commentary_desc: "これからセックスしまーす♪と言ってるシーン(・ω・`)\nhttps://downloads.fanbox.cc/images/post/1306390/VOXblkyvltL5fRhMoR7RdSkk.png\n※海苔強化して再アップしました( 'A`;)\n",
artist = FactoryBot.create(:artist, name: "omu", url_string: "https://omu001.fanbox.cc") profile_url: "https://mfr.fanbox.cc"
assert_equal([artist], post.artists) )
end
end end
context "A cover image" do context "A cover image" do
should "still work" do strategy_should_work(
post = Source::Extractor.find("https://pixiv.pximg.net/c/1620x580_90_a2_g5/fanbox/public/images/creator/1566167/cover/QqxYtuWdy4XWQx1ZLIqr4wvA.jpeg") "https://pixiv.pximg.net/c/1620x580_90_a2_g5/fanbox/public/images/creator/1566167/cover/QqxYtuWdy4XWQx1ZLIqr4wvA.jpeg",
assert_nothing_raised { post.to_h } download_size: 750_484,
assert_downloaded(750_484, post.image_urls.sole) profile_url: "https://omu001.fanbox.cc"
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
end end
context "A dead profile picture from the old domain" do context "A post in the old pixiv format" do
should "still find the artist" do strategy_should_work(
post = Source::Extractor.find("https://pixiv.pximg.net/c/400x400_90_a2_g5/fanbox/public/images/creator/1566167/profile/Ix6bnJmTaOAFZhXHLbWyIY1e.jpeg") "https://www.pixiv.net/fanbox/creator/1566167/post/39714",
assert_equal("https://omu001.fanbox.cc", post.profile_url) page_url: "https://omu001.fanbox.cc/posts/39714",
artist = FactoryBot.create(:artist, name: "omu", url_string: "https://omu001.fanbox.cc") profile_url: "https://omu001.fanbox.cc"
assert_equal([artist], post.artists) )
end
end end
context "A deleted /fanbox/creator/:id profile url" do context "A dead profile picture in the old pixiv format" do
should "not raise an exception" do strategy_should_work(
source = Source::Extractor.find("https://www.pixiv.net/fanbox/creator/40684196") "https://pixiv.pximg.net/c/400x400_90_a2_g5/fanbox/public/images/creator/29999491/profile/Ew6fOhLGPvmUcwU6FyH8JAMX.jpeg",
profile_url: "https://deaver0211.fanbox.cc"
assert_equal("https://www.pixiv.net/fanbox/creator/40684196", source.profile_url) )
assert_nothing_raised { source.to_h }
end
end end
should "Parse Fanbox URLs correctly" do 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/creator/1566167"))
assert(Source::URL.profile_url?("https://www.pixiv.net/fanbox/member.php?user_id=3410642")) assert(Source::URL.profile_url?("https://www.pixiv.net/fanbox/member.php?user_id=3410642"))
assert(Source::URL.profile_url?("https://omu001.fanbox.cc")) assert(Source::URL.profile_url?("https://omu001.fanbox.cc"))
refute(Source::URL.profile_url?("https://www.fanbox.cc")) assert_not(Source::URL.profile_url?("https://www.fanbox.cc"))
refute(Source::URL.profile_url?("https://fanbox.cc")) assert_not(Source::URL.profile_url?("https://fanbox.cc"))
end end
end end
end end

View File

@@ -2,99 +2,60 @@ require 'test_helper'
module Sources module Sources
class HentaiFoundryTest < ActiveSupport::TestCase class HentaiFoundryTest < ActiveSupport::TestCase
context "The source for a hentai foundry picture" do context "A hentai-foundry post" do
setup do strategy_should_work(
@image_1 = Source::Extractor.find("https://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda") "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") image_urls: ["https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png"],
end artist_name: "Afrobull",
artist_commentary_title: "kuroeda",
should "get the illustration id" do profile_url: "https://www.hentai-foundry.com/user/Afrobull",
assert_equal("795025", @image_1.illust_id) download_size: 1_349_887,
assert_equal("795025", @image_2.illust_id) tags: [["elf", "https://www.hentai-foundry.com/pictures/tagged/elf"]]
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 end
context "An artist profile url" do context "A hentai-foundry picture" do
setup do strategy_should_work(
@site = Source::Extractor.find("https://www.hentai-foundry.com/user/Afrobull/profile") "https://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda",
end image_urls: ["https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png"],
artist_name: "Afrobull",
should "get the profile url" do artist_commentary_title: "kuroeda",
assert_equal("https://www.hentai-foundry.com/user/Afrobull", @site.profile_url) profile_url: "https://www.hentai-foundry.com/user/Afrobull",
end download_size: 1_349_887,
tags: [["elf", "https://www.hentai-foundry.com/pictures/tagged/elf"]]
should "get the artist name" do )
assert_equal("Afrobull", @site.artist_name)
end
end end
context "A deleted picture" do context "A deleted picture" do
setup do strategy_should_work(
@image = Source::Extractor.find("https://www.hentai-foundry.com/pictures/user/faustsketcher/279498") "https://www.hentai-foundry.com/pictures/user/faustsketcher/279498",
@artist = FactoryBot.create(:artist, name: "faustsketcher", url_string: @image.url) image_urls: [],
end artist_name: "faustsketcher",
profile_url: "https://www.hentai-foundry.com/user/faustsketcher",
should "still find the artist name" do deleted: true
assert_equal("faustsketcher", @image.artist_name) )
assert_equal("https://www.hentai-foundry.com/user/faustsketcher", @image.profile_url)
assert_equal([@artist], @image.artists)
end
end end
context "generating page urls" do context "An old image url" do
should "work" do strategy_should_work(
source1 = "http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg" "http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg",
source2 = "http://pictures.hentai-foundry.com/a/AnimeFlux/219123/Mobile-Suit-Equestria-rainbow-run.jpg" image_urls: ["https://pictures.hentai-foundry.com/a/AnimeFlux/219123/AnimeFlux-219123-Mobile_Suit_Equestria_rainbow_run.jpg"],
source3 = "http://www.hentai-foundry.com/pictures/user/Ganassa/457176/LOL-Swimsuit---Caitlyn-reworked-nude-ver." page_url: "https://www.hentai-foundry.com/pictures/user/AnimeFlux/219123",
profile_url: "https://www.hentai-foundry.com/user/AnimeFlux"
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
end end
context "a post with a deeply nested commentary" do context "An image url without the extension" do
should "work" do strategy_should_work(
@source = Source::Extractor.find("https://hentai-foundry.com/pictures/user/LumiNyu/867562/Mona-patreon-winner") "http://www.hentai-foundry.com/pictures/user/Ganassa/457176/LOL-Swimsuit---Caitlyn-reworked-nude-ver.",
assert_nothing_raised { @source.to_h } image_urls: ["https://pictures.hentai-foundry.com/g/Ganassa/457176/Ganassa-457176-LOL_Swimsuit_-_Caitlyn_reworked_nude_ver..jpg"],
end 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 deeply nested commentary" do
strategy_should_work("https://hentai-foundry.com/pictures/user/LumiNyu/867562/Mona-patreon-winner")
end end
should "Parse HentaiFoundry URLs correctly" do should "Parse HentaiFoundry URLs correctly" do

View File

@@ -2,75 +2,23 @@ require 'test_helper'
module Sources module Sources
class MastodonTest < ActiveSupport::TestCase class MastodonTest < ActiveSupport::TestCase
context "The source site for a https://pawoo.net/web/status/$id url" do context "For Pawoo," do
setup do setup do
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
@site = Source::Extractor.find("https://pawoo.net/web/statuses/1202176")
end end
should "get the profile" do context "a https://pawoo.net/web/status/$id url" do
assert_equal("https://pawoo.net/@9ed00e924818", @site.profile_url) 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 end
should "get the artist name" do context "a https://pawoo.net/$user/$id url" do
assert_equal("9ed00e924818", @site.artist_name) desc = <<~DESC.chomp
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
test post please ignore test post please ignore
blah blah blah 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] "#foo":[https://pawoo.net/tags/foo] "#bar":[https://pawoo.net/tags/bar] "#baz":[https://pawoo.net/tags/baz]
DESC 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
end end
context "The source site for a https://img.pawoo.net/ url" do context "For Baraag," 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
setup do setup do
skip "Baraag keys not set" unless Danbooru.config.baraag_client_id 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 end
should "work" do context "a baraag.net/$user/$id url" do
assert_equal("https://baraag.net/@bardbot", @site1.profile_url) strategy_should_work(
assert_equal(["https://baraag.net/system/media_attachments/files/105/732/803/241/495/700/original/556e1eb7f5ca610f.png"], @site1.image_urls) "https://baraag.net/@bardbot/105732813175612920",
assert_equal("bardbot", @site1.artist_name) image_urls: ["https://baraag.net/system/media_attachments/files/105/732/803/241/495/700/original/556e1eb7f5ca610f.png"],
assert_equal("🍌", @site1.dtext_artist_commentary_desc) 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
end end
@@ -136,23 +111,6 @@ module Sources
end end
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 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://img.pawoo.net/media_attachments/files/001/297/997/small/c4272a09570757c2.png"))
assert(Source::URL.image_url?("https://pawoo.net/media/lU2uV7C1MMQSb1czwvg")) assert(Source::URL.image_url?("https://pawoo.net/media/lU2uV7C1MMQSb1czwvg"))

View File

@@ -2,111 +2,105 @@ require "test_helper"
module Sources module Sources
class MoebooruTest < ActiveSupport::TestCase 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) context "For Yande.re," do
site = Source::Extractor.find(url, referer) context "a post" do
strategy_should_work(
assert_equal(site_name, site.site_name) "https://yande.re/post/show/482880",
assert_equal([image_url], site.image_urls) image_urls: ["https://files.yande.re/image/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880.jpg"],
assert_equal(page_url, site.page_url) if page_url.present? download_size: 362_554,
assert_equal(tags.sort, site.tags.map(&:first).sort) tags: ["bayashiko", "journey_to_the_west", "sun_wukong"],
assert_equal(profile_url.to_s, site.profile_url.to_s) page_url: "https://yande.re/post/show/482880",
assert_nothing_raised { site.to_h } 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
end end
context "Fetching data for an active yande.re .jpg post" do context "a https://yande.re/sample/:hash/:file.jpg" do
should "work" do strategy_should_work(
@samp = "https://files.yande.re/sample/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880%20sample%20bayashiko%20journey_to_the_west%20sun_wukong.jpg" "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" image_urls: ["https://files.yande.re/image/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880.jpg"],
@page = "https://yande.re/post/show/482880" download_size: 362_554,
@tags = ["bayashiko", "journey_to_the_west", "sun_wukong"] tags: ["bayashiko", "journey_to_the_west", "sun_wukong"],
@size = 362_554 page_url: "https://yande.re/post/show/482880",
@profile_url = "https://twitter.com/apononori" 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
end end
context "Fetching data for a deleted yande.re .png post with the post id" do context "a 'https://yande.re/jpeg/:hash/:file.jpg' jpeg sample url" do
should "work" do strategy_should_work(
@samp = "https://files.yande.re/sample/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018%20detexted%20misaki_kurehito%20saenai_heroine_no_sodatekata%20sawamura_spencer_eriri%20thighhighs.jpg" "https://yande.re/jpeg/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092%20hatsune_miku%20tid%20vocaloid.jpg",
@jpeg = "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/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092.png"],
@full = "https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018.png" download_size: 1_050_117
@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
end end
context "Fetching data for a deleted yande.re .png post without the post id" do context "a deleted yande.re post with the post id" do
should "work" do strategy_should_work(
@samp = "https://files.yande.re/sample/fb27a7ea6c48b2ef76fe915e378b9098.jpg" "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/jpeg/fb27a7ea6c48b2ef76fe915e378b9098.jpg" image_urls: ["https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018.png"],
@full = "https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098.png" page_url: "https://yande.re/post/show/398018",
@tags = [] tags: ["misaki_kurehito", "saenai_heroine_no_sodatekata", "sawamura_spencer_eriri", "detexted", "thighhighs"],
@size = 9_118_998 download_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
end end
context "When the referer URL is SauceNao" do context "a deleted yande.re post without the post id" do
should "ignore the referer" do strategy_should_work(
@url = "https://yande.re/post/show/469929" "https://files.yande.re/jpeg/fb27a7ea6c48b2ef76fe915e378b9098.jpg",
@ref = "https://saucenao.com/" image_urls: ["https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098.png"],
download_size: 9_118_998
)
end
assert_source_data_equals(@url, @ref, context "a yande.re post with a saucenao referer" do
site_name: "Yande.re", strategy_should_work(
image_url: "https://files.yande.re/image/36b031b266605d89aed2b62d479e64b1/yande.re%20469929.jpg", "https://yande.re/post/show/469929",
page_url: "https://yande.re/post/show/469929", referer: "https://saucenao.com",
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], image_urls: ["https://files.yande.re/image/36b031b266605d89aed2b62d479e64b1/yande.re%20469929.jpg"],
) page_url: "https://yande.re/post/show/469929",
end 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
end end
context "Konachan.com:" do context "For konachan.com," do
context "Fetching data for an active konachan.com .png post" do context "a sample url" do
should "work" do strategy_should_work(
@samp = "https://konachan.com/sample/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916%20sample.jpg" "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" image_urls: ["https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png"],
@full = "https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png" download_size: 8_167_593,
@page = "https://konachan.com/post/show/270916" 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)],
@size = 8_167_593 profile_url: "https://www.pixiv.net/users/22528152"
@tags = %w[ )
anthropomorphism bed blonde_hair bow brown_eyes doll end
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 } context "a jpeg url" do
assert_source_data_equals(@samp, **@data) strategy_should_work(
assert_source_data_equals(@jpeg, **@data) "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",
assert_source_data_equals(@full, **@data) image_urls: ["https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png"],
assert_source_data_equals(@page, **@data) download_size: 8_167_593,
end 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
end end

View File

@@ -2,100 +2,55 @@ require 'test_helper'
module Sources module Sources
class NewgroundsTest < ActiveSupport::TestCase class NewgroundsTest < ActiveSupport::TestCase
context "The source for a newgrounds picture" do context "A newgrounds post url" do
setup do strategy_should_work(
@url = "https://www.newgrounds.com/art/view/hcnone/sephiroth" "https://www.newgrounds.com/art/view/hcnone/sephiroth",
@image_url = "https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234" image_urls: ["https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234"],
@image_1 = Source::Extractor.find(@url) page_url: "https://www.newgrounds.com/art/view/hcnone/sephiroth",
@image_2 = Source::Extractor.find(@image_url) download_size: 4_224,
end artist_name: "hcnone",
profile_url: "https://hcnone.newgrounds.com",
should "get the artist name" do artist_commentary_title: "Sephiroth",
assert_equal("hcnone", @image_1.artist_name) tags: [
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 = [
%w[sephiroth https://www.newgrounds.com/search/conduct/art?match=tags&tags=sephiroth], %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], %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
end end
context "A multi-image Newgrounds post" do context "A newgrounds image url" do
should "get all the images" do strategy_should_work(
source = Source::Extractor.find("https://www.newgrounds.com/art/view/natthelich/weaver") "https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234",
image_urls = [ 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 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/images/1520000/1520217_natthelich_weaver.jpg?f1606365031",
"https://art.ngfiles.com/comments/199000/iu_199826_7115981.jpg", "https://art.ngfiles.com/comments/199000/iu_199826_7115981.jpg",
] ]
)
assert_equal(image_urls, source.image_urls)
end
end end
context "A deleted or not existing picture" do context "A deleted or non-existing post" do
setup do strategy_should_work(
@fake_1 = Source::Extractor.find("https://www.newgrounds.com/art/view/ThisUser/DoesNotExist") "https://www.newgrounds.com/art/view/natthelich/nopicture",
@artist_1 = create(:artist, name: "thisuser", url_string: "https://thisuser.newgrounds.com") deleted: true,
profile_url: "https://natthelich.newgrounds.com",
@fake_2 = Source::Extractor.find("https://www.newgrounds.com/art/view/natthelich/nopicture") artist_name: "natthelich"
@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
end end
context "A www.newgrounds.com/dump/item URL" do context "A www.newgrounds.com/dump/item URL" do
@@ -103,23 +58,15 @@ module Sources
"https://www.newgrounds.com/dump/item/a1f417d20f5eaef31e26ac3c4956b3d4", "https://www.newgrounds.com/dump/item/a1f417d20f5eaef31e26ac3c4956b3d4",
image_urls: [], image_urls: [],
artist_name: nil, artist_name: nil,
profile_url: nil, profile_url: nil
) )
end end
context "A post with links to other illustrations in the commentary" do context "A post with links to other illustrations not belonging to the commentary" do
should "not include the links in the commentary" do strategy_should_work(
@source = Source::Extractor.find("https://www.newgrounds.com/art/view/boxofwant/annie-hughes-1") "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].'
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
end end
should "Parse Newgrounds URLs correctly" do 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.page_url?("https://www.newgrounds.com/portal/view/830293"))
assert(Source::URL.profile_url?("https://natthelich.newgrounds.com")) assert(Source::URL.profile_url?("https://natthelich.newgrounds.com"))
refute(Source::URL.profile_url?("https://www.newgrounds.com")) assert_not(Source::URL.profile_url?("https://www.newgrounds.com"))
refute(Source::URL.profile_url?("https://newgrounds.com")) assert_not(Source::URL.profile_url?("https://newgrounds.com"))
end end
end end
end end

View File

@@ -2,68 +2,113 @@ require 'test_helper'
module Sources module Sources
class PixivSketchTest < ActiveSupport::TestCase class PixivSketchTest < ActiveSupport::TestCase
context "A Pixiv Sketch source" do context "A Pixiv Sketch post" do
should "work for a post with a single image" do strategy_should_work(
source = Source::Extractor.find("https://sketch.pixiv.net/items/5835314698645024323") "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
assert_equal("Pixiv Sketch", source.site_name) context "A Pixiv Sketch image with referer" do
assert_equal(["https://img-sketch.pixiv.net/uploads/medium/file/9986983/8431631593768139653.jpg"], source.image_urls) strategy_should_work(
assert_equal("https://sketch.pixiv.net/items/5835314698645024323", source.page_url) "https://img-sketch.pixiv.net/uploads/medium/file/9986983/8431631593768139653.jpg",
assert_equal("https://sketch.pixiv.net/@user_ejkv8372", source.profile_url) referer: "https://sketch.pixiv.net/items/5835314698645024323",
assert_equal(["https://sketch.pixiv.net/@user_ejkv8372", "https://www.pixiv.net/users/44772126"], source.profile_urls) image_urls: ["https://img-sketch.pixiv.net/uploads/medium/file/9986983/8431631593768139653.jpg"],
assert_equal("user_ejkv8372", source.artist_name) page_url: "https://sketch.pixiv.net/items/5835314698645024323",
assert_equal(["user_ejkv8372", "サコ"], source.other_names) profile_urls: ["https://sketch.pixiv.net/@user_ejkv8372", "https://www.pixiv.net/users/44772126"],
assert_equal("🍻シャンクスとミホーク誕生日おめでとう🍻(過去絵) ", source.artist_commentary_desc) profile_url: "https://sketch.pixiv.net/@user_ejkv8372",
assert_equal([], source.tags.map(&:first)) artist_name: "user_ejkv8372",
assert_nothing_raised { source.to_h } other_names: ["user_ejkv8372", "サコ"],
end artist_commentary_desc: "🍻シャンクスとミホーク誕生日おめでとう🍻(過去絵) ",
tags: []
)
end
should "work for an image url without a referer" do context "A Pixiv Sketch image without the referer" do
# page: https://sketch.pixiv.net/items/8052785510155853613 # page: https://sketch.pixiv.net/items/8052785510155853613
source = Source::Extractor.find("https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg") 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
assert_equal(["https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg"], source.image_urls) context "A NSFW post" do
assert_nil(source.page_url) strategy_should_work(
assert_nil(source.profile_url) "https://sketch.pixiv.net/items/193462611994864256",
assert_equal([], source.profile_urls) image_urls: ["https://img-sketch.pixiv.net/uploads/medium/file/884876/4909517173982299587.jpg"],
assert_nil(source.artist_name) page_url: "https://sketch.pixiv.net/items/193462611994864256",
assert_equal([], source.other_names) profile_url: "https://sketch.pixiv.net/@lithla",
assert_nil(source.artist_commentary_desc) artist_name: "lithla",
assert_equal([], source.tags.map(&:first)) other_names: ["lithla", "リリスラウダ"],
assert_nothing_raised { source.to_h } artist_commentary_desc: "チビッコ露出プレイ ピース",
end tags: []
)
end
should "work for an image url with a referer" do context "A post with multiple images" do
source = Source::Extractor.find("https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg", "https://sketch.pixiv.net/items/8052785510155853613") desc = <<~EOS.normalize_whitespace
33
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", "俺P"], 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 }
end
should "work for a NSFW post" do
source = Source::Extractor.find("https://sketch.pixiv.net/items/193462611994864256")
()
()
()+
1()
1()()
()
()
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) 5(30)
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") (3D化できない)
12
assert_equal(%w[
()
#制作過程
#このすば
#この素晴らしい世界に祝福を!
#セナ
#バニー
#3月3日
#巨乳
#黒髪巨乳
#タイツ
EOS
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/9988964/1564052114639195387.png
https://img-sketch.pixiv.net/uploads/medium/file/9988965/3187185972065199018.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/9988966/5281789458380074490.png
@@ -74,70 +119,21 @@ module Sources
https://img-sketch.pixiv.net/uploads/medium/file/9988971/9105451079763734305.jpg 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/9988972/2641925439408057307.jpg
https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.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) artist_commentary_desc: desc,
assert_equal("https://sketch.pixiv.net/@op-one", source.profile_url) artist_name: "op-one",
assert_equal("op-one", source.artist_name) page_url: "https://sketch.pixiv.net/items/8052785510155853613",
assert_equal(<<~EOS.normalize_whitespace, source.artist_commentary_desc) profile_url: "https://sketch.pixiv.net/@op-one",
33 tags: %w[制作過程 このすば この素晴らしい世界に祝福を セナ バニー 3月3日 巨乳 黒髪巨乳 タイツ]
)
end
should "Parse Pixiv Sketch URLs correctly" do
assert(Source::URL.image_url?("https://img-sketch.pixiv.net/uploads/medium/file/4463372/8906921629213362989.jpg "))
assert(Source::URL.image_url?("https://img-sketch.pximg.net/c!/w=540,f=webp:jpeg/uploads/medium/file/4463372/8906921629213362989.jpg"))
() assert(Source::URL.image_url?("https://img-sketch.pixiv.net/c/f_540/uploads/medium/file/9986983/8431631593768139653.jpg"))
() assert(Source::URL.page_url?("https://sketch.pixiv.net/items/5835314698645024323"))
()+ assert(Source::URL.profile_url?("https://sketch.pixiv.net/@user_ejkv8372"))
1()
1()()
()
()
5(30)
(3D化できない)
12
()
#制作過程
#このすば
#この素晴らしい世界に祝福を!
#セナ
#バニー
#3月3日
#巨乳
#黒髪巨乳
#タイツ
EOS
assert_equal(%w[制作過程 このすば この素晴らしい世界に祝福を セナ バニー 3月3日 巨乳 黒髪巨乳 タイツ], source.tags.map(&:first))
assert_nothing_raised { source.to_h }
end
should "Parse Pixiv Sketch URLs correctly" do
assert(Source::URL.image_url?("https://img-sketch.pixiv.net/uploads/medium/file/4463372/8906921629213362989.jpg "))
assert(Source::URL.image_url?("https://img-sketch.pximg.net/c!/w=540,f=webp:jpeg/uploads/medium/file/4463372/8906921629213362989.jpg"))
assert(Source::URL.image_url?("https://img-sketch.pixiv.net/c/f_540/uploads/medium/file/9986983/8431631593768139653.jpg"))
assert(Source::URL.page_url?("https://sketch.pixiv.net/items/5835314698645024323"))
assert(Source::URL.profile_url?("https://sketch.pixiv.net/@user_ejkv8372"))
end
end end
end end
end end

View File

@@ -2,105 +2,75 @@ require "test_helper"
module Sources module Sources
class PlurkTest < ActiveSupport::TestCase class PlurkTest < ActiveSupport::TestCase
context "The source for a Plurk picture" do context "A plurk post" do
setup do strategy_should_work(
@post_url = "https://www.plurk.com/p/om6zv4" "https://www.plurk.com/p/om6zv4",
@adult_post_url = "https://www.plurk.com/p/omc64y" image_urls: ["https://images.plurk.com/5wj6WD0r6y4rLN0DL3sqag.jpg"],
@image_url = "https://images.plurk.com/5wj6WD0r6y4rLN0DL3sqag.jpg" download_size: 627_697,
@profile_url = "https://www.plurk.com/redeyehare" artist_name: "紅眼兔@姑且是個畫圖的",
@post1 = Source::Extractor.find(@post_url) tag_name: "redeyehare",
@post2 = Source::Extractor.find(@image_url) profile_url: "https://www.plurk.com/redeyehare",
@post3 = Source::Extractor.find(@profile_url) dtext_artist_commentary_desc: "Trick or Treat!\n很久沒畫萬聖賀圖了,畫一波大的 感覺持續復健中"
@post4 = Source::Extractor.find(@adult_post_url) )
end end
should "not raise errors" do context "An adult plurk post" do
assert_nothing_raised { @post1.to_h } strategy_should_work(
assert_nothing_raised { @post2.to_h } "https://www.plurk.com/p/omc64y",
assert_nothing_raised { @post3.to_h } profile_url: "https://www.plurk.com/BOW99",
assert_nothing_raised { @post4.to_h } artist_name: "BOW🔞",
end tag_name: "BOW99",
dtext_artist_commentary_desc: "[十月號]",
should "get the artist name" do image_urls: [
assert_equal("紅眼兔@姑且是個畫圖的", @post1.artist_name) "https://images.plurk.com/yfnumBJqqoQt50Em6xKwf.png",
assert_equal("redeyehare", @post1.tag_name) "https://images.plurk.com/5NaqqO3Yi6bQW1wKXq1Dc2.png",
assert_equal("BOW99", @post4.tag_name) "https://images.plurk.com/3HzNcbMhCozHPk5YY8j9fI.png",
end "https://images.plurk.com/2e0duwn8BpSW9MGuUvbrim.png",
"https://images.plurk.com/1OuiMDp82hYPEUn64CWFFB.png",
should "get profile url" do "https://images.plurk.com/3F3KzZOabeMYkgTeseEZ0r.png",
assert_equal(@profile_url, @post1.profile_url) "https://images.plurk.com/7onKKTAIXkY4pASszrBys8.png",
end "https://images.plurk.com/6aotmjLGbtMLiI3slN7ODv.png",
"https://images.plurk.com/6pzn7jE2nkj9EV7H25L0x1.png",
should "get the image url" do "https://images.plurk.com/yA8egjDuhy0eNG9yxRj1d.png",
assert_equal([@image_url], @post1.image_urls) "https://images.plurk.com/55tbTkH3cKTTYkZe9fu1Pv.png",
assert_equal([@image_url], @post2.image_urls) "https://images.plurk.com/5z64F9uUipJ0fMJWXNGHTw.png",
end "https://images.plurk.com/6cwurMe6jymEu6INzmyg74.png",
"https://images.plurk.com/7zyTReS8UVyCFYtU1DJRYt.png",
should "get the image urls for an adult post" do "https://images.plurk.com/1PiRWGzaXozU15Scx1ZC4T.png",
images = %w[ "https://images.plurk.com/2xzB5qacdLVV75GhaFifaY.png",
https://images.plurk.com/yfnumBJqqoQt50Em6xKwf.png "https://images.plurk.com/7uQENFmFNtWSKF0AAQKffr.png",
https://images.plurk.com/5NaqqO3Yi6bQW1wKXq1Dc2.png "https://images.plurk.com/7ChGLokdAezvbEjPCLUr8f.png",
https://images.plurk.com/3HzNcbMhCozHPk5YY8j9fI.png "https://images.plurk.com/3AzjLxynamDGxNDTq4wt5x.png",
https://images.plurk.com/2e0duwn8BpSW9MGuUvbrim.png "https://images.plurk.com/3SYjvKc3IBbz6ZXWeG1pY8.png",
https://images.plurk.com/1OuiMDp82hYPEUn64CWFFB.png "https://images.plurk.com/7bk2kYN2fEVV0kiT5qoiuO.png",
https://images.plurk.com/3F3KzZOabeMYkgTeseEZ0r.png "https://images.plurk.com/6mgCwWjSqOfi0BtSg6THcZ.png",
https://images.plurk.com/7onKKTAIXkY4pASszrBys8.png "https://images.plurk.com/3BwtMvr6S13gr96r5TLIFd.png",
https://images.plurk.com/6aotmjLGbtMLiI3slN7ODv.png "https://images.plurk.com/22CPzkRM71frDR5eRMPthC.png",
https://images.plurk.com/6pzn7jE2nkj9EV7H25L0x1.png "https://images.plurk.com/1IFScoxA7m0FXNu6XirBwa.jpg",
https://images.plurk.com/yA8egjDuhy0eNG9yxRj1d.png "https://images.plurk.com/5v1ZXQxbS7ocV4BybwbCSs.jpg",
https://images.plurk.com/55tbTkH3cKTTYkZe9fu1Pv.png "https://images.plurk.com/4n1og7pg4KP3wRYSKpFzF7.png",
https://images.plurk.com/5z64F9uUipJ0fMJWXNGHTw.png "https://images.plurk.com/5gK1PyPTrVYoeZBr10lEYu.png",
https://images.plurk.com/6cwurMe6jymEu6INzmyg74.png "https://images.plurk.com/3m8YZS3D9vaAH8Lw1LDTix.png",
https://images.plurk.com/7zyTReS8UVyCFYtU1DJRYt.png "https://images.plurk.com/3oy7joPrEFm0Wlo7NplXOl.png",
https://images.plurk.com/1PiRWGzaXozU15Scx1ZC4T.png "https://images.plurk.com/2IBA93ghmCJCJT72mQyLUK.png",
https://images.plurk.com/2xzB5qacdLVV75GhaFifaY.png "https://images.plurk.com/16jqEhVqtuLJwnRjpIDRCr.png",
https://images.plurk.com/7uQENFmFNtWSKF0AAQKffr.png "https://images.plurk.com/7cKzaSigAvKc6DKNxeGmnH.png",
https://images.plurk.com/7ChGLokdAezvbEjPCLUr8f.png "https://images.plurk.com/ypfkOMsC24hIPGSEWjJ8A.png",
https://images.plurk.com/3AzjLxynamDGxNDTq4wt5x.png "https://images.plurk.com/5qW11yr06e9u3t5Zt9Jxmm.png",
https://images.plurk.com/3SYjvKc3IBbz6ZXWeG1pY8.png "https://images.plurk.com/4H5st1xsFDSFgLd7gNXgD8.png",
https://images.plurk.com/7bk2kYN2fEVV0kiT5qoiuO.png "https://images.plurk.com/4nf49mWygwQyrYriZ453Qx.png",
https://images.plurk.com/6mgCwWjSqOfi0BtSg6THcZ.png "https://images.plurk.com/2Y0TXcYZkni94j7yxxosV9.png",
https://images.plurk.com/3BwtMvr6S13gr96r5TLIFd.png "https://images.plurk.com/5ih71C9XNJDq88wzKbBdNp.png",
https://images.plurk.com/22CPzkRM71frDR5eRMPthC.png "https://images.plurk.com/UmoZjSHx0Y4NYa3mgKffU.png",
https://images.plurk.com/1IFScoxA7m0FXNu6XirBwa.jpg "https://images.plurk.com/4IHGG5mQNw95vqClFEBoOM.png",
https://images.plurk.com/5v1ZXQxbS7ocV4BybwbCSs.jpg "https://images.plurk.com/5J3bRPjGBZV8fDxo7cTwGs.png",
https://images.plurk.com/4n1og7pg4KP3wRYSKpFzF7.png "https://images.plurk.com/3uAjR5oBfe4d6MFThFQ0Gt.png",
https://images.plurk.com/5gK1PyPTrVYoeZBr10lEYu.png "https://images.plurk.com/3fFJ8RN3HkmfcuUdn7OpnQ.png",
https://images.plurk.com/3m8YZS3D9vaAH8Lw1LDTix.png "https://images.plurk.com/sxkaWnhmDrCSsUEg6Kn9Y.png",
https://images.plurk.com/3oy7joPrEFm0Wlo7NplXOl.png "https://images.plurk.com/1f3W8JnHlwpt3OlT4ZJhiu.gif",
https://images.plurk.com/2IBA93ghmCJCJT72mQyLUK.png "https://images.plurk.com/5lNGKqPCf6opXu21f5DdbU.gif",
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 end
should "Parse Plurk URLs correctly" do should "Parse Plurk URLs correctly" do

View File

@@ -7,48 +7,39 @@ module Sources
skip "DeviantArt API keys not set" unless Danbooru.config.deviantart_client_id.present? skip "DeviantArt API keys not set" unless Danbooru.config.deviantart_client_id.present?
end end
context "A https://sta.sh/:id page url" do context "A https://sta.sh/:id url" do
should "work" do strategy_should_work(
@site = Source::Extractor.find("https://sta.sh/0wxs31o7nn2") "https://sta.sh/0wxs31o7nn2",
image_urls: ["https://wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dcmga0s-a345a815-2436-4ab5-8941-492011e1bff6.png"],
assert_equal("noizave", @site.artist_name) page_url: "https://sta.sh/0wxs31o7nn2",
assert_equal("https://www.deviantart.com/noizave", @site.profile_url) artist_name: "noizave",
profile_url: "https://www.deviantart.com/noizave",
assert_equal("A pepe", @site.artist_commentary_title) artist_commentary_title: "A pepe",
assert_equal("This is a test.", @site.artist_commentary_desc) artist_commentary_desc: "This is a test."
)
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
end end
context "A https://orig00.deviantart.net/* image url" do context "A https://orig00.deviantart.net/* image url with a https://sta.sh/:id referer" do
context "with a https://sta.sh/:id referer" do strategy_should_work(
should "work" do "https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png",
@site = Source::Extractor.find("https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png", "https://sta.sh/0wxs31o7nn2") 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
assert_equal("noizave", @site.artist_name) context "A https://orig00.deviantart.net/* image url without the referer" do
assert_equal("https://www.deviantart.com/noizave", @site.profile_url) strategy_should_work(
"https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png",
assert_equal("A pepe", @site.artist_commentary_title) # if all we have is the image url, then we can't tell that this is really a sta.sh image.
assert_equal("This is a test.", @site.artist_commentary_desc) 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://sta.sh/0wxs31o7nn2", @site.page_url) page_url: "https://www.deviantart.com/noizave/art/A-Pepe-763305148"
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
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")
# 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)
# 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
end end
end end
end end