sources: add image_url?, page_url?, and profile_url? methods.

Add methods to Source::URL for determining whether a URL is an image
URL, a page URL, or a profile URL.

Also add more source URL tests and fix various URL parsing bugs.
This commit is contained in:
evazion
2022-05-01 17:55:58 -05:00
parent d54ad9103b
commit 23b8350320
47 changed files with 571 additions and 165 deletions

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
class Source::URL::HentaiFoundry < Source::URL
attr_reader :username, :work_id
attr_reader :username, :work_id, :file
def self.match?(url)
url.domain == "hentai-foundry.com"
@@ -12,17 +12,20 @@ class Source::URL::HentaiFoundry < Source::URL
# 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
in "pictures.hentai-foundry.com", _, username, /^\d+$/ => work_id, file
@file = file
@username = username
@work_id = work_id
# http://pictures.hentai-foundry.com//s/soranamae/363663.jpg
in "pictures.hentai-foundry.com", _, username, /^(\d+)\.\w+$/
in "pictures.hentai-foundry.com", _, username, /^(\d+)\.\w+$/ => file
@file = file
@username = username
@work_id = $1
# http://www.hentai-foundry.com/piccies/d/dmitrys/1183.jpg
in "www.hentai-foundry.com", "piccies", _, username, /^(\d+)\.\w+$/
in "www.hentai-foundry.com", "piccies", _, username, /^(\d+)\.\w+$/ => file
@file = file
@username = username
@work_id = $1
@@ -64,6 +67,10 @@ class Source::URL::HentaiFoundry < Source::URL
end
end
def image_url?
file.present? || host == "thumbs.hentai-foundry.com"
end
def page_url
if username.present? && work_id.present?
"https://www.hentai-foundry.com/pictures/user/#{username}/#{work_id}"