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",
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 end
should "get the image url" do context "A http://cdn.artstation.com/p/assets/... url" do
url = "https://cdn.artstation.com/p/assets/images/images/000/144/922/4k/cassio-yoshiyaki-cody2backup2-yoshiyaki.jpg?1406314198" strategy_should_work(
assert_equal([url], @site.image_urls) "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 end
should "get the tags" do context "A http://cdn.artstation.com/p/assets/... url with referrer" do
assert_equal(["Street Fighter", "Cody", "SF"].sort, @site.tags.map(&:first).sort) strategy_should_work(
assert_equal(["street_fighter", "cody", "sf"].sort, @site.normalized_tags.sort) "https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg",
end 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 end
context "The source site for a http://cdn.artstation.com/p/assets/... url" do context "An ArtStation cover 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/covers/images/007/262/828/large/monica-kyrie-1.jpg?1504865060",
@ref = "https://www.artstation.com/artwork/4BWW2" image_urls: ["https://cdn.artstation.com/p/assets/covers/images/007/262/828/original/monica-kyrie-1.jpg?1504865060"]
)
end end
context "with a referer" do context "An ArtStation post with images and youtube links" do
should "work" do strategy_should_work(
site = Source::Extractor.find(@url, @ref) "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"]
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 end
context "without a referer" do context "An ArtStation post with images and videos" do
should "work" do strategy_should_work( # XXX Broken by Cloudflare captcha
site = Source::Extractor.find(@url) "https://www.artstation.com/artwork/0nP1e8",
image_urls: %w[
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[
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 end
should "work for the video itself" do context "An ArtStation video url" do
@source = Source::Extractor.find("https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4") strategy_should_work(
"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) image_urls: ["https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4"]
end )
end end
context "A work that has been deleted" do context "A deleted ArtStation url" do
should "work" do strategy_should_work(
url = "https://fiship.artstation.com/projects/x8n8XT" "https://fiship.artstation.com/projects/x8n8XT",
site = Source::Extractor.find(url) deleted: true,
image_urls: [],
assert_equal("fiship", site.artist_name) artist_name: "fiship",
assert_equal("https://www.artstation.com/fiship", site.profile_url) profile_url: "https://www.artstation.com/fiship",
assert_equal(url, site.page_url) page_url: "https://fiship.artstation.com/projects/x8n8XT"
assert_equal([], site.image_urls) )
assert_nothing_raised { site.to_h }
end
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ちゃんアラフィフライダーさん",
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",
profile_url: "https://chanxco.fanbox.cc",
download_size: 245_678,
artist_name: "chanxco",
display_name: "CHANxCO"
)
end end
should "get the commentary" do context "A Pixiv Fanbox sample" do
# Normal commentary strategy_should_work(
assert_equal("栗山やんみ(デザイン)", @post1.artist_commentary_title) "https://downloads.fanbox.cc/images/post/209386/w/1200/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg",
image_urls: ["https://downloads.fanbox.cc/images/post/209386/8dRNHXkFqAwSt31W2Bg8fSdL.jpeg"],
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" artist_commentary_title: "水着BBちゃんアラフィフライダーさん",
assert_equal(body1, @post1.artist_commentary_desc) 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",
# With embedded pics profile_url: "https://chanxco.fanbox.cc",
assert_equal("水着BBちゃんアラフィフライダーさん", @post2.artist_commentary_title) download_size: 320_056,
assert_equal("水着BBちゃんアラフィフライダーさん", @post3.artist_commentary_title) artist_name: "chanxco",
display_name: "CHANxCO"
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 end
should "get the right page url" do context "An age-restricted Fanbox post" do
assert_equal("https://yanmi0308.fanbox.cc/posts/1141325", @post1.page_url) strategy_should_work(
assert_equal("https://chanxco.fanbox.cc/posts/209386", @post2.page_url) "https://mfr.fanbox.cc/posts/1306390",
assert_equal("https://chanxco.fanbox.cc/posts/209386", @post3.page_url) image_urls: ["https://downloads.fanbox.cc/images/post/1306390/VOXblkyvltL5fRhMoR7RdSkk.png"],
end artist_name: "mfr",
artist_commentary_desc: "これからセックスしまーす♪と言ってるシーン(・ω・`)\nhttps://downloads.fanbox.cc/images/post/1306390/VOXblkyvltL5fRhMoR7RdSkk.png\n※海苔強化して再アップしました( 'A`;)\n",
should "correctly download the right image" do profile_url: "https://mfr.fanbox.cc"
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
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"],
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 end
should "get the illustration id" do context "A hentai-foundry picture" do
assert_equal("795025", @image_1.illust_id) strategy_should_work(
assert_equal("795025", @image_2.illust_id) "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 artist name" do artist_commentary_title: "kuroeda",
assert_equal("Afrobull", @image_1.artist_name) profile_url: "https://www.hentai-foundry.com/user/Afrobull",
assert_equal("Afrobull", @image_2.artist_name) download_size: 1_349_887,
end tags: [["elf", "https://www.hentai-foundry.com/pictures/tagged/elf"]]
)
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
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: [],
artist_name: "faustsketcher",
profile_url: "https://www.hentai-foundry.com/user/faustsketcher",
deleted: true
)
end end
should "still find the artist name" do context "An old image url" do
assert_equal("faustsketcher", @image.artist_name) strategy_should_work(
assert_equal("https://www.hentai-foundry.com/user/faustsketcher", @image.profile_url) "http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg",
assert_equal([@artist], @image.artists) image_urls: ["https://pictures.hentai-foundry.com/a/AnimeFlux/219123/AnimeFlux-219123-Mobile_Suit_Equestria_rainbow_run.jpg"],
end page_url: "https://www.hentai-foundry.com/pictures/user/AnimeFlux/219123",
profile_url: "https://www.hentai-foundry.com/user/AnimeFlux"
)
end end
context "generating page urls" do context "An image url without the extension" do
should "work" do strategy_should_work(
source1 = "http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg" "http://www.hentai-foundry.com/pictures/user/Ganassa/457176/LOL-Swimsuit---Caitlyn-reworked-nude-ver.",
source2 = "http://pictures.hentai-foundry.com/a/AnimeFlux/219123/Mobile-Suit-Equestria-rainbow-run.jpg" image_urls: ["https://pictures.hentai-foundry.com/g/Ganassa/457176/Ganassa-457176-LOL_Swimsuit_-_Caitlyn_reworked_nude_ver..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/Ganassa/457176",
profile_url: "https://www.hentai-foundry.com/user/Ganassa"
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 "A post with deeply nested commentary" do
should "work" do strategy_should_work("https://hentai-foundry.com/pictures/user/LumiNyu/867562/Mona-patreon-winner")
@source = Source::Extractor.find("https://hentai-foundry.com/pictures/user/LumiNyu/867562/Mona-patreon-winner")
assert_nothing_raised { @source.to_h }
end
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 end
context "Yande.re:" do context "a https://yande.re/sample/:hash/:file.jpg" do
context "A 'https://yande.re/jpeg/:hash/:file.jpg' jpeg sample url" do strategy_should_work(
should "download the original file" do "https://files.yande.re/sample/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880%20sample%20bayashiko%20journey_to_the_west%20sun_wukong.jpg",
@source = "https://yande.re/jpeg/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092%20hatsune_miku%20tid%20vocaloid.jpg" image_urls: ["https://files.yande.re/image/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880.jpg"],
@rewrite = "https://files.yande.re/image/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092.png" download_size: 362_554,
assert_rewritten(@rewrite, @source) tags: ["bayashiko", "journey_to_the_west", "sun_wukong"],
assert_downloaded(1_050_117, @source) page_url: "https://yande.re/post/show/482880",
end profile_url: "https://twitter.com/apononori"
)
end end
context "Fetching data for an active yande.re .jpg post" 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/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880%20sample%20bayashiko%20journey_to_the_west%20sun_wukong.jpg" "https://yande.re/jpeg/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092%20hatsune_miku%20tid%20vocaloid.jpg",
@full = "https://files.yande.re/image/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880.jpg" image_urls: ["https://files.yande.re/image/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092.png"],
@page = "https://yande.re/post/show/482880" download_size: 1_050_117
@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
end end
context "Fetching data for a deleted yande.re .png post with 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/yande.re%20398018%20detexted%20misaki_kurehito%20saenai_heroine_no_sodatekata%20sawamura_spencer_eriri%20thighhighs.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/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"],
@full = "https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018.png" page_url: "https://yande.re/post/show/398018",
@page = "https://yande.re/post/show/398018" tags: ["misaki_kurehito", "saenai_heroine_no_sodatekata", "sawamura_spencer_eriri", "detexted", "thighhighs"],
@tags = ["misaki_kurehito", "saenai_heroine_no_sodatekata", "sawamura_spencer_eriri", "detexted", "thighhighs"] download_size: 9_118_998
@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 without the post id" do
should "work" do strategy_should_work(
@samp = "https://files.yande.re/sample/fb27a7ea6c48b2ef76fe915e378b9098.jpg" "https://files.yande.re/jpeg/fb27a7ea6c48b2ef76fe915e378b9098.jpg",
@jpeg = "https://files.yande.re/jpeg/fb27a7ea6c48b2ef76fe915e378b9098.jpg" image_urls: ["https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098.png"],
@full = "https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098.png" download_size: 9_118_998
@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
end end
context "When the referer URL is SauceNao" do context "a yande.re post with a saucenao referer" do
should "ignore the referer" do strategy_should_work(
@url = "https://yande.re/post/show/469929" "https://yande.re/post/show/469929",
@ref = "https://saucenao.com/" referer: "https://saucenao.com",
image_urls: ["https://files.yande.re/image/36b031b266605d89aed2b62d479e64b1/yande.re%20469929.jpg"],
assert_source_data_equals(@url, @ref,
site_name: "Yande.re",
image_url: "https://files.yande.re/image/36b031b266605d89aed2b62d479e64b1/yande.re%20469929.jpg",
page_url: "https://yande.re/post/show/469929", 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
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 end
context "Konachan.com:" do context "a jpeg url" do
context "Fetching data for an active konachan.com .png post" do strategy_should_work(
should "work" do "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",
@samp = "https://konachan.com/sample/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916%20sample.jpg" image_urls: ["https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png"],
@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" download_size: 8_167_593,
@full = "https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png" 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)],
@page = "https://konachan.com/post/show/270916" profile_url: "https://www.pixiv.net/users/22528152"
@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)
end 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 end
should "find the right artist" do context "A newgrounds image url" do
artist_1 = create(:artist, name: "hcnone1", url_string: "https://hcnone.newgrounds.com/art") strategy_should_work(
artist_2 = create(:artist, name: "hcnone2", url_string: "https://www.newgrounds.com/art/view/hcnone/sephiroth") "https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234",
artist_3 = create(:artist, name: "bad_artist", url_string: "https://www.newgrounds.com/art") image_urls: ["https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234"],
page_url: "https://www.newgrounds.com/art/view/hcnone/sephiroth",
assert_equal([artist_1, artist_2], @image_1.artists) download_size: 4_224,
assert_equal([artist_1, artist_2], @image_2.artists) artist_name: "hcnone",
profile_url: "https://hcnone.newgrounds.com",
assert_not_equal([artist_3], @image_1.artists) artist_commentary_title: "Sephiroth",
end 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 end
context "A multi-image Newgrounds post" do context "A multi-image post" do
should "get all the images" do strategy_should_work(
source = Source::Extractor.find("https://www.newgrounds.com/art/view/natthelich/weaver") "https://www.newgrounds.com/art/view/natthelich/weaver",
image_urls = [ 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,83 +2,62 @@ 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"],
assert_equal("Pixiv Sketch", source.site_name) page_url: "https://sketch.pixiv.net/items/5835314698645024323",
assert_equal(["https://img-sketch.pixiv.net/uploads/medium/file/9986983/8431631593768139653.jpg"], source.image_urls) profile_urls: ["https://sketch.pixiv.net/@user_ejkv8372", "https://www.pixiv.net/users/44772126"],
assert_equal("https://sketch.pixiv.net/items/5835314698645024323", source.page_url) profile_url: "https://sketch.pixiv.net/@user_ejkv8372",
assert_equal("https://sketch.pixiv.net/@user_ejkv8372", source.profile_url) artist_name: "user_ejkv8372",
assert_equal(["https://sketch.pixiv.net/@user_ejkv8372", "https://www.pixiv.net/users/44772126"], source.profile_urls) other_names: ["user_ejkv8372", "サコ"],
assert_equal("user_ejkv8372", source.artist_name) artist_commentary_desc: "🍻シャンクスとミホーク誕生日おめでとう🍻(過去絵) ",
assert_equal(["user_ejkv8372", "サコ"], source.other_names) tags: []
assert_equal("🍻シャンクスとミホーク誕生日おめでとう🍻(過去絵) ", source.artist_commentary_desc) )
assert_equal([], source.tags.map(&:first))
assert_nothing_raised { source.to_h }
end 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 # 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",
assert_equal(["https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg"], source.image_urls) page_url: nil,
assert_nil(source.page_url) profile_url: nil,
assert_nil(source.profile_url) artist_name: nil,
assert_equal([], source.profile_urls) tags: [],
assert_nil(source.artist_name) artist_commentary_desc: nil
assert_equal([], source.other_names) )
assert_nil(source.artist_commentary_desc)
assert_equal([], source.tags.map(&:first))
assert_nothing_raised { source.to_h }
end end
should "work for an image url with a referer" do context "A NSFW post" do
source = Source::Extractor.find("https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg", "https://sketch.pixiv.net/items/8052785510155853613") strategy_should_work(
"https://sketch.pixiv.net/items/193462611994864256",
assert_equal("https://sketch.pixiv.net/items/8052785510155853613", source.page_url) image_urls: ["https://img-sketch.pixiv.net/uploads/medium/file/884876/4909517173982299587.jpg"],
assert_equal("https://sketch.pixiv.net/@op-one", source.profile_url) page_url: "https://sketch.pixiv.net/items/193462611994864256",
assert_equal(["https://sketch.pixiv.net/@op-one", "https://www.pixiv.net/users/5903369"], source.profile_urls) profile_url: "https://sketch.pixiv.net/@lithla",
assert_equal("op-one", source.artist_name) artist_name: "lithla",
assert_equal(["op-one", "俺P"], source.other_names) other_names: ["lithla", "リリスラウダ"],
assert_match(/\A3月3日は「うさぎの日」らしいので/, source.artist_commentary_desc) artist_commentary_desc: "チビッコ露出プレイ ピース",
assert_equal(%w[制作過程 このすば この素晴らしい世界に祝福を セナ バニー 3月3日 巨乳 黒髪巨乳 タイツ], source.tags.map(&:first)) tags: []
assert_nothing_raised { source.to_h } )
end end
should "work for a NSFW post" do context "A post with multiple images" do
source = Source::Extractor.find("https://sketch.pixiv.net/items/193462611994864256") desc = <<~EOS.normalize_whitespace
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)
33 33
@@ -127,8 +106,26 @@ module Sources
#タイツ #タイツ
EOS EOS
assert_equal(%w[制作過程 このすば この素晴らしい世界に祝福を セナ バニー 3月3日 巨乳 黒髪巨乳 タイツ], source.tags.map(&:first)) strategy_should_work(
assert_nothing_raised { source.to_h } "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 end
should "Parse Pixiv Sketch URLs correctly" do should "Parse Pixiv Sketch URLs correctly" do
@@ -139,5 +136,4 @@ module Sources
assert(Source::URL.profile_url?("https://sketch.pixiv.net/@user_ejkv8372")) 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",
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 "without a referer" do context "A https://orig00.deviantart.net/* image url without the referer" do
should "use the base deviantart strategy" do strategy_should_work(
@site = Source::Extractor.find("https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png") "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. # 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. # 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) page_url: "https://www.deviantart.com/noizave/art/A-Pepe-763305148"
end )
end
end end
end end
end end