Make the artist finder work with new Pixiv URLs.

This commit is contained in:
evazion
2014-10-04 11:57:09 -05:00
parent 58f0ec3dec
commit ec0f226f46
2 changed files with 16 additions and 5 deletions

View File

@@ -118,11 +118,7 @@ class ArtistsController < ApplicationController
end
def finder
url = params[:url]
headers = {
"User-Agent" => "#{Danbooru.config.safe_app_name}/#{Danbooru.config.version}"
}
url, headers = Downloads::Strategies::Pixiv.new.rewrite(url, headers)
url = Sources::Strategies::Pixiv.new(url).normalize_for_artist_finder!(params[:url])
@artists = Artist.url_matches(url).order("id desc").limit(20)
respond_with(@artists) do |format|

View File

@@ -25,6 +25,21 @@ module Sources
@pixiv_moniker
end
def normalize_for_artist_finder!(url)
illust_id = illust_id_from_url(url)
# 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
get_metadata_from_spapi!(illust_id) do |metadata|
username = metadata[24]
end
end
"http://img.pixiv.net/img/#{username}"
end
def get
agent.get(URI.parse(normalized_url)) do |page|
@artist_name, @profile_url = get_profile_from_page(page)