fixes #2805: Improve nico seiga support
This commit is contained in:
@@ -23,14 +23,7 @@ module Sources
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get
|
def get
|
||||||
page = agent.get(normalized_url)
|
page = load_page
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
@artist_name, @profile_url = get_profile_from_page(page)
|
@artist_name, @profile_url = get_profile_from_page(page)
|
||||||
@image_url = get_image_url_from_page(page)
|
@image_url = get_image_url_from_page(page)
|
||||||
@@ -44,8 +37,35 @@ module Sources
|
|||||||
end
|
end
|
||||||
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
|
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)
|
def get_profile_from_page(page)
|
||||||
links = page.search("li a").select {|x| x["href"] =~ /user\/illust/}
|
links = page.search("li a").select {|x| x["href"] =~ /user\/illust/}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ module Sources
|
|||||||
end
|
end
|
||||||
|
|
||||||
def normalized_for_artist_finder?
|
def normalized_for_artist_finder?
|
||||||
url =~ %r!http://img\.pixiv\.net/img/#{MONIKER}/?$!i
|
url =~ %r!https?://img\.pixiv\.net/img/#{MONIKER}/?$!i
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalizable_for_artist_finder?
|
def normalizable_for_artist_finder?
|
||||||
|
|||||||
334
test/fixtures/vcr_cassettes/artist-url-test/nico-seiga.yml
vendored
Normal file
334
test/fixtures/vcr_cassettes/artist-url-test/nico-seiga.yml
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1,6 +1,12 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class ArtistUrlTest < ActiveSupport::TestCase
|
class ArtistUrlTest < ActiveSupport::TestCase
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
@record = false
|
||||||
|
setup_vcr
|
||||||
|
end
|
||||||
|
|
||||||
context "An artist url" do
|
context "An artist url" do
|
||||||
setup do
|
setup do
|
||||||
MEMCACHE.flush_all
|
MEMCACHE.flush_all
|
||||||
@@ -40,8 +46,13 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "normalize nico seiga artist urls" do
|
should "normalize nico seiga artist urls" do
|
||||||
url = FactoryGirl.create(:artist_url, :url => "http://seiga.nicovideo.jp/user/illust/1826959?target=illust_all")
|
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)
|
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
|
end
|
||||||
|
|
||||||
should "normalize hentai foundry artist urls" do
|
should "normalize hentai foundry artist urls" do
|
||||||
|
|||||||
Reference in New Issue
Block a user