From 64472a7b7e5cf6386dcfc8afeab7f3abc2e7ab35 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 25 Feb 2022 19:09:29 -0600 Subject: [PATCH] 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. --- app/logical/source/url.rb | 3 +- app/logical/source/url/hentai_foundry.rb | 96 +++++++++++++++++++ app/logical/source/url/twit_pic.rb | 4 + .../sources/strategies/hentai_foundry.rb | 41 ++------ 4 files changed, 111 insertions(+), 33 deletions(-) create mode 100644 app/logical/source/url/hentai_foundry.rb diff --git a/app/logical/source/url.rb b/app/logical/source/url.rb index 783761863..5600480c9 100644 --- a/app/logical/source/url.rb +++ b/app/logical/source/url.rb @@ -19,6 +19,7 @@ module Source class URL < Danbooru::URL SUBCLASSES = [ Source::URL::Twitter, + Source::URL::HentaiFoundry, Source::URL::Plurk, Source::URL::Skeb, 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. def site_name - self.class.name.demodulize + self.class.name.demodulize.titleize end protected def initialize(...) diff --git a/app/logical/source/url/hentai_foundry.rb b/app/logical/source/url/hentai_foundry.rb new file mode 100644 index 000000000..a10a2946c --- /dev/null +++ b/app/logical/source/url/hentai_foundry.rb @@ -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 diff --git a/app/logical/source/url/twit_pic.rb b/app/logical/source/url/twit_pic.rb index b292d759d..8e8259d8f 100644 --- a/app/logical/source/url/twit_pic.rb +++ b/app/logical/source/url/twit_pic.rb @@ -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]) end + def site_name + "TwitPic" + end + def parse case [domain, *path_segments] diff --git a/app/logical/sources/strategies/hentai_foundry.rb b/app/logical/sources/strategies/hentai_foundry.rb index 8baa11c7b..f93ff7f61 100644 --- a/app/logical/sources/strategies/hentai_foundry.rb +++ b/app/logical/sources/strategies/hentai_foundry.rb @@ -1,42 +1,17 @@ # frozen_string_literal: true -# Image URLs -# -# * 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 - +# @see Source::URL::HentaiFoundry module Sources module Strategies class HentaiFoundry < Base - BASE_URL = %r{\Ahttps?://(?:www\.)?hentai-foundry\.com}i - PAGE_URL = %r{#{BASE_URL}/pictures/user/(?[\w-]+)/(?\d+)(?:/[\w.-]*)?(\?[\w=]*)?\z}i - OLD_PAGE = %r{#{BASE_URL}/pic-(?\d+)(?:\.html)?\z}i - PROFILE_URL = %r{#{BASE_URL}/(?:pictures/)?user/(?[\w-]+)(?:/[a-z]*)?\z}i - IMAGE_URL = %r{\Ahttps?://pictures\.hentai-foundry\.com/+\w/(?[\w-]+)/(?\d+)(?:(?:/[\w.-]+)?\.\w+)?\z}i + extend Memoist - def domains - ["hentai-foundry.com"] + def match? + parsed_url&.site_name == "Hentai Foundry" end def site_name - "Hentai Foundry" + parsed_url.site_name end def image_urls @@ -81,7 +56,7 @@ module Sources end 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 def canonical_url @@ -110,8 +85,10 @@ module Sources end 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 + + memoize :page end end end