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

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

View File

@@ -17,7 +17,8 @@ module Sources
Strategies::Weibo,
Strategies::Newgrounds,
Strategies::Skeb,
Strategies::Lofter
Strategies::Lofter,
Strategies::Foundation,
]
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