fixed pixiv sources

This commit is contained in:
albert
2011-09-30 13:27:22 -04:00
parent 641da03250
commit 2287bc8d61
5 changed files with 14 additions and 28 deletions

View File

@@ -26,7 +26,11 @@ module Sources
end
def artist_record
Artist.other_names_match(artist_name)
if artist_name.present?
Artist.other_names_match(artist_name)
else
nil
end
end
protected

View File

@@ -25,12 +25,12 @@ module Sources
protected
def get_profile_from_page(page)
links = page.search("div.front-subContent a").find_all do |node|
links = page.search("div.profile_area a.avatar_m").find_all do |node|
node["href"] =~ /member\.php/
end
if links.any?
profile_url = "http://www.pixiv.net/" + links[0]["href"]
profile_url = "http://www.pixiv.net" + links[0]["href"]
children = links[0].children
artist = children[0]["alt"]
return [artist, profile_url]
@@ -49,13 +49,13 @@ module Sources
end
def get_tags_from_page(page)
links = page.search("div.pedia li a").find_all do |node|
links = page.search("span#tags a").find_all do |node|
node["href"] =~ /tags\.php/
end
if links.any?
links.map do |node|
[node.inner_text, "http://www.pixiv.net/" + node.attr("href")]
[node.inner_text, "http://www.pixiv.net" + node.attr("href")]
end
else
[]
@@ -66,6 +66,8 @@ module Sources
@normalized_url ||= begin
if url =~ /\/(\d+)(_m|_p\d+)?\.(jpg|jpeg|png|gif)/i
"http://www.pixiv.net/member_illust.php?mode=medium&illust_id=#{$1}"
elsif url =~ /mode=big/
url.sub(/mode=big/, "mode=medium")
elsif url =~ /member_illust\.php/ && url =~ /illust_id=/
url
else
@@ -80,8 +82,7 @@ module Sources
mech.get("http://www.pixiv.net") do |page|
page.form_with(:action => "/login.php") do |form|
form['mode'] = "login"
form['login_pixiv_id'] = Danbooru.config.pixiv_login
form['pixiv_id'] = Danbooru.config.pixiv_login
form['pass'] = Danbooru.config.pixiv_password
end.click_button
end

View File

@@ -60,7 +60,7 @@ class Artist < ActiveRecord::Base
module NameMethods
module ClassMethods
def normalize_name(name)
name.downcase.strip.gsub(/ /, '_')
name.to_s.downcase.strip.gsub(/ /, '_')
end
end