Merge branch 'pixiv-whitecube'
This commit is contained in:
@@ -112,10 +112,15 @@ class ArtistsController < ApplicationController
|
||||
end
|
||||
|
||||
def finder
|
||||
@artists = Artist.url_matches(params[:url]).order("id desc").limit(20)
|
||||
if @artists.empty? && params[:referer_url].present? && params[:referer_url] != params[:url]
|
||||
@artists = Artist.url_matches(params[:referer_url]).order("id desc").limit(20)
|
||||
begin
|
||||
@artists = Artist.url_matches(params[:url]).order("id desc").limit(20)
|
||||
if @artists.empty? && params[:referer_url].present? && params[:referer_url] != params[:url]
|
||||
@artists = Artist.url_matches(params[:referer_url]).order("id desc").limit(20)
|
||||
end
|
||||
rescue PixivApiClient::Error => e
|
||||
@artists = []
|
||||
end
|
||||
|
||||
respond_with(@artists) do |format|
|
||||
format.xml do
|
||||
render :xml => @artists.to_xml(:include => [:urls], :root => "artists")
|
||||
@@ -131,5 +136,4 @@ private
|
||||
def load_artist
|
||||
@artist = Artist.find(params[:id])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -53,10 +53,11 @@ module Downloads
|
||||
# http://www.pixiv.net/member_illust.php?mode=big&illust_id=18557054
|
||||
# http://www.pixiv.net/member_illust.php?mode=manga&illust_id=18557054
|
||||
# http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=18557054&page=1
|
||||
# http://www.pixiv.net/whitecube/user/277898/illust/59182257
|
||||
# Plus this:
|
||||
# i2.pixiv.net/img-inf/img/2014/09/25/00/57/24/46170939_64x64.jpg
|
||||
def rewrite_html_pages(url, headers)
|
||||
if url =~ /illust_id=\d+/i || url =~ %r!pixiv\.net/img-inf/img/!i
|
||||
if url =~ /illust_id=\d+/i || url =~ %r!pixiv\.net/img-inf/img/!i || url =~ /illust\/\d+/
|
||||
return [source.file_url, headers]
|
||||
else
|
||||
return [url, headers]
|
||||
|
||||
@@ -6,7 +6,7 @@ class PixivApiClient
|
||||
class Error < Exception ; end
|
||||
|
||||
class WorksResponse
|
||||
attr_reader :json, :pages, :moniker, :page_count
|
||||
attr_reader :json, :pages, :name, :moniker, :user_id, :page_count, :tags
|
||||
attr_reader :artist_commentary_title, :artist_commentary_desc
|
||||
|
||||
def initialize(json)
|
||||
@@ -90,10 +90,13 @@ class PixivApiClient
|
||||
# }
|
||||
|
||||
@json = json
|
||||
@name = json["user"]["name"]
|
||||
@user_id = json["user"]["id"]
|
||||
@moniker = json["user"]["account"]
|
||||
@page_count = json["page_count"].to_i
|
||||
@artist_commentary_title = json["title"]
|
||||
@artist_commentary_desc = json["caption"]
|
||||
@tags = json["tags"]
|
||||
|
||||
if page_count > 1
|
||||
@pages = json["metadata"]["pages"].map {|x| x["image_urls"]["large"]}
|
||||
|
||||
@@ -31,7 +31,7 @@ class PixivUgoiraConverter
|
||||
f.write("# timecode format v2\n")
|
||||
frame_data.each do |img|
|
||||
f.write("#{delay_sum}\n")
|
||||
delay_sum += img["delay"]
|
||||
delay_sum += (img["delay"] || img["delay_msec"])
|
||||
end
|
||||
f.write("#{delay_sum}\n")
|
||||
f.write("#{delay_sum}\n")
|
||||
|
||||
@@ -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 = {})
|
||||
|
||||
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
|
||||
@@ -261,7 +261,7 @@ class Upload < ActiveRecord::Base
|
||||
# by the time this runs we'll have moved source_path to md5_file_path
|
||||
ugoira_service.generate_resizes(md5_file_path, resized_file_path_for(Danbooru.config.large_image_width), resized_file_path_for(Danbooru.config.small_image_width))
|
||||
else
|
||||
ugoira_service.generate_resizes(source_path, resized_file_path_for(Danbooru.config.large_image_width), resized_file_path_for(Danbooru.config.small_image_width))
|
||||
ugoira_service.generate_resizes(source_path, resized_file_path_for(Danbooru.config.large_image_width), resized_file_path_for(Danbooru.config.small_image_width), false)
|
||||
end
|
||||
elsif is_video?
|
||||
generate_video_preview_for(width, height, output_path)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<% if @error_message %>
|
||||
{"success": false, "message": <%= raw @error_message.to_json %>}
|
||||
{"success": false, "message": <%= raw @error_message.encode("utf-8", {:invalid => :replace, :undef => :replace, :replace => "?"}).to_json %>}
|
||||
<% else %>
|
||||
{"success": false, "message": <%= raw @exception.to_s.to_json %>}
|
||||
{"success": false, "message": <%= raw @exception.to_s.encode("utf-8", {:invalid => :replace, :undef => :replace, :replace => "?"}).to_json %>}
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user