pixiv: remove fanbox support.
This is broken and it needs to be rewritten as a separate source strategy anyway.
This commit is contained in:
@@ -99,50 +99,6 @@ class PixivApiClient
|
||||
end
|
||||
end
|
||||
|
||||
class FanboxResponse
|
||||
attr_reader :json
|
||||
|
||||
def initialize(json)
|
||||
@json = json
|
||||
end
|
||||
|
||||
def name
|
||||
json["body"]["user"]["name"]
|
||||
end
|
||||
|
||||
def user_id
|
||||
json["body"]["user"]["userId"]
|
||||
end
|
||||
|
||||
def moniker
|
||||
""
|
||||
end
|
||||
|
||||
def page_count
|
||||
json["body"]["body"]["images"].size
|
||||
end
|
||||
|
||||
def artist_commentary_title
|
||||
json["body"]["title"]
|
||||
end
|
||||
|
||||
def artist_commentary_desc
|
||||
json["body"]["body"]["text"]
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
end
|
||||
|
||||
def pages
|
||||
if json["body"]["body"]
|
||||
json["body"]["body"]["images"].map {|x| x["originalUrl"]}
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def work(illust_id)
|
||||
headers = Danbooru.config.http_headers.merge(
|
||||
"Referer" => "http://www.pixiv.net",
|
||||
@@ -169,19 +125,6 @@ class PixivApiClient
|
||||
raise Error.new("Pixiv API call failed (status=#{response.code} body=#{response.body})")
|
||||
end
|
||||
|
||||
def fanbox(fanbox_id)
|
||||
url = "https://www.pixiv.net/ajax/fanbox/post?postId=#{fanbox_id.to_i}"
|
||||
resp = agent.get(url)
|
||||
json = JSON.parse(resp.body)
|
||||
if resp.code == "200"
|
||||
FanboxResponse.new(json)
|
||||
elsif json["status"] == "failure"
|
||||
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
||||
end
|
||||
rescue JSON::ParserError
|
||||
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
||||
end
|
||||
|
||||
def novel(novel_id)
|
||||
headers = Danbooru.config.http_headers.merge(
|
||||
"Referer" => "http://www.pixiv.net",
|
||||
@@ -237,9 +180,4 @@ class PixivApiClient
|
||||
access_token
|
||||
end
|
||||
end
|
||||
|
||||
def agent
|
||||
PixivWebAgent.build
|
||||
end
|
||||
memoize :agent
|
||||
end
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
class PixivWebAgent
|
||||
SESSION_CACHE_KEY = "pixiv-phpsessid"
|
||||
COMIC_SESSION_CACHE_KEY = "pixiv-comicsessid"
|
||||
SESSION_COOKIE_KEY = "PHPSESSID"
|
||||
COMIC_SESSION_COOKIE_KEY = "_pixiv-comic_session"
|
||||
|
||||
def self.phpsessid(agent)
|
||||
agent.cookies.select { |cookie| cookie.name == SESSION_COOKIE_KEY }.first.try(:value)
|
||||
end
|
||||
|
||||
def self.build
|
||||
mech = Mechanize.new
|
||||
mech.keep_alive = false
|
||||
|
||||
phpsessid = Cache.get(SESSION_CACHE_KEY)
|
||||
comicsessid = Cache.get(COMIC_SESSION_CACHE_KEY)
|
||||
|
||||
if phpsessid
|
||||
cookie = Mechanize::Cookie.new(SESSION_COOKIE_KEY, phpsessid)
|
||||
cookie.domain = ".pixiv.net"
|
||||
cookie.path = "/"
|
||||
mech.cookie_jar.add(cookie)
|
||||
|
||||
if comicsessid
|
||||
cookie = Mechanize::Cookie.new(COMIC_SESSION_COOKIE_KEY, comicsessid)
|
||||
cookie.domain = ".pixiv.net"
|
||||
cookie.path = "/"
|
||||
mech.cookie_jar.add(cookie)
|
||||
end
|
||||
else
|
||||
headers = {
|
||||
"Origin" => "https://accounts.pixiv.net",
|
||||
"Referer" => "https://accounts.pixiv.net/login?lang=en^source=pc&view_type=page&ref=wwwtop_accounts_index"
|
||||
}
|
||||
|
||||
params = {
|
||||
pixiv_id: Danbooru.config.pixiv_login,
|
||||
password: Danbooru.config.pixiv_password,
|
||||
captcha: nil,
|
||||
g_captcha_response: nil,
|
||||
source: "pc",
|
||||
post_key: nil
|
||||
}
|
||||
|
||||
mech.get("https://accounts.pixiv.net/login?lang=en&source=pc&view_type=page&ref=wwwtop_accounts_index") do |page|
|
||||
json = page.search("input#init-config").first.attr("value")
|
||||
if json =~ /pixivAccount\.postKey":"([a-f0-9]+)/
|
||||
params[:post_key] = $1
|
||||
end
|
||||
end
|
||||
|
||||
mech.post("https://accounts.pixiv.net/api/login?lang=en", params, headers)
|
||||
if mech.current_page.body =~ /"error":false/
|
||||
cookie = mech.cookies.select {|x| x.name == SESSION_COOKIE_KEY}.first
|
||||
if cookie
|
||||
Cache.put(SESSION_CACHE_KEY, cookie.value, 1.week)
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
mech.get("https://comic.pixiv.net") do
|
||||
cookie = mech.cookies.select {|x| x.name == COMIC_SESSION_COOKIE_KEY}.first
|
||||
if cookie
|
||||
Cache.put(COMIC_SESSION_CACHE_KEY, cookie.value, 1.week)
|
||||
end
|
||||
end
|
||||
rescue Net::HTTPServiceUnavailable
|
||||
# ignore
|
||||
end
|
||||
end
|
||||
|
||||
mech
|
||||
end
|
||||
end
|
||||
@@ -64,9 +64,6 @@ module Sources
|
||||
ORIG_IMAGE = %r{#{PXIMG}/img-original/img/#{DATE}/(?<illust_id>\d+)_p(?<page>\d+)\.#{EXT}\z}i
|
||||
STACC_PAGE = %r{\A#{WEB}/stacc/#{MONIKER}/?\z}i
|
||||
NOVEL_PAGE = %r{(?:\Ahttps?://www\.pixiv\.net/novel/show\.php\?id=(\d+))}
|
||||
FANBOX_ACCOUNT = %r{(?:\Ahttps?://www\.pixiv\.net/fanbox/creator/\d+\z)}
|
||||
FANBOX_IMAGE = %r{(?:\Ahttps?://fanbox\.pixiv\.net/images/post/(\d+))}
|
||||
FANBOX_PAGE = %r{(?:\Ahttps?://www\.pixiv\.net/fanbox/creator/\d+/post/(\d+))}
|
||||
|
||||
def self.to_dtext(text)
|
||||
if text.nil?
|
||||
@@ -127,14 +124,6 @@ module Sources
|
||||
return "https://www.pixiv.net/novel/show.php?id=#{novel_id}&mode=cover"
|
||||
end
|
||||
|
||||
if fanbox_id.present?
|
||||
return "https://www.pixiv.net/fanbox/creator/#{metadata.user_id}/post/#{fanbox_id}"
|
||||
end
|
||||
|
||||
if fanbox_account_id.present?
|
||||
return "https://www.pixiv.net/fanbox/creator/#{fanbox_account_id}"
|
||||
end
|
||||
|
||||
if illust_id.present?
|
||||
return "https://www.pixiv.net/artworks/#{illust_id}"
|
||||
end
|
||||
@@ -192,17 +181,7 @@ module Sources
|
||||
end
|
||||
|
||||
def headers
|
||||
if fanbox_id.present?
|
||||
# need the session to download fanbox images
|
||||
return {
|
||||
"Referer" => "https://www.pixiv.net/fanbox",
|
||||
"Cookie" => HTTP::Cookie.cookie_value(agent.cookies)
|
||||
}
|
||||
end
|
||||
|
||||
{
|
||||
"Referer" => "https://www.pixiv.net"
|
||||
}
|
||||
{ "Referer" => "https://www.pixiv.net" }
|
||||
end
|
||||
|
||||
def normalize_for_source
|
||||
@@ -242,10 +221,6 @@ module Sources
|
||||
end
|
||||
|
||||
def image_urls_sub
|
||||
if url =~ FANBOX_IMAGE
|
||||
return [url]
|
||||
end
|
||||
|
||||
# there's too much normalization bullshit we have to deal with
|
||||
# raw urls, so just fetch the canonical url from the api every
|
||||
# time.
|
||||
@@ -265,7 +240,7 @@ module Sources
|
||||
# even though it makes sense to reference page_url here, it will only look
|
||||
# at (url, referer_url).
|
||||
def illust_id
|
||||
return nil if novel_id.present? || fanbox_id.present?
|
||||
return nil if novel_id.present?
|
||||
|
||||
parsed_urls.each do |url|
|
||||
# http://www.pixiv.net/member_illust.php?mode=medium&illust_id=18557054
|
||||
@@ -328,46 +303,11 @@ module Sources
|
||||
end
|
||||
memoize :novel_id
|
||||
|
||||
def fanbox_id
|
||||
[url, referer_url].each do |x|
|
||||
if x =~ FANBOX_PAGE
|
||||
return $1
|
||||
end
|
||||
|
||||
if x =~ FANBOX_IMAGE
|
||||
return $1
|
||||
end
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
memoize :fanbox_id
|
||||
|
||||
def fanbox_account_id
|
||||
[url, referer_url].each do |x|
|
||||
if x =~ FANBOX_ACCOUNT
|
||||
return x
|
||||
end
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
memoize :fanbox_account_id
|
||||
|
||||
def agent
|
||||
PixivWebAgent.build
|
||||
end
|
||||
memoize :agent
|
||||
|
||||
def metadata
|
||||
if novel_id.present?
|
||||
return PixivApiClient.new.novel(novel_id)
|
||||
end
|
||||
|
||||
if fanbox_id.present?
|
||||
return PixivApiClient.new.fanbox(fanbox_id)
|
||||
end
|
||||
|
||||
PixivApiClient.new.work(illust_id)
|
||||
end
|
||||
memoize :metadata
|
||||
|
||||
@@ -122,17 +122,6 @@ module Downloads
|
||||
assert_downloaded(@file_size, @file_url, @ref)
|
||||
end
|
||||
end
|
||||
|
||||
context "downloading a pixiv fanbox image" do
|
||||
should_eventually "work" do
|
||||
@source = "https://www.pixiv.net/fanbox/creator/12491073/post/82406"
|
||||
@file_url = "https://fanbox.pixiv.net/images/post/82406/D833IKA7FIesJXL8xx39rrG0.jpeg"
|
||||
@file_size = 873_387
|
||||
|
||||
assert_not_rewritten(@file_url, @source)
|
||||
assert_downloaded(@file_size, @file_url, @source)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "An ugoira site for pixiv" do
|
||||
|
||||
@@ -73,17 +73,6 @@ module Sources
|
||||
end
|
||||
end
|
||||
|
||||
context "A https://www.pixiv.net/fanbox/creator/*/post/* source" do
|
||||
should_eventually "work" do
|
||||
@site = Sources::Strategies.find("http://www.pixiv.net/fanbox/creator/554149/post/82555")
|
||||
|
||||
assert_equal("TYONE(お仕事募集中)", @site.artist_name)
|
||||
assert_equal("https://www.pixiv.net/member.php?id=554149", @site.profile_url)
|
||||
assert_equal("https://fanbox.pixiv.net/images/post/82555/Lyyeb6dDLcQZmy09nqLZapuS.jpeg", @site.image_url)
|
||||
assert_nothing_raised { @site.to_h }
|
||||
end
|
||||
end
|
||||
|
||||
context "A https://www.pixiv.net/*/artworks/* source" do
|
||||
should "work" do
|
||||
@site = Sources::Strategies.find("https://www.pixiv.net/en/artworks/64476642")
|
||||
|
||||
Reference in New Issue
Block a user