add support for nico seiga manga (fixes #4060)
This commit is contained in:
@@ -3,7 +3,8 @@ module Sources
|
||||
def self.all
|
||||
return [
|
||||
Strategies::Pixiv,
|
||||
Strategies::NicoSeiga,
|
||||
Strategies::NicoSeigaManga, # must come before NicoSeiga
|
||||
Strategies::NicoSeiga,
|
||||
Strategies::Twitter,
|
||||
Strategies::Stash, # must come before DeviantArt
|
||||
Strategies::DeviantArt,
|
||||
|
||||
@@ -153,39 +153,7 @@ module Sources
|
||||
memoize :page
|
||||
|
||||
def agent
|
||||
mech = Mechanize.new
|
||||
mech.redirect_ok = false
|
||||
mech.keep_alive = false
|
||||
|
||||
session = Cache.get("nico-seiga-session")
|
||||
if session
|
||||
cookie = Mechanize::Cookie.new("user_session", session)
|
||||
cookie.domain = ".nicovideo.jp"
|
||||
cookie.path = "/"
|
||||
mech.cookie_jar.add(cookie)
|
||||
else
|
||||
mech.get("https://account.nicovideo.jp/login") do |page|
|
||||
page.form_with(:id => "login_form") do |form|
|
||||
form["mail_tel"] = Danbooru.config.nico_seiga_login
|
||||
form["password"] = Danbooru.config.nico_seiga_password
|
||||
end.click_button
|
||||
end
|
||||
session = mech.cookie_jar.cookies.select{|c| c.name == "user_session"}.first
|
||||
if session
|
||||
Cache.put("nico-seiga-session", session.value, 1.month)
|
||||
else
|
||||
raise "Session not found"
|
||||
end
|
||||
end
|
||||
|
||||
# This cookie needs to be set to allow viewing of adult works
|
||||
cookie = Mechanize::Cookie.new("skip_fetish_warning", "1")
|
||||
cookie.domain = "seiga.nicovideo.jp"
|
||||
cookie.path = "/"
|
||||
mech.cookie_jar.add(cookie)
|
||||
|
||||
mech.redirect_ok = true
|
||||
mech
|
||||
NicoSeigaApiClient.agent
|
||||
end
|
||||
memoize :agent
|
||||
end
|
||||
|
||||
71
app/logical/sources/strategies/nico_seiga_manga.rb
Normal file
71
app/logical/sources/strategies/nico_seiga_manga.rb
Normal file
@@ -0,0 +1,71 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class NicoSeigaManga < Base
|
||||
PAGE_URL = %r!\Ahttps?://seiga\.nicovideo\.jp/watch/mg(\d+)!i
|
||||
|
||||
def domains
|
||||
["nicoseiga.jp", "nicovideo.jp"]
|
||||
end
|
||||
|
||||
def site_name
|
||||
"Nico Seiga (manga)"
|
||||
end
|
||||
|
||||
def image_urls
|
||||
api_client.image_ids.map do |image_id|
|
||||
"https://seiga.nicovideo.jp/image/source/#{image_id}"
|
||||
end
|
||||
end
|
||||
|
||||
def page_url
|
||||
[url, referer_url].each do |x|
|
||||
if x =~ PAGE_URL
|
||||
return x
|
||||
end
|
||||
end
|
||||
|
||||
return super
|
||||
end
|
||||
|
||||
def canonical_url
|
||||
image_url
|
||||
end
|
||||
|
||||
def profile_url
|
||||
if url =~ PROFILE
|
||||
return url
|
||||
end
|
||||
|
||||
"http://seiga.nicovideo.jp/user/illust/#{api_client.user_id}"
|
||||
end
|
||||
|
||||
def artist_name
|
||||
api_client.moniker
|
||||
end
|
||||
|
||||
def artist_commentary_title
|
||||
api_client.title
|
||||
end
|
||||
|
||||
def artist_commentary_desc
|
||||
api_client.desc
|
||||
end
|
||||
|
||||
def headers
|
||||
super.merge(
|
||||
"Referer" => "https://seiga.nicovideo.jp"
|
||||
)
|
||||
end
|
||||
|
||||
def theme_id
|
||||
if page_url =~ PAGE_URL
|
||||
return $1
|
||||
end
|
||||
end
|
||||
|
||||
def api_client
|
||||
NicoSeigaMangaApiClient.new(theme_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user