Foundation: fix some video posts not being extracted

Also adjusts SourceTestHelper to not autogenerate contexts, so that
tests can be launched individually.
This commit is contained in:
nonamethanks
2022-04-21 17:50:10 +02:00
parent edb67b1b81
commit e6cb255a7a
6 changed files with 224 additions and 197 deletions

View File

@@ -11,7 +11,7 @@ module Source
def image_urls def image_urls
if parsed_url.full_image_url.present? if parsed_url.full_image_url.present?
[parsed_url.full_image_url] [parsed_url.full_image_url]
elsif image_url = page&.at(".fullscreen img, .fullscreen video")&.attr(:src) elsif (image_url = page&.at(".fullscreen img, .fullscreen video")&.attr(:src))
[Source::URL.parse(image_url).full_image_url].compact [Source::URL.parse(image_url).full_image_url].compact
else else
[] []

View File

@@ -11,8 +11,10 @@
class Source::URL::Foundation < Source::URL class Source::URL::Foundation < Source::URL
attr_reader :username, :token_id, :work_id, :hash attr_reader :username, :token_id, :work_id, :hash
IMAGE_HOSTS = %w[assets.foundation.app f8n-ipfs-production.imgix.net f8n-production-collection-assets.imgix.net d2ybmb80bbm9ts.cloudfront.net]
def self.match?(url) def self.match?(url)
url.host.in?(%w[foundation.app assets.foundation.app f8n-ipfs-production.imgix.net f8n-production-collection-assets.imgix.net]) url.host.in?(%w[foundation.app assets.foundation.app]) || url.host.in?(IMAGE_HOSTS)
end end
def parse def parse
@@ -52,12 +54,14 @@ class Source::URL::Foundation < Source::URL
@hash = hash @hash = hash
# https://f8n-production-collection-assets.imgix.net/0xFb0a8e1bB97fD7231Cd73c489dA4732Ae87995F0/4/nft.png # https://f8n-production-collection-assets.imgix.net/0xFb0a8e1bB97fD7231Cd73c489dA4732Ae87995F0/4/nft.png
in "f8n-production-collection-assets.imgix.net", token_id, work_id, file # https://assets.foundation.app/0x21Afa9aB02B6Fb7cb483ff3667c39eCdd6D9Ea73/4/nft.mp4
in ("f8n-production-collection-assets.imgix.net" | "assets.foundation.app"), /^0x\w{40}$/ => token_id, work_id, file
@token_id = token_id @token_id = token_id
@work_id = work_id @work_id = work_id
# https://assets.foundation.app/7i/gs/QmU8bbsjaVQpEKMDWbSZdDD6GsPmRYBhQtYRn8bEGv7igs/nft_q4.mp4 # https://assets.foundation.app/7i/gs/QmU8bbsjaVQpEKMDWbSZdDD6GsPmRYBhQtYRn8bEGv7igs/nft_q4.mp4
in "assets.foundation.app", *subdirs, hash, file # https://d2ybmb80bbm9ts.cloudfront.net/zd/BD/QmXiCEoBLcpfvpEwAEanLXe3Tjr5ykYJFzCVfpzDDQzdBD/nft_q4.mp4
in ("assets.foundation.app" | "d2ybmb80bbm9ts.cloudfront.net"), *subdirs, hash, file
@hash = hash @hash = hash
else else
@@ -74,7 +78,7 @@ class Source::URL::Foundation < Source::URL
def page_url def page_url
return nil unless work_id.present? return nil unless work_id.present?
return nil if host == "f8n-production-collection-assets.imgix.net" && @hash.blank? return nil if host.in?(IMAGE_HOSTS) && @hash.blank?
# https://f8n-production-collection-assets.imgix.net/0xAcf67a11D93D22bbB51fddD9B039d43d5Db484Bc/3/nft.png cannot be normalized to a correct page url # https://f8n-production-collection-assets.imgix.net/0xAcf67a11D93D22bbB51fddD9B039d43d5Db484Bc/3/nft.png cannot be normalized to a correct page url
username = @username || "foundation" username = @username || "foundation"
@@ -87,6 +91,8 @@ class Source::URL::Foundation < Source::URL
"https://f8n-ipfs-production.imgix.net/#{hash}/nft.#{file_ext}" "https://f8n-ipfs-production.imgix.net/#{hash}/nft.#{file_ext}"
elsif host == "f8n-production-collection-assets.imgix.net" && token_id.present? && work_id.present? && file_ext.present? elsif host == "f8n-production-collection-assets.imgix.net" && token_id.present? && work_id.present? && file_ext.present?
"https://f8n-production-collection-assets.imgix.net/#{token_id}/#{work_id}/nft.#{file_ext}" "https://f8n-production-collection-assets.imgix.net/#{token_id}/#{work_id}/nft.#{file_ext}"
elsif file_ext.present?
url.omit(:query).to_s
end end
end end

