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 end
def artist_record def artist_record
Artist.other_names_match(artist_name) if artist_name.present?
Artist.other_names_match(artist_name)
else
nil
end
end end
protected protected

View File

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

View File

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

View File

@@ -1,19 +0,0 @@
# encoding: UTF-8
require 'test_helper'
class PixivProxyTest < ActiveSupport::TestCase
context "The proxy" do
should "get a single post" do
site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=9646484")
site.get
assert_equal("http://www.pixiv.net/member.php?id=4015", site.profile_url)
assert(site.tags.size > 0)
first_tag = site.tags.first
assert_equal(2, first_tag.size)
assert(first_tag[0] =~ /./)
assert(first_tag[1] =~ /tags\.php\?tag=/)
end
end
end

View File

@@ -6,7 +6,7 @@ module Sources
class PixivTest < ActiveSupport::TestCase class PixivTest < ActiveSupport::TestCase
context "The source site for pixiv" do context "The source site for pixiv" do
setup do setup do
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=9646484") @site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=big&illust_id=9646484")
@site.get @site.get
end end