Refactor normalize_for_artist_finder!
Refactors things such that Sources::Site has a normalize_for_artist_finder! method that delegates to the strategy for the appropriate site. This way any site that needs to normalize URLs for the artist finder can do so.
This commit is contained in:
@@ -118,7 +118,7 @@ class ArtistsController < ApplicationController
|
||||
end
|
||||
|
||||
def finder
|
||||
url = Sources::Strategies::Pixiv.new(url).normalize_for_artist_finder!(params[:url])
|
||||
url = Sources::Site.new(params[:url]).normalize_for_artist_finder!
|
||||
|
||||
@artists = Artist.url_matches(url).order("id desc").limit(20)
|
||||
respond_with(@artists) do |format|
|
||||
|
||||
@@ -20,6 +20,14 @@ module Sources
|
||||
end
|
||||
end
|
||||
|
||||
def normalize_for_artist_finder!
|
||||
if available?
|
||||
return strategy.normalize_for_artist_finder!
|
||||
else
|
||||
return url
|
||||
end
|
||||
end
|
||||
|
||||
def translated_tags
|
||||
untranslated_tags = tags
|
||||
untranslated_tags = untranslated_tags.map(&:first)
|
||||
|
||||
@@ -18,6 +18,10 @@ module Sources
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def normalize_for_artist_finder!
|
||||
url
|
||||
end
|
||||
|
||||
def site_name
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
@@ -25,13 +25,12 @@ module Sources
|
||||
@pixiv_moniker
|
||||
end
|
||||
|
||||
def normalize_for_artist_finder!(url)
|
||||
illust_id = illust_id_from_url(url)
|
||||
|
||||
def normalize_for_artist_finder!
|
||||
# http://i2.pixiv.net/img04/img/syounen_no_uta/46170939_m.jpg
|
||||
if url =~ %r!/img/([^/]+)/\d+(?:_\w+)?\.(?:jpg|jpeg|png|gif)!i
|
||||
username = $1
|
||||
else
|
||||
illust_id = illust_id_from_url(url)
|
||||
get_metadata_from_spapi!(illust_id) do |metadata|
|
||||
username = metadata[24]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user