View File

@@ -4,51 +4,42 @@ module SourceTestHelper
# * If download_size is nil, it tests that the file is downloaded correctly, otherwise it also checks the filesize. # * If download_size is nil, it tests that the file is downloaded correctly, otherwise it also checks the filesize.
# * If deleted is true, it skips the downloading check, but it still tries everything else and makes sure nothing breaks. # * If deleted is true, it skips the downloading check, but it still tries everything else and makes sure nothing breaks.
# * Any passed kwargs parameter is tested against the strategy. # * Any passed kwargs parameter is tested against the strategy.
def strategy_should_work(url, referer: nil, download_size: nil, deleted: false, **methods_to_test)
context "a strategy for #{url}#{", referer: #{referer}" if referer.present?}".chomp do
strategy = Source::Extractor.find(url, referer)
should "not raise anything" do def strategy_should_work(url, arguments)
assert_nothing_raised { strategy.to_h } # XXX: can't use **kwargs because of a bug with shoulda-context
end referer, download_size, deleted = [:referer, :download_size, :deleted].map { |arg| arguments.delete(arg) }
should "make sure that image_urls is an array of valid elements" do strategy = Source::Extractor.find(url, referer)
assert((strategy.image_urls.instance_of? Array))
assert_not(strategy.image_urls.include?(nil))
end
should_download_successfully(strategy, download_size) unless deleted should "not raise anything" do
assert_nothing_raised { strategy.to_h }
# {profile_url: nil}[:profile_url].present? -> false
# Doing it this way instead we can check profile_url even if it's passed as a nil.
if methods_to_test.include? :profile_url
profile_url = methods_to_test.delete(:profile_url)
should_handle_artists_correctly(strategy, profile_url)
end
tags = methods_to_test.delete(:tags)
should_validate_tags(strategy, tags)
# check any method that is passed as kwargs, in order to hardcode as few thingss as possible
methods_to_test.each do |method_name, expected_value|
should "make sure that '#{method_name}' matches" do
if expected_value.instance_of? Regexp
assert_match(expected_value, strategy.try(method_name))
elsif expected_value.nil?
assert_nil(strategy.try(method_name))
else
assert_equal(expected_value, strategy.try(method_name))
end
end
end
end end
should "make sure that image_urls is an array of valid elements" do
assert((strategy.image_urls.instance_of? Array))
assert_not(strategy.image_urls.include?(nil))
end
should_download_successfully(strategy, download_size) unless deleted
# {profile_url: nil}[:profile_url].present? -> false
# Doing it this way instead we can check profile_url even if it's passed as a nil.
if arguments.include? :profile_url
profile_url = arguments.delete(:profile_url)
should_handle_artists_correctly(strategy, profile_url)
end
tags = arguments.delete(:tags)
should_validate_tags(strategy, tags)
should_match_source_data(strategy, arguments)
end end
def should_download_successfully(strategy, download_size = nil) def should_download_successfully(strategy, download_size = nil)
should "download successfully" do should "download successfully" do
file = strategy.download_file!(strategy.image_urls.first) file = strategy.download_file!(strategy.image_urls.first)
if download_size.present? if download_size.present?
assert_equal(expected_filesize, file.size) assert_equal(download_size, file.size)
else else
assert_not_nil(file.size) assert_not_nil(file.size)
end end
@@ -90,4 +81,21 @@ module SourceTestHelper
end end
end end
def should_match_source_data(strategy, methods_to_test)
# check any method that is passed as kwargs, in order to hardcode as few things as possible
# XXX can't use **kwargs because of a bug with shoulda-context, so we're using a hash temporarily
methods_to_test.each do |method_name, expected_value|
should "make sure that '#{method_name}' matches" do
if expected_value.instance_of? Regexp
assert_match(expected_value, strategy.try(method_name))
elsif expected_value.instance_of? Array
assert_equal(expected_value.sort, strategy.try(method_name).sort)
elsif expected_value.nil?
assert_nil(strategy.try(method_name))
else
assert_equal(expected_value, strategy.try(method_name))
end
end
end
end
end end

