From 2287bc8d617ace9e8363723a708a6e8203fd911f Mon Sep 17 00:00:00 2001 From: albert Date: Fri, 30 Sep 2011 13:27:22 -0400 Subject: [PATCH] fixed pixiv sources --- app/logical/sources/strategies/base.rb | 6 +++++- app/logical/sources/strategies/pixiv.rb | 13 +++++++------ app/models/artist.rb | 2 +- test/unit/pixiv_proxy_test.rb | 19 ------------------- test/unit/sources/pixiv_test.rb | 2 +- 5 files changed, 14 insertions(+), 28 deletions(-) delete mode 100644 test/unit/pixiv_proxy_test.rb diff --git a/app/logical/sources/strategies/base.rb b/app/logical/sources/strategies/base.rb index a89df514c..700460452 100644 --- a/app/logical/sources/strategies/base.rb +++ b/app/logical/sources/strategies/base.rb @@ -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 diff --git a/app/logical/sources/strategies/pixiv.rb b/app/logical/sources/strategies/pixiv.rb index f22f93add..def6920a5 100644 --- a/app/logical/sources/strategies/pixiv.rb +++ b/app/logical/sources/strategies/pixiv.rb @@ -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 diff --git a/app/models/artist.rb b/app/models/artist.rb index 0990a30fe..2bad09e1a 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -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 diff --git a/test/unit/pixiv_proxy_test.rb b/test/unit/pixiv_proxy_test.rb deleted file mode 100644 index 6fe7b31d4..000000000 --- a/test/unit/pixiv_proxy_test.rb +++ /dev/null @@ -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 diff --git a/test/unit/sources/pixiv_test.rb b/test/unit/sources/pixiv_test.rb index 5b705686d..352a42619 100644 --- a/test/unit/sources/pixiv_test.rb +++ b/test/unit/sources/pixiv_test.rb @@ -6,7 +6,7 @@ module Sources class PixivTest < ActiveSupport::TestCase context "The source site for pixiv" 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 end