Fix it so that Unicode characters aren't unnecessarily percent-encoded when generating tag search URLs. For example, generate URLs like this: * https://www.pixiv.net/tags/オリジナル/artworks Not like this: * https://www.pixiv.net/tags/%E3%82%AA%E3%83%AA%E3%82%B8%E3%83%8A%E3%83%AB/artworks
59 lines
1.6 KiB
Ruby
59 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# https://rule34.us is running a modified fork of Gelbooru 0.1, so its structure is similar but not identical to that of
|
|
# other Gelbooru-based sites.
|
|
#
|
|
# @see Source::Extractor::Gelbooru
|
|
# @see Source::URL::Rule34DotUs
|
|
# @see https://rule34.us
|
|
module Source
|
|
class Extractor
|
|
class Rule34DotUs < Source::Extractor
|
|
def match?
|
|
Source::URL::Rule34DotUs === parsed_url
|
|
end
|
|
|
|
def image_urls
|
|
if parsed_url.full_image_url.present?
|
|
[parsed_url.full_image_url]
|
|
else
|
|
image_url = page&.css(".tag-list-left > a[href*='/images/']")&.attr("href")&.value
|
|
[image_url].compact
|
|
end
|
|
end
|
|
|
|
def page_url
|
|
"https://rule34.us/index.php?r=posts/view&id=#{post_id}" if post_id.present?
|
|
end
|
|
|
|
def tags
|
|
page&.css("meta[name='keywords']")&.attr("content")&.value.to_s.split(/, /).compact.map do |tag|
|
|
[tag.tr(" ", "_"), "https://rule34.us/index.php?r=posts/index&q=#{Danbooru::URL.escape(tag)}"]
|
|
end
|
|
end
|
|
|
|
def post_id
|
|
parsed_url.post_id || parsed_referer&.post_id || post_id_from_page
|
|
end
|
|
|
|
def post_id_from_page
|
|
# title = "Rule34 - If it exists, there is porn of it / sora / 6204967"
|
|
page&.title.to_s[/([0-9]+)\z/, 1]
|
|
end
|
|
|
|
def api_url
|
|
parsed_url.page_url || parsed_referer&.page_url
|
|
end
|
|
|
|
memoize def page
|
|
return nil if api_url.blank?
|
|
|
|
response = http.cache(1.minute).get(api_url)
|
|
return nil unless response.status == 200
|
|
|
|
response.parse
|
|
end
|
|
end
|
|
end
|
|
end
|