include whitecube source/rewrite strategies
This commit is contained in:
@@ -10,7 +10,7 @@ module Sources
|
||||
:artist_commentary_desc, :to => :strategy
|
||||
|
||||
def self.strategies
|
||||
[Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie, Strategies::Twitter, Strategies::Tumblr]
|
||||
[Strategies::PixivWhitecube, Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie, Strategies::Twitter, Strategies::Tumblr]
|
||||
end
|
||||
|
||||
def initialize(url, options = {})
|
||||
|
||||
@@ -11,12 +11,13 @@ module Sources
|
||||
TIMESTAMP = '(?:[0-9]{4}/[0-9]{2}/[0-9]{2}/[0-9]{2}/[0-9]{2}/[0-9]{2})'
|
||||
EXT = "(?:jpg|jpeg|png|gif)"
|
||||
|
||||
WHITECUBE = /^https?:\/\/wwww\.pixiv\.net\/whitecube/i
|
||||
WEB = "^(?:https?://)?www\\.pixiv\\.net"
|
||||
I12 = "^(?:https?://)?i[0-9]+\\.pixiv\\.net"
|
||||
IMG = "^(?:https?://)?img[0-9]*\\.pixiv\\.net"
|
||||
|
||||
def self.url_match?(url)
|
||||
url =~ /#{WEB}|#{IMG}|#{I12}/i
|
||||
url !~ WHITECUBE && url =~ /#{WEB}|#{IMG}|#{I12}/i
|
||||
end
|
||||
|
||||
def referer_url
|
||||
|
||||
83
app/logical/sources/strategies/pixiv_whitecube.rb
Normal file
83
app/logical/sources/strategies/pixiv_whitecube.rb
Normal file
@@ -0,0 +1,83 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class PixivWhitecube < Base
|
||||
# sample: http://www.pixiv.net/whitecube/user/277898/illust/59182257
|
||||
WHITECUBE_ILLUST = %r!^https?://www\.pixiv\.net/whitecube/user/\d+/illust/\d+!i
|
||||
|
||||
def self.url_match?(url)
|
||||
url =~ WHITECUBE_ILLUST
|
||||
end
|
||||
|
||||
def referer_url
|
||||
@url
|
||||
end
|
||||
|
||||
def site_name
|
||||
"Pixiv Whitecube"
|
||||
end
|
||||
|
||||
def unique_id
|
||||
@pixiv_moniker
|
||||
end
|
||||
|
||||
def fake_referer
|
||||
"http://www.pixiv.net"
|
||||
end
|
||||
|
||||
def has_artist_commentary?
|
||||
@artist_commentary_desc.present?
|
||||
end
|
||||
|
||||
def normalizable_for_artist_finder?
|
||||
true
|
||||
end
|
||||
|
||||
def normalize_for_artist_finder!
|
||||
"http://img.pixiv.net/img/#{@moniker}/"
|
||||
end
|
||||
|
||||
def get
|
||||
@illust_id = illust_id_from_url
|
||||
@data = query_pixiv_api(@illust_id)
|
||||
|
||||
@artist_name = @data.name
|
||||
@profile_url = "https://www.pixiv.net/whitecube/user/" + @data.user_id.to_s
|
||||
@pixiv_moniker = @data.moniker
|
||||
@zip_url, @ugoira_frame_data = get_zip_url_from_api(@data)
|
||||
@tags = @data.tags
|
||||
@page_count = @data.page_count
|
||||
@artist_commentary_title = @data.artist_commentary_title
|
||||
@artist_commentary_desc = @data.artist_commentary_desc
|
||||
|
||||
is_manga = @page_count > 1
|
||||
|
||||
if !@zip_url
|
||||
@image_url = @data.pages.first
|
||||
end
|
||||
end
|
||||
|
||||
def illust_id_from_url
|
||||
# http://www.pixiv.net/whitecube/user/277898/illust/59182257
|
||||
if url =~ %r!/whitecube/user/\d+/illust/(\d+)!
|
||||
$1
|
||||
|
||||
else
|
||||
raise Sources::Error.new("Couldn't get illust ID from URL: #{url}")
|
||||
end
|
||||
end
|
||||
|
||||
def query_pixiv_api(illust_id)
|
||||
@data ||= PixivApiClient.new.works(illust_id)
|
||||
end
|
||||
|
||||
def get_zip_url_from_api(data)
|
||||
if data.json["metadata"] && data.json["metadata"]["zip_urls"]
|
||||
zip_url = data.json["metadata"]["zip_urls"]["ugoira600x600"].sub("_ugoira600x600.zip", "_ugoira1920x1080.zip")
|
||||
frame_data = data.json["metadata"]["frames"]
|
||||
|
||||
return [zip_url, frame_data]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user