normalize nijie popup urls (fixes #3153)

This commit is contained in:
r888888888
2017-06-14 12:14:55 -07:00
parent cdef9fda7d
commit 6174d0eef2
2 changed files with 33 additions and 6 deletions

View File

@@ -5,6 +5,10 @@ module Sources
url =~ /^https?:\/\/(?:.+?\.)?nijie\.info/
end
def initialize(url, referer_url=nil)
super(normalize_url(url), normalize_url(referer_url))
end
def referer_url
if @referer_url =~ /nijie\.info\/view\.php.+id=\d+/ && @url =~ /pic\d+\.nijie.info\/nijie_picture\//
@referer_url
@@ -23,13 +27,13 @@ module Sources
end
def get
page = agent.get(url)
page = agent.get(referer_url)
if page.search("div#header-login-container").any?
# Session cache is invalid, clear it and log in normally.
Cache.delete("nijie-session")
@agent = nil
page = agent.get(url)
page = agent.get(referer_url)
end
@artist_name, @profile_url = get_profile_from_page(page)
@@ -79,6 +83,14 @@ module Sources
end
end
def normalize_url(url)
if url =~ %r!https?://nijie\.info/view_popup\.php.+id=(\d+)!
return "http://nijie.info/view.php?id=#{$1}"
else
return url
end
end
def agent
@agent ||= begin
mech = Mechanize.new

View File

@@ -25,6 +25,25 @@ module Sources
end
end
context "The source site for a nijie referer url" do
setup do
@site = Sources::Site.new("http://pic03.nijie.info/nijie_picture/728995_20170505014820_0.jpg", referer_url: "https://nijie.info/view_popup.php?id=213043")
@site.get
end
should "get the image url" do
assert_equal("http://pic03.nijie.info/nijie_picture/728995_20170505014820_0.jpg", @site.image_url)
end
should "get the profile" do
assert_equal("http://nijie.info/members.php?id=728995", @site.profile_url)
end
should "get the artist name" do
assert_equal("", @site.artist_name)
end
end
context "The source site for a nijie popup" do
setup do
@site = Sources::Site.new("https://nijie.info/view_popup.php?id=213043")
@@ -42,10 +61,6 @@ module Sources
should "get the artist name" do
assert_equal("", @site.artist_name)
end
should "get the tags" do
assert_equal([["眼鏡", "http://nijie.info/search.php?word=%E7%9C%BC%E9%8F%A1"], ["リトルウィッチアカデミア", "http://nijie.info/search.php?word=%E3%83%AA%E3%83%88%E3%83%AB%E3%82%A6%E3%82%A3%E3%83%83%E3%83%81%E3%82%A2%E3%82%AB%E3%83%87%E3%83%9F%E3%82%A2"], ["アーシュラ先生", "http://nijie.info/search.php?word=%E3%82%A2%E3%83%BC%E3%82%B7%E3%83%A5%E3%83%A9%E5%85%88%E7%94%9F"]], @site.tags)
end
end
end
end