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?