View File

@@ -2,42 +2,50 @@ require "test_helper"
module Sources module Sources
class AniftyTest < ActiveSupport::TestCase class AniftyTest < ActiveSupport::TestCase
strategy_should_work( context "An anifty post" do
"https://anifty.jp/ja/creations/1500", strategy_should_work(
image_urls: ["https://storage.googleapis.com/anifty-media/creation/0x0913be22dd08f7e092e00d4f8c2f61778dc6df94/a5bb2c63b8a602aba6cfd93d2147bef23b6b9bc2.jpg"], "https://anifty.jp/ja/creations/1500",
profile_url: "https://anifty.jp/@inamihatoko", image_urls: ["https://storage.googleapis.com/anifty-media/creation/0x0913be22dd08f7e092e00d4f8c2f61778dc6df94/a5bb2c63b8a602aba6cfd93d2147bef23b6b9bc2.jpg"],
page_url: "https://anifty.jp/creations/1500", profile_url: "https://anifty.jp/@inamihatoko",
artist_name: "inami hatoko", page_url: "https://anifty.jp/creations/1500",
other_names: ["inamihatoko", "井波ハトコ"], artist_name: "inami hatoko",
tags: ["background", "girl"], other_names: ["inamihatoko", "井波ハトコ"],
artist_commentary_title: "Escape", tags: ["background", "girl"],
artist_commentary_desc: "Let's get out of there." artist_commentary_title: "Escape",
) artist_commentary_desc: "Let's get out of there."
)
end
strategy_should_work( context "An anifty image hosted on imgix" do
"https://anifty.imgix.net/creation/0x9942a21fdc78fe2c3973d219a1d705a4efd056b4/22f4c9694dd2f1f32b610d1d75a18621c5c2d6d8.jpg?w=3840&q=undefined&auto=compress", strategy_should_work(
image_urls: ["https://storage.googleapis.com/anifty-media/creation/0x9942a21fdc78fe2c3973d219a1d705a4efd056b4/22f4c9694dd2f1f32b610d1d75a18621c5c2d6d8.jpg"], "https://anifty.imgix.net/creation/0x9942a21fdc78fe2c3973d219a1d705a4efd056b4/22f4c9694dd2f1f32b610d1d75a18621c5c2d6d8.jpg?w=3840&q=undefined&auto=compress",
profile_url: "https://anifty.jp/@unagi189", image_urls: ["https://storage.googleapis.com/anifty-media/creation/0x9942a21fdc78fe2c3973d219a1d705a4efd056b4/22f4c9694dd2f1f32b610d1d75a18621c5c2d6d8.jpg"],
page_url: "https://anifty.jp/creations/1585", profile_url: "https://anifty.jp/@unagi189",
artist_name: "yunagi", page_url: "https://anifty.jp/creations/1585",
other_names: ["unagi189", "夕凪"], artist_name: "yunagi",
tags: ["background", "girl", "uniform"], other_names: ["unagi189", "夕凪"],
artist_commentary_title: "Sound!", tags: ["background", "girl", "uniform"],
artist_commentary_desc: "This work was created in 2017 and partially modified for exhibition.I created this work with the image of after-school for the girls in the brass band." artist_commentary_title: "Sound!",
) artist_commentary_desc: "This work was created in 2017 and partially modified for exhibition.I created this work with the image of after-school for the girls in the brass band."
)
end
strategy_should_work( context "An anifty image hosted on googleapis" do
"https://storage.googleapis.com/anifty-media/profile/0x961d09077b4a9f7a27f6b7ee78cb4c26f0e72c18/a6d2c366a3e876ddbf04fc269b63124be18af424.png", strategy_should_work(
image_urls: ["https://storage.googleapis.com/anifty-media/profile/0x961d09077b4a9f7a27f6b7ee78cb4c26f0e72c18/a6d2c366a3e876ddbf04fc269b63124be18af424.png"], "https://storage.googleapis.com/anifty-media/profile/0x961d09077b4a9f7a27f6b7ee78cb4c26f0e72c18/a6d2c366a3e876ddbf04fc269b63124be18af424.png",
profile_url: "https://anifty.jp/@hightree", image_urls: ["https://storage.googleapis.com/anifty-media/profile/0x961d09077b4a9f7a27f6b7ee78cb4c26f0e72c18/a6d2c366a3e876ddbf04fc269b63124be18af424.png"],
page_url: nil, profile_url: "https://anifty.jp/@hightree",
artist_name: "Knoy Konome", page_url: nil,
other_names: ["hightree", "木芽のい"], artist_name: "Knoy Konome",
tags: [], other_names: ["hightree", "木芽のい"],
artist_commentary_title: nil, tags: [],
artist_commentary_desc: nil artist_commentary_title: nil,
) artist_commentary_desc: nil
)
end
strategy_should_work("https://anifty.jp/zh/creations/373123123", deleted: true, profile_url: nil) context "A deleted or non-existing anifty post" do
strategy_should_work("https://anifty.jp/zh/creations/373123123", deleted: true, profile_url: nil)
end
end end
end end

