sources: factor out Source::URL::HentaiFoundry.
Add support for these URL types: * http://pictures.hentai-foundry.com//s/soranamae/363663.jpg * http://www.hentai-foundry.com/piccies/d/dmitrys/1183.jpg * http://www.hentai-foundry.com/pic-149160.php * http://www.hentai-foundry.com/user-RockCandy.php * http://www.hentai-foundry.com/profile-sawao.php These URL types are obsolete, but still present in some old posts.
This commit is contained in:
@@ -19,6 +19,7 @@ module Source
|
|||||||
class URL < Danbooru::URL
|
class URL < Danbooru::URL
|
||||||
SUBCLASSES = [
|
SUBCLASSES = [
|
||||||
Source::URL::Twitter,
|
Source::URL::Twitter,
|
||||||
|
Source::URL::HentaiFoundry,
|
||||||
Source::URL::Plurk,
|
Source::URL::Plurk,
|
||||||
Source::URL::Skeb,
|
Source::URL::Skeb,
|
||||||
Source::URL::TwitPic,
|
Source::URL::TwitPic,
|
||||||
@@ -54,7 +55,7 @@ module Source
|
|||||||
|
|
||||||
# @return [String, nil] The name of the site this URL belongs to, or possibly nil if unknown.
|
# @return [String, nil] The name of the site this URL belongs to, or possibly nil if unknown.
|
||||||
def site_name
|
def site_name
|
||||||
self.class.name.demodulize
|
self.class.name.demodulize.titleize
|
||||||
end
|
end
|
||||||
|
|
||||||
protected def initialize(...)
|
protected def initialize(...)
|
||||||
|
|||||||
96
app/logical/source/url/hentai_foundry.rb
Normal file
96
app/logical/source/url/hentai_foundry.rb
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Image URLs
|
||||||
|
#
|
||||||
|
# * http://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png
|
||||||
|
# * http://pictures.hentai-foundry.com/_/-MadKaiser-/532792/-MadKaiser--532792-FFXIV_Miqote.png
|
||||||
|
# * http://pictures.hentai-foundry.com/p/PalomaP/855497/PalomaP-855497-Boooo..._bs..jpg
|
||||||
|
# * http://pictures.hentai-foundry.com//s/soranamae/363663.jpg
|
||||||
|
# * http://www.hentai-foundry.com/piccies/d/dmitrys/1183.jpg
|
||||||
|
#
|
||||||
|
# Page URLs
|
||||||
|
#
|
||||||
|
# * http://www.hentai-foundry.com/pictures/user/Afrobull/795025
|
||||||
|
# * http://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda
|
||||||
|
# * http://www.hentai-foundry.com/pictures/user/Ganassa/457176/LOL-Swimsuit---Caitlyn-reworked-nude-ver.
|
||||||
|
# * http://www.hentai-foundry.com/pic-795025
|
||||||
|
# * http://www.hentai-foundry.com/pic-149160.html
|
||||||
|
# * http://www.hentai-foundry.com/pic-149160.php
|
||||||
|
# * http://www.hentai-foundry.com/pic_full-66045.php
|
||||||
|
#
|
||||||
|
# Preview URLs
|
||||||
|
#
|
||||||
|
# * https://thumbs.hentai-foundry.com/thumb.php?pid=795025&size=350
|
||||||
|
#
|
||||||
|
# Profile URLs
|
||||||
|
#
|
||||||
|
# * https://www.hentai-foundry.com/user/kajinman/profile
|
||||||
|
# * https://www.hentai-foundry.com/pictures/user/kajinman
|
||||||
|
# * https://www.hentai-foundry.com/pictures/user/kajinman/scraps
|
||||||
|
# * https://www.hentai-foundry.com/user/J-likes-to-draw/profile
|
||||||
|
# * http://www.hentai-foundry.com/user-RockCandy.php
|
||||||
|
# * http://www.hentai-foundry.com/profile-sawao.php
|
||||||
|
#
|
||||||
|
class Source::URL::HentaiFoundry < Source::URL
|
||||||
|
attr_reader :username, :work_id
|
||||||
|
|
||||||
|
def self.match?(url)
|
||||||
|
url.domain == "hentai-foundry.com"
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse
|
||||||
|
case [host, *path_segments]
|
||||||
|
|
||||||
|
# https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png
|
||||||
|
# https://pictures.hentai-foundry.com/_/-MadKaiser-/532792/-MadKaiser--532792-FFXIV_Miqote.png
|
||||||
|
in "pictures.hentai-foundry.com", _, username, /^\d+$/ => work_id, slug
|
||||||
|
@username = username
|
||||||
|
@work_id = work_id
|
||||||
|
|
||||||
|
# http://pictures.hentai-foundry.com//s/soranamae/363663.jpg
|
||||||
|
in "pictures.hentai-foundry.com", _, username, /^\d+\.\w+$/ => filename
|
||||||
|
@username = username
|
||||||
|
@work_id, @file_ext = filename.split(".")
|
||||||
|
|
||||||
|
# http://www.hentai-foundry.com/piccies/d/dmitrys/1183.jpg
|
||||||
|
in "www.hentai-foundry.com", "piccies", _, username, /^\d+\.\w+$/ => filename
|
||||||
|
@username = username
|
||||||
|
@work_id, @file_ext = filename.split(".")
|
||||||
|
|
||||||
|
# https://www.hentai-foundry.com/pictures/user/Afrobull/795025
|
||||||
|
# https://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda
|
||||||
|
in "www.hentai-foundry.com", "pictures", "user", username, /^\d+$/ => work_id, *slug
|
||||||
|
@username = username
|
||||||
|
@work_id = work_id
|
||||||
|
|
||||||
|
# http://www.hentai-foundry.com/pic-795025
|
||||||
|
# http://www.hentai-foundry.com/pic-149160.html
|
||||||
|
# http://www.hentai-foundry.com/pic-149160.php
|
||||||
|
# http://www.hentai-foundry.com/pic_full-66045.php
|
||||||
|
in "www.hentai-foundry.com", /^pic\w*-(\d+)/
|
||||||
|
@work_id = $1
|
||||||
|
|
||||||
|
# https://thumbs.hentai-foundry.com/thumb.php?pid=795025&size=350
|
||||||
|
in "thumbs.hentai-foundry.com", "thumb.php" if params[:pid].present?
|
||||||
|
@work_id = params[:pid]
|
||||||
|
|
||||||
|
# https://www.hentai-foundry.com/user/kajinman
|
||||||
|
# https://www.hentai-foundry.com/user/kajinman/profile
|
||||||
|
# https://www.hentai-foundry.com/user/J-likes-to-draw/profile
|
||||||
|
in "www.hentai-foundry.com", "user", username, *slug
|
||||||
|
@username = username
|
||||||
|
|
||||||
|
# https://www.hentai-foundry.com/pictures/user/kajinman
|
||||||
|
# https://www.hentai-foundry.com/pictures/user/kajinman/scraps
|
||||||
|
in "www.hentai-foundry.com", "pictures", "user", username, *slug
|
||||||
|
@username = username
|
||||||
|
|
||||||
|
# http://www.hentai-foundry.com/user-RockCandy.php
|
||||||
|
# http://www.hentai-foundry.com/profile-sawao.php
|
||||||
|
in "www.hentai-foundry.com", /^(?:user|profile)-([^.]+)\.php$/
|
||||||
|
@username = $1
|
||||||
|
|
||||||
|
else
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -28,6 +28,10 @@ class Source::URL::TwitPic < Source::URL
|
|||||||
url.host.in?(%w[twitpic.com o.twimg.com dn3pm25xmtlyu.cloudfront.net d3j5vwomefv46c.cloudfront.net])
|
url.host.in?(%w[twitpic.com o.twimg.com dn3pm25xmtlyu.cloudfront.net d3j5vwomefv46c.cloudfront.net])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def site_name
|
||||||
|
"TwitPic"
|
||||||
|
end
|
||||||
|
|
||||||
def parse
|
def parse
|
||||||
case [domain, *path_segments]
|
case [domain, *path_segments]
|
||||||
|
|
||||||
|
|||||||
@@ -1,42 +1,17 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Image URLs
|
# @see Source::URL::HentaiFoundry
|
||||||
#
|
|
||||||
# * https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png
|
|
||||||
#
|
|
||||||
# Page URLs
|
|
||||||
#
|
|
||||||
# * https://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda
|
|
||||||
# * https://www.hentai-foundry.com/pictures/user/Afrobull/795025
|
|
||||||
# * http://www.hentai-foundry.com/pic-795025
|
|
||||||
# * http://www.hentai-foundry.com/pictures/user/Ganassa/457176/LOL-Swimsuit---Caitlyn-reworked-nude-ver.
|
|
||||||
#
|
|
||||||
# Preview URLs
|
|
||||||
#
|
|
||||||
# * https://thumbs.hentai-foundry.com/thumb.php?pid=795025&size=350
|
|
||||||
#
|
|
||||||
# Profile URLs
|
|
||||||
#
|
|
||||||
# * https://www.hentai-foundry.com/user/kajinman/profile
|
|
||||||
# * https://www.hentai-foundry.com/pictures/user/kajinman
|
|
||||||
# * https://www.hentai-foundry.com/pictures/user/kajinman/scraps
|
|
||||||
# * https://www.hentai-foundry.com/user/J-likes-to-draw/profile
|
|
||||||
|
|
||||||
module Sources
|
module Sources
|
||||||
module Strategies
|
module Strategies
|
||||||
class HentaiFoundry < Base
|
class HentaiFoundry < Base
|
||||||
BASE_URL = %r{\Ahttps?://(?:www\.)?hentai-foundry\.com}i
|
extend Memoist
|
||||||
PAGE_URL = %r{#{BASE_URL}/pictures/user/(?<artist_name>[\w-]+)/(?<illust_id>\d+)(?:/[\w.-]*)?(\?[\w=]*)?\z}i
|
|
||||||
OLD_PAGE = %r{#{BASE_URL}/pic-(?<illust_id>\d+)(?:\.html)?\z}i
|
|
||||||
PROFILE_URL = %r{#{BASE_URL}/(?:pictures/)?user/(?<artist_name>[\w-]+)(?:/[a-z]*)?\z}i
|
|
||||||
IMAGE_URL = %r{\Ahttps?://pictures\.hentai-foundry\.com/+\w/(?<artist_name>[\w-]+)/(?<illust_id>\d+)(?:(?:/[\w.-]+)?\.\w+)?\z}i
|
|
||||||
|
|
||||||
def domains
|
def match?
|
||||||
["hentai-foundry.com"]
|
parsed_url&.site_name == "Hentai Foundry"
|
||||||
end
|
end
|
||||||
|
|
||||||
def site_name
|
def site_name
|
||||||
"Hentai Foundry"
|
parsed_url.site_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_urls
|
def image_urls
|
||||||
@@ -81,7 +56,7 @@ module Sources
|
|||||||
end
|
end
|
||||||
|
|
||||||
def artist_name
|
def artist_name
|
||||||
urls.map { |url| url[PROFILE_URL, :artist_name] || url[PAGE_URL, :artist_name] || url[IMAGE_URL, :artist_name] }.compact.first
|
parsed_url.username || parsed_referer&.username
|
||||||
end
|
end
|
||||||
|
|
||||||
def canonical_url
|
def canonical_url
|
||||||
@@ -110,8 +85,10 @@ module Sources
|
|||||||
end
|
end
|
||||||
|
|
||||||
def illust_id
|
def illust_id
|
||||||
url[PAGE_URL, :illust_id] || url[IMAGE_URL, :illust_id] || url[OLD_PAGE, :illust_id]
|
parsed_url.work_id || parsed_referer&.work_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
memoize :page
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user