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
|
||||
|
||||
Reference in New Issue
Block a user