fixes #2805: Improve nico seiga support

This commit is contained in:
Albert Yi
2016-12-27 16:09:20 -08:00
parent 08e0480a62
commit 3ad639521f
4 changed files with 376 additions and 11 deletions

View File

@@ -23,14 +23,7 @@ module Sources
end
def get
page = agent.get(normalized_url)
if page.search("a#link_btn_login").any?
# Session cache is invalid, clear it and log in normally.
Cache.delete("nico-seiga-session")
@agent = nil
page = agent.get(normalized_url)
end
page = load_page
@artist_name, @profile_url = get_profile_from_page(page)
@image_url = get_image_url_from_page(page)
@@ -44,8 +37,35 @@ module Sources
end
end
def normalized_for_artist_finder?
url =~ %r!https?://seiga\.nicovideo\.jp/user/illust/\d+!i
end
def normalizable_for_artist_finder?
url =~ %r!https?://seiga\.nicovideo\.jp/seiga/im\d+!i
end
def normalize_for_artist_finder!
page = load_page
@artist_name, @profile_url = get_profile_from_page(page)
profile_url
end
protected
def load_page
page = agent.get(normalized_url)
if page.search("a#link_btn_login").any?
# Session cache is invalid, clear it and log in normally.
Cache.delete("nico-seiga-session")
@agent = nil
page = agent.get(normalized_url)
end
page
end
def get_profile_from_page(page)
links = page.search("li a").select {|x| x["href"] =~ /user\/illust/}

View File

@@ -45,7 +45,7 @@ module Sources
end
def normalized_for_artist_finder?
url =~ %r!http://img\.pixiv\.net/img/#{MONIKER}/?$!i
url =~ %r!https?://img\.pixiv\.net/img/#{MONIKER}/?$!i
end
def normalizable_for_artist_finder?

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,12 @@
require 'test_helper'
class ArtistUrlTest < ActiveSupport::TestCase
def setup
super
@record = false
setup_vcr
end
context "An artist url" do
setup do
MEMCACHE.flush_all
@@ -40,8 +46,13 @@ class ArtistUrlTest < ActiveSupport::TestCase
end
should "normalize nico seiga artist urls" do
url = FactoryGirl.create(:artist_url, :url => "http://seiga.nicovideo.jp/user/illust/1826959?target=illust_all")
assert_equal("http://seiga.nicovideo.jp/user/illust/1826959/", url.normalized_url)
url = FactoryGirl.create(:artist_url, :url => "http://seiga.nicovideo.jp/user/illust/1826959")
assert_equal("http://seiga.nicovideo.jp/user/illust/1826959", url.normalized_url)
VCR.use_cassette("artist-url-test/nico-seiga", :record => @vcr_record_option) do
url = FactoryGirl.create(:artist_url, :url => "http://seiga.nicovideo.jp/seiga/im4937663")
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777/", url.normalized_url)
end
end
should "normalize hentai foundry artist urls" do