View File

@@ -2,59 +2,71 @@ require "test_helper"
module Sources module Sources
class BoothTest < ActiveSupport::TestCase class BoothTest < ActiveSupport::TestCase
standard_url_images = %w[ context "A booth post" do
https://booth.pximg.net/a212cd73-75ab-482d-8fce-1ce2965e4d4f/i/3713604/ae0fdbcf-e4c5-4840-8d5c-43e18bddc93e.jpg images = %w[
https://booth.pximg.net/a212cd73-75ab-482d-8fce-1ce2965e4d4f/i/3713604/d12bce50-a0c7-43f8-a4fb-5ee0ea6855a3.jpg https://booth.pximg.net/a212cd73-75ab-482d-8fce-1ce2965e4d4f/i/3713604/ae0fdbcf-e4c5-4840-8d5c-43e18bddc93e.jpg
https://booth.pximg.net/a212cd73-75ab-482d-8fce-1ce2965e4d4f/i/3713604/f5332da3-4097-4d33-bbf6-a9b64c7671b3.jpg https://booth.pximg.net/a212cd73-75ab-482d-8fce-1ce2965e4d4f/i/3713604/d12bce50-a0c7-43f8-a4fb-5ee0ea6855a3.jpg
] https://booth.pximg.net/a212cd73-75ab-482d-8fce-1ce2965e4d4f/i/3713604/f5332da3-4097-4d33-bbf6-a9b64c7671b3.jpg
strategy_should_work( ]
"https://booth.pm/en/items/3713604", strategy_should_work(
image_urls: standard_url_images, "https://booth.pm/en/items/3713604",
profile_url: "https://amedamacon.booth.pm", image_urls: images,
page_url: "https://booth.pm/en/items/3713604", profile_url: "https://amedamacon.booth.pm",
artist_name: "amedamacon", page_url: "https://booth.pm/en/items/3713604",
other_names: ["あめうさぎBOOTH"], artist_name: "amedamacon",
tags: [["抱き枕カバー", "https://booth.pm/en/browse/Pillow%20Cover?tags%5B%5D=%E6%8A%B1%E3%81%8D%E6%9E%95%E3%82%AB%E3%83%90%E3%83%BC"]], other_names: ["あめうさぎBOOTH"],
artist_commentary_title: "フユちゃん抱き枕カバー", tags: [["抱き枕カバー", "https://booth.pm/en/browse/Pillow%20Cover?tags%5B%5D=%E6%8A%B1%E3%81%8D%E6%9E%95%E3%82%AB%E3%83%90%E3%83%BC"]],
dtext_artist_commentary_desc: /発送6月上旬頃BOOTH倉庫より発送/ artist_commentary_title: "フユちゃん抱き枕カバー",
) dtext_artist_commentary_desc: /発送6月上旬頃BOOTH倉庫より発送/
)
end
strategy_should_work( context "A booth image" do
"https://booth.pximg.net/a212cd73-75ab-482d-8fce-1ce2965e4d4f/i/3713604/d12bce50-a0c7-43f8-a4fb-5ee0ea6855a3_base_resized.jpg", strategy_should_work(
image_urls: [standard_url_images.second], "https://booth.pximg.net/a212cd73-75ab-482d-8fce-1ce2965e4d4f/i/3713604/d12bce50-a0c7-43f8-a4fb-5ee0ea6855a3_base_resized.jpg",
profile_url: "https://amedamacon.booth.pm", image_urls: ["https://booth.pximg.net/a212cd73-75ab-482d-8fce-1ce2965e4d4f/i/3713604/d12bce50-a0c7-43f8-a4fb-5ee0ea6855a3.jpg"],
page_url: "https://booth.pm/en/items/3713604", profile_url: "https://amedamacon.booth.pm",
artist_name: "amedamacon", page_url: "https://booth.pm/en/items/3713604",
other_names: ["あめうさぎBOOTH"], artist_name: "amedamacon",
tags: [["抱き枕カバー", "https://booth.pm/en/browse/Pillow%20Cover?tags%5B%5D=%E6%8A%B1%E3%81%8D%E6%9E%95%E3%82%AB%E3%83%90%E3%83%BC"]], other_names: ["あめうさぎBOOTH"],
artist_commentary_title: "フユちゃん抱き枕カバー", tags: [["抱き枕カバー", "https://booth.pm/en/browse/Pillow%20Cover?tags%5B%5D=%E6%8A%B1%E3%81%8D%E6%9E%95%E3%82%AB%E3%83%90%E3%83%BC"]],
dtext_artist_commentary_desc: /発送6月上旬頃BOOTH倉庫より発送/ artist_commentary_title: "フユちゃん抱き枕カバー",
) dtext_artist_commentary_desc: /発送6月上旬頃BOOTH倉庫より発送/
)
end
strategy_should_work( context "A booth post with artist name in the url" do
"https://re-face.booth.pm/items/2423989", strategy_should_work(
image_urls: ["https://booth.pximg.net/8bb9e4e3-d171-4027-88df-84480480f79d/i/2423989/a692d4f3-4371-4a86-a337-83fee82d46a4.png"], "https://re-face.booth.pm/items/2423989",
profile_url: "https://re-face.booth.pm", image_urls: ["https://booth.pximg.net/8bb9e4e3-d171-4027-88df-84480480f79d/i/2423989/a692d4f3-4371-4a86-a337-83fee82d46a4.png"],
page_url: "https://booth.pm/en/items/2423989", profile_url: "https://re-face.booth.pm",
artist_name: "re-face", page_url: "https://booth.pm/en/items/2423989",
other_names: ["Re:fAce/りふぇいす。"], artist_name: "re-face",
tags: ["original"], other_names: ["Re:fAce/りふぇいす。"],
artist_commentary_title: "RwithV vol.1 -アイドルはじめます!-", tags: ["original"],
dtext_artist_commentary_desc: /注文が殺到した際は、発送が遅れてしまう場合もございますので予めご了承ください。/ artist_commentary_title: "RwithV vol.1 -アイドルはじめます!-",
) dtext_artist_commentary_desc: /注文が殺到した際は、発送が遅れてしまう場合もございますので予めご了承ください。/
)
end
strategy_should_work( context "A profile background picture" do
"https://s2.booth.pm/8bb9e4e3-d171-4027-88df-84480480f79d/3d70de06-8e7c-444e-b8eb-a8a95bf20638_base_resized.jpg", strategy_should_work(
image_urls: ["https://s2.booth.pm/8bb9e4e3-d171-4027-88df-84480480f79d/3d70de06-8e7c-444e-b8eb-a8a95bf20638.png"], "https://s2.booth.pm/8bb9e4e3-d171-4027-88df-84480480f79d/3d70de06-8e7c-444e-b8eb-a8a95bf20638_base_resized.jpg",
profile_url: nil image_urls: ["https://s2.booth.pm/8bb9e4e3-d171-4027-88df-84480480f79d/3d70de06-8e7c-444e-b8eb-a8a95bf20638.png"],
) profile_url: nil
)
end
strategy_should_work( context "A profile icon" do
"https://booth.pximg.net/c/128x128/users/3193929/icon_image/5be9eff4-1d9e-4a79-b097-33c1cd4ad314_base_resized.jpg", strategy_should_work(
image_urls: ["https://booth.pximg.net/users/3193929/icon_image/5be9eff4-1d9e-4a79-b097-33c1cd4ad314.png"], "https://booth.pximg.net/c/128x128/users/3193929/icon_image/5be9eff4-1d9e-4a79-b097-33c1cd4ad314_base_resized.jpg",
profile_url: nil image_urls: ["https://booth.pximg.net/users/3193929/icon_image/5be9eff4-1d9e-4a79-b097-33c1cd4ad314.png"],
) profile_url: nil
)
end
strategy_should_work("https://booth.pm/en/items/2003079", deleted: true) context "A non-existing or deleted post" do
strategy_should_work("https://booth.pm/en/items/2003079", deleted: true)
end
end end
end end

