Fix #3906: Moebooru strategy raises NotImplementedError.
This commit is contained in:
@@ -43,8 +43,14 @@ module Sources
|
||||
@referer_url = referer_url
|
||||
end
|
||||
|
||||
def urls
|
||||
[url, referer_url].select(&:present?)
|
||||
end
|
||||
|
||||
def site_name
|
||||
raise NotImplementedError
|
||||
Addressable::URI.heuristic_parse(url).host
|
||||
rescue Addressable::URI::InvalidURIError => e
|
||||
nil
|
||||
end
|
||||
|
||||
# Whatever <tt>url</tt> is, this method should return the direct links
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Moebooru < Base
|
||||
DOMAINS = /(?:[^.]+\.)?yande\.re|konachan\.com/
|
||||
BASE_URL = %r!\Ahttps?://(?:[^.]+\.)?(?<domain>yande\.re|konachan\.com)!i
|
||||
|
||||
def self.match?(*urls)
|
||||
urls.compact.any? { |x| x.match?(DOMAINS) }
|
||||
urls.compact.any? { |x| x.match?(BASE_URL) }
|
||||
end
|
||||
|
||||
def site_name
|
||||
URI.parse(url).host
|
||||
urls.map { |url| url[BASE_URL, :domain] }.compact.first
|
||||
end
|
||||
|
||||
def image_url
|
||||
if url =~ %r{\A(https?://(?:#{DOMAINS}))/jpeg/([a-f0-9]+(?:/.*)?)\.jpg\Z}
|
||||
return $1 + "/image/" + $2 + ".png"
|
||||
if url =~ %r{\A(?<base>#{BASE_URL})/jpeg/(?<md5>\h+(?:/.*)?)\.jpg\Z}
|
||||
return $~[:base] + "/image/" + $~[:md5] + ".png"
|
||||
end
|
||||
|
||||
return url
|
||||
end
|
||||
|
||||
def image_urls
|
||||
[image_url]
|
||||
end
|
||||
|
||||
def page_url
|
||||
return url
|
||||
end
|
||||
|
||||
@@ -29,12 +29,6 @@ module Sources
|
||||
url
|
||||
end
|
||||
|
||||
def site_name
|
||||
URI.parse(url).hostname || "N/A"
|
||||
rescue
|
||||
"N/A"
|
||||
end
|
||||
|
||||
def unique_id
|
||||
url
|
||||
end
|
||||
|
||||
@@ -2,12 +2,23 @@ require "test_helper"
|
||||
|
||||
module Sources
|
||||
class MoebooruTest < ActiveSupport::TestCase
|
||||
context "downloading a 'https://yande.re/jpeg/:hash/:file.jpg' jpeg sample url" do
|
||||
should "download the original file" do
|
||||
@source = "https://yande.re/jpeg/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092%20hatsune_miku%20tid%20vocaloid.jpg"
|
||||
@rewrite = "https://yande.re/image/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092%20hatsune_miku%20tid%20vocaloid.png"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(1_050_117, @source)
|
||||
context "Yande.re:" do
|
||||
context "A 'https://yande.re/jpeg/:hash/:file.jpg' jpeg sample url" do
|
||||
should "download the original file" do
|
||||
@source = "https://yande.re/jpeg/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092%20hatsune_miku%20tid%20vocaloid.jpg"
|
||||
@rewrite = "https://yande.re/image/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092%20hatsune_miku%20tid%20vocaloid.png"
|
||||
assert_rewritten(@rewrite, @source)
|
||||
assert_downloaded(1_050_117, @source)
|
||||
end
|
||||
end
|
||||
|
||||
context "A 'https://files.yande.re/sample/:hash/:file.jpg' sample url" do
|
||||
should "work" do
|
||||
@site = Sources::Strategies.find("https://files.yande.re/sample/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880%20sample%20bayashiko%20journey_to_the_west%20sun_wukong.jpg")
|
||||
|
||||
assert_equal("yande.re", @site.site_name)
|
||||
assert_nothing_raised { @site.to_h }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user