Add Foundation support

This commit is contained in:
nonamethanks
2021-11-01 01:37:45 +01:00
parent 5946544f71
commit 043f2fb124
7 changed files with 148 additions and 2 deletions

View File

@@ -202,6 +202,8 @@ module IconHelper
image_icon_tag("fantia-logo.png", **options) image_icon_tag("fantia-logo.png", **options)
when "FC2" when "FC2"
image_icon_tag("fc2-logo.png", **options) image_icon_tag("fc2-logo.png", **options)
when "Foundation"
image_icon_tag("foundation-logo.png", **options)
when "Gumroad" when "Gumroad"
image_icon_tag("gumroad-logo.png", **options) image_icon_tag("gumroad-logo.png", **options)
when "Hentai Foundry" when "Hentai Foundry"

View File

@@ -47,6 +47,7 @@ module ArtistFinder
"fav.me", # http://fav.me/d9y1njg "fav.me", # http://fav.me/d9y1njg
/blog-imgs-\d+(?:-origin)?\.fc2\.com/i, /blog-imgs-\d+(?:-origin)?\.fc2\.com/i,
%r{blog\.fc2\.com(/\w)+/?}i, # http://blog71.fc2.com/a/abk00/file/20080220194219.jpg %r{blog\.fc2\.com(/\w)+/?}i, # http://blog71.fc2.com/a/abk00/file/20080220194219.jpg
"foundation.app",
"furaffinity.net", "furaffinity.net",
"furaffinity.net/user", # http://www.furaffinity.net/user/achthenuts "furaffinity.net/user", # http://www.furaffinity.net/user/achthenuts
"gelbooru.com", # http://gelbooru.com/index.php?page=account&s=profile&uname=junou "gelbooru.com", # http://gelbooru.com/index.php?page=account&s=profile&uname=junou

View File

@@ -17,7 +17,8 @@ module Sources
Strategies::Weibo, Strategies::Weibo,
Strategies::Newgrounds, Strategies::Newgrounds,
Strategies::Skeb, Strategies::Skeb,
Strategies::Lofter Strategies::Lofter,
Strategies::Foundation,
] ]
end end

View File

@@ -0,0 +1,96 @@
# Image URLs
# * https://f8n-ipfs-production.imgix.net/QmX4MotNAAj9Rcyew43KdgGDxU1QtXemMHoUTNacMLLSjQ/nft.png
#
# Page URLs
#
# * https://foundation.app/@mochiiimo/~/97376
#
# Profile URLs
#
# * https://foundation.app/@mochiiimo
module Sources
module Strategies
class Foundation < Base
BASE_URL = %r{\Ahttps?://(www\.)?foundation\.app}i
PROFILE_URL = %r{#{BASE_URL}/@(?<artist_name>\w+)}i
PAGE_URL = %r{#{PROFILE_URL}/~/(?<illust_id>\d+)}i
IMAGE_HOST = /f8n-ipfs-production\.imgix\.net/
IMAGE_URL = %r{\Ahttps?://#{IMAGE_HOST}/\w+/nft.\w+}i
def domains
["foundation.app"]
end
def match?
return false if parsed_url.nil?
parsed_url.domain.in?(domains) || parsed_url.host =~ IMAGE_HOST
end
def site_name
"Foundation"
end
def image_urls
return [url.gsub(/\?.*/, "")] if url =~ IMAGE_URL
page&.search("meta[property='og:image']").map do |img|
img["content"].gsub(/\?.*/, "")
end
end
def preview_urls
image_urls.map { |img| "#{img}?fit=fill&max-h=600" }
end
def page_url
urls.select { |url| url[PAGE_URL]}.compact.first
end
def page
return nil if page_url.blank?
response = http.cache(1.minute).get(page_url)
return nil unless response.status == 200
response.parse
end
def tags
tags = page&.search("a[href^='/tags/']").to_a
tags.map do |tag|
[tag.text, URI.join(page_url, tag.attr("href")).to_s]
end
end
def artist_name
urls.map { |u| u[PROFILE_URL, :artist_name] }.compact.first
end
def profile_url
return nil if artist_name.blank?
"https://foundation.app/@#{artist_name}"
end
def artist_commentary_title
return nil if page.blank?
page.at("meta[property='og:title']")["content"].gsub(/ \| Foundation$/, "")
end
def artist_commentary_desc
header = page&.xpath("//div[text()='Description']")&.first
return nil if header.blank?
header&.parent&.search("div").to_a.fetch(1, nil)&.to_html
end
def dtext_artist_commentary_desc
DText.from_html(artist_commentary_desc)
end
def normalize_for_source
page_url
end
end
end
end

View File

@@ -108,7 +108,7 @@ class ArtistUrl < ApplicationRecord
def priority def priority
sites = %w[ sites = %w[
Pixiv Twitter Pixiv Twitter
ArtStation BCY Deviant\ Art Hentai\ Foundry Nico\ Seiga Nijie pawoo.net Pixiv\ Fanbox Pixiv\ Sketch Tinami Tumblr ArtStation BCY Deviant\ Art Hentai\ Foundry Foundation Nico\ Seiga Nijie pawoo.net Pixiv\ Fanbox Pixiv\ Sketch Tinami Tumblr
Ask.fm Booth.pm Facebook Fantia FC2 Gumroad Instagram Ko-fi Livedoor Lofter Mihuashi Mixi.jp Patreon Piapro.jp Picarto Privatter Sakura.ne.jp Stickam Skeb Twitch Weibo Youtube Ask.fm Booth.pm Facebook Fantia FC2 Gumroad Instagram Ko-fi Livedoor Lofter Mihuashi Mixi.jp Patreon Piapro.jp Picarto Privatter Sakura.ne.jp Stickam Skeb Twitch Weibo Youtube
Amazon Circle.ms DLSite Doujinshi.org Erogamescape Mangaupdates Melonbooks Toranoana Wikipedia Amazon Circle.ms DLSite Doujinshi.org Erogamescape Mangaupdates Melonbooks Toranoana Wikipedia
] ]

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

View File

@@ -0,0 +1,46 @@
require "test_helper"
module Sources
class FoundationTest < ActiveSupport::TestCase
context "The source for a Foundation picture" do
setup do
@post_url = "https://foundation.app/@dadachyo/~/103724"
@image_url = "https://f8n-ipfs-production.imgix.net/QmPhpz6E9TFRpvdVTviM8Hy9o9rxrnPW5Ywj471NnSNkpi/nft.jpg"
@image1 = Sources::Strategies.find(@post_url)
@image2 = Sources::Strategies.find(@image_url)
end
should "get the artist name" do
assert_equal("dadachyo", @image1.artist_name)
end
should "get the artist commentary title" do
assert_equal("Rose tea", @image1.artist_commentary_title)
end
should "get profile url" do
assert_equal("https://foundation.app/@dadachyo", @image1.profile_url)
end
should "get the image url" do
assert_equal(@image_url, @image1.image_url)
assert_equal(@image_url, @image2.image_url)
end
should "download an image" do
assert_downloaded(13_908_349, @image1.image_url)
assert_downloaded(13_908_349, @image2.image_url)
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 }
end
end
end
end