View File

@@ -2,97 +2,90 @@ require "test_helper"
module Sources module Sources
class FoundationTest < ActiveSupport::TestCase class FoundationTest < ActiveSupport::TestCase
context "The source for a Foundation picture" do context "A foundation post" do
setup do strategy_should_work(
@post_url = "https://foundation.app/@dadachyo/~/103724" "https://foundation.app/@dadachyo/~/103724",
@post_with_video = "https://foundation.app/@huwari/~/88982" download_size: 13_908_349,
@image_url = "https://f8n-ipfs-production.imgix.net/QmPhpz6E9TFRpvdVTviM8Hy9o9rxrnPW5Ywj471NnSNkpi/nft.jpg" image_urls: ["https://f8n-ipfs-production.imgix.net/QmPhpz6E9TFRpvdVTviM8Hy9o9rxrnPW5Ywj471NnSNkpi/nft.jpg"],
@image1 = Source::Extractor.find(@post_url) artist_commentary_title: "Rose tea",
@image2 = Source::Extractor.find(@image_url) artist_name: "dadachyo",
@image3 = Source::Extractor.find(@post_with_video) profile_url: "https://foundation.app/@dadachyo",
end profile_urls: ["https://foundation.app/0xb4D9073800c7935351ACDC1e46F0CF670853eA99", "https://foundation.app/@dadachyo"],
tags: %w[dadachyo rose 2018 matcrewnft]
should "get the artist name" do )
assert_equal("dadachyo", @image1.artist_name)
assert_equal("huwari", @image3.artist_name)
end
should "get the artist commentary title" do
assert_equal("Rose tea", @image1.artist_commentary_title)
assert_equal("bus", @image3.artist_commentary_title)
end
should "get profile url" do
assert_equal("https://foundation.app/@dadachyo", @image1.profile_url)
assert_equal(["https://foundation.app/@dadachyo", "https://foundation.app/0xb4D9073800c7935351ACDC1e46F0CF670853eA99"], @image1.profile_urls)
assert_equal("https://foundation.app/@huwari", @image3.profile_url)
assert_equal(["https://foundation.app/@huwari", "https://foundation.app/0xaa2f2eDE4D502F59b3706d2E2dA873C8A00A3d4d"], @image3.profile_urls)
end
should "get the image url" do
assert_equal([@image_url], @image1.image_urls)
assert_equal([@image_url], @image2.image_urls)
end
should "download an image" do
assert_downloaded(13_908_349, @image1.image_urls.sole)
assert_downloaded(13_908_349, @image2.image_urls.sole)
assert_downloaded(13_391_766, @image3.image_urls.sole)
end
should "find the correct artist" do
@artist = FactoryBot.create(:artist, name: "dadachyo", url_string: @image1.profile_url)
assert_equal([@artist], @image1.artists)
end
should "not raise errors" do
assert_nothing_raised { @image1.to_h }
assert_nothing_raised { @image2.to_h }
assert_nothing_raised { @image3.to_h }
end
end end
context "for a foundation.app/@username/foo-bar-1234 URL" do context "A foundation image url" do
should "work" do strategy_should_work(
page_url = "https://foundation.app/@asuka111art/dinner-with-cats-82426" "https://f8n-ipfs-production.imgix.net/QmPhpz6E9TFRpvdVTviM8Hy9o9rxrnPW5Ywj471NnSNkpi/nft.jpg",
image_url = "https://f8n-ipfs-production.imgix.net/Qma7Lz2LfFb4swoqzr1V43oRGh9xikgigM11g3EukdU61R/nft.png" image_urls: ["https://f8n-ipfs-production.imgix.net/QmPhpz6E9TFRpvdVTviM8Hy9o9rxrnPW5Ywj471NnSNkpi/nft.jpg"],
source = Source::Extractor.find(page_url) download_size: 13_908_349
)
assert_equal("asuka111art", source.artist_name)
assert_equal(["https://foundation.app/@asuka111art", "https://foundation.app/0x9A94f94626352566e0A9105F1e3DA0439E3e3783"], source.profile_urls)
assert_equal([image_url], source.image_urls)
assert_equal(%w[2d anime illustration digital fantasy], source.tags.map(&:first))
end
end end
context "for a f8n-production-collection-assets.imgix.net URL" do context "A foundation.app/@username/foo-bar-1234 URL" do
should "work" do strategy_should_work(
image_url = "https://f8n-production-collection-assets.imgix.net/0x3B3ee1931Dc30C1957379FAc9aba94D1C48a5405/128711/QmcBfbeCMSxqYB3L1owPAxFencFx3jLzCPFx6xUBxgSCkH/nft.png?q=80&auto=format%2Ccompress&cs=srgb&h=640" "https://foundation.app/@asuka111art/dinner-with-cats-82426",
source = Source::Extractor.find(image_url) image_urls: ["https://f8n-ipfs-production.imgix.net/Qma7Lz2LfFb4swoqzr1V43oRGh9xikgigM11g3EukdU61R/nft.png"],
artist_name: "asuka111art",
assert_equal("mochiiimo", source.artist_name) profile_url: "https://foundation.app/@asuka111art",
assert_equal(["https://foundation.app/@mochiiimo", "https://foundation.app/0x7E2ef75C0C09b2fc6BCd1C68B6D409720CcD58d2"], source.profile_urls) profile_urls: ["https://foundation.app/@asuka111art", "https://foundation.app/0x9A94f94626352566e0A9105F1e3DA0439E3e3783"],
assert_equal(["https://f8n-ipfs-production.imgix.net/QmcBfbeCMSxqYB3L1owPAxFencFx3jLzCPFx6xUBxgSCkH/nft.png"], source.image_urls) tags: %w[2d anime illustration digital fantasy]
assert_equal(%w[anime landscape girl cat 2d illustration matcrewnft], source.tags.map(&:first)) )
end
end end
context "for a collection" do context "A f8n-production-collection-assets.imgix.net URL" do
strategy_should_work(
"https://f8n-production-collection-assets.imgix.net/0x3B3ee1931Dc30C1957379FAc9aba94D1C48a5405/128711/QmcBfbeCMSxqYB3L1owPAxFencFx3jLzCPFx6xUBxgSCkH/nft.png?q=80&auto=format%2Ccompress&cs=srgb&h=640",
image_urls: ["https://f8n-ipfs-production.imgix.net/QmcBfbeCMSxqYB3L1owPAxFencFx3jLzCPFx6xUBxgSCkH/nft.png"],
artist_name: "mochiiimo",
profile_url: "https://foundation.app/@mochiiimo",
profile_urls: ["https://foundation.app/0x7E2ef75C0C09b2fc6BCd1C68B6D409720CcD58d2", "https://foundation.app/@mochiiimo"],
tags: %w[anime landscape girl cat 2d illustration matcrewnft]
)
end
context "A foundation post with a video hosted on imgix" do
strategy_should_work(
"https://foundation.app/@huwari/~/88982",
image_urls: ["https://f8n-ipfs-production.imgix.net/QmU8bbsjaVQpEKMDWbSZdDD6GsPmRYBhQtYRn8bEGv7igs/nft.mp4"],
download_size: 13_391_766,
artist_name: "huwari",
profile_url: "https://foundation.app/@huwari",
profile_urls: ["https://foundation.app/@huwari", "https://foundation.app/0xaa2f2eDE4D502F59b3706d2E2dA873C8A00A3d4d"],
artist_commentary_title: "bus"
)
end
context "A foundation post with a video hosted on foundation" do
strategy_should_work(
"https://foundation.app/@mcbess/ladies/4",
image_urls: ["https://assets.foundation.app/0x21Afa9aB02B6Fb7cb483ff3667c39eCdd6D9Ea73/4/nft.mp4"]
)
end
context "A foundation post with a video hosted on cloudfront" do
strategy_should_work(
"https://foundation.app/@nixeu/foundation/109126",
image_urls: ["https://f8n-ipfs-production.imgix.net/QmXiCEoBLcpfvpEwAEanLXe3Tjr5ykYJFzCVfpzDDQzdBD/nft.mp4"]
)
end
context "A collection" do
should "get the image urls" do should "get the image urls" do
assert_equal( assert_equal(
["https://f8n-ipfs-production.imgix.net/QmX4MotNAAj9Rcyew43KdgGDxU1QtXemMHoUTNacMLLSjQ/nft.png"], ["https://f8n-ipfs-production.imgix.net/QmX4MotNAAj9Rcyew43KdgGDxU1QtXemMHoUTNacMLLSjQ/nft.png"],
Source::Extractor.find("https://foundation.app/@mochiiimo/~/97376").image_urls, Source::Extractor.find("https://foundation.app/@mochiiimo/~/97376").image_urls
) )
assert_equal( assert_equal(
["https://f8n-ipfs-production.imgix.net/QmX4MotNAAj9Rcyew43KdgGDxU1QtXemMHoUTNacMLLSjQ/nft.png"], ["https://f8n-ipfs-production.imgix.net/QmX4MotNAAj9Rcyew43KdgGDxU1QtXemMHoUTNacMLLSjQ/nft.png"],
Source::Extractor.find("https://foundation.app/@mochiiimo/foundation/97376").image_urls, Source::Extractor.find("https://foundation.app/@mochiiimo/foundation/97376").image_urls
) )
assert_equal( assert_equal(
["https://f8n-production-collection-assets.imgix.net/0xFb0a8e1bB97fD7231Cd73c489dA4732Ae87995F0/4/nft.png"], ["https://f8n-production-collection-assets.imgix.net/0xFb0a8e1bB97fD7231Cd73c489dA4732Ae87995F0/4/nft.png"],
Source::Extractor.find("https://foundation.app/@KILLERGF/kgfgen/4").image_urls, Source::Extractor.find("https://foundation.app/@KILLERGF/kgfgen/4").image_urls
) )
end end
end end