Refactor sources
This commit is contained in:
@@ -1,62 +1,80 @@
|
||||
# html page urls:
|
||||
# https://pawoo.net/@evazion/19451018
|
||||
# https://pawoo.net/web/statuses/19451018
|
||||
#
|
||||
# image urls:
|
||||
# https://img.pawoo.net/media_attachments/files/001/297/997/small/c4272a09570757c2.png
|
||||
# https://img.pawoo.net/media_attachments/files/001/297/997/original/c4272a09570757c2.png
|
||||
# https://pawoo.net/media/lU2uV7C1MMQSb1czwvg
|
||||
#
|
||||
# artist urls:
|
||||
# https://pawoo.net/@evazion
|
||||
# https://pawoo.net/web/accounts/47806
|
||||
|
||||
module Sources::Strategies
|
||||
class Pawoo < Base
|
||||
attr_reader :image_urls
|
||||
IMAGE = %r!\Ahttps?://img\.pawoo\.net/media_attachments/files/(\d+/\d+/\d+)!
|
||||
|
||||
def self.url_match?(url)
|
||||
PawooApiClient::Status.is_match?(url) || PawooApiClient::Account.is_match?(url)
|
||||
end
|
||||
|
||||
def referer_url
|
||||
normalized_url
|
||||
def self.match?(*urls)
|
||||
urls.compact.any? do |x|
|
||||
x =~ IMAGE || PawooApiClient::Status.is_match?(x) || PawooApiClient::Account.is_match?(x)
|
||||
end
|
||||
end
|
||||
|
||||
def site_name
|
||||
"Pawoo"
|
||||
end
|
||||
|
||||
def api_response
|
||||
@response ||= PawooApiClient.new.get(normalized_url)
|
||||
def image_url
|
||||
image_urls.first
|
||||
end
|
||||
|
||||
def get
|
||||
response = api_response
|
||||
@artist_name = response.account_name
|
||||
@profile_url = response.profile_url
|
||||
@image_url = response.image_urls.first
|
||||
@image_urls = response.image_urls
|
||||
@tags = response.tags
|
||||
@artist_commentary_title = nil
|
||||
@artist_commentary_desc = response.commentary
|
||||
end
|
||||
|
||||
def normalized_url
|
||||
if self.class.url_match?(@url)
|
||||
@url
|
||||
elsif self.class.url_match?(@referer_url)
|
||||
@referer_url
|
||||
# https://img.pawoo.net/media_attachments/files/001/297/997/small/c4272a09570757c2.png
|
||||
# https://img.pawoo.net/media_attachments/files/001/297/997/original/c4272a09570757c2.png
|
||||
# https://pawoo.net/media/lU2uV7C1MMQSb1czwvg
|
||||
def image_urls
|
||||
if url =~ %r!#{IMAGE}/small/([a-z0-9]+\.\w+)\z!i
|
||||
return ["https://img.pawoo.net/media_attachments/files/#{$1}/original/#{$2}"]
|
||||
end
|
||||
|
||||
if url =~ %r!#{IMAGE}/original/([a-z0-9]+\.\w+)\z!i
|
||||
return [url]
|
||||
end
|
||||
|
||||
return api_response.image_urls
|
||||
end
|
||||
|
||||
# https://pawoo.net/@evazion/19451018
|
||||
# https://pawoo.net/web/statuses/19451018
|
||||
def page_url
|
||||
[url, referer_url].each do |x|
|
||||
if PawooApiClient::Status.is_match?(x)
|
||||
return x
|
||||
end
|
||||
end
|
||||
|
||||
return super
|
||||
end
|
||||
|
||||
# https://pawoo.net/@evazion
|
||||
# https://pawoo.net/web/accounts/47806
|
||||
def profile_url
|
||||
if url =~ PawooApiClient::PROFILE2
|
||||
return "https://pawoo.net/@#{$1}"
|
||||
end
|
||||
|
||||
api_response.profile_url
|
||||
end
|
||||
|
||||
def artist_name
|
||||
api_response.account_name
|
||||
end
|
||||
|
||||
def artist_commentary_title
|
||||
nil
|
||||
end
|
||||
|
||||
def artist_commentary_desc
|
||||
api_response.commentary
|
||||
end
|
||||
|
||||
def tags
|
||||
api_response.tags
|
||||
end
|
||||
|
||||
def normalizable_for_artist_finder?
|
||||
true
|
||||
end
|
||||
|
||||
def normalize_for_artist_finder!
|
||||
get
|
||||
@profile_url || @url
|
||||
def normalize_for_artist_finder
|
||||
profile_url
|
||||
end
|
||||
|
||||
def dtext_artist_commentary_desc
|
||||
@@ -68,5 +86,18 @@ module Sources::Strategies
|
||||
end
|
||||
end.strip
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
def api_response
|
||||
[url, referer_url].each do |x|
|
||||
if client = PawooApiClient.new.get(x)
|
||||
return client
|
||||
end
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
memoize :api_response
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user