fixes #2299
This commit is contained in:
@@ -20,8 +20,6 @@ module Downloads
|
|||||||
if url =~ %r!\Ahttps?://i\d+\.pixiv\.net/img-zip-ugoira/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/\d+_ugoira\d+x\d+\.zip\z!i
|
if url =~ %r!\Ahttps?://i\d+\.pixiv\.net/img-zip-ugoira/img/\d{4}/\d{2}/\d{2}/\d{2}/\d{2}/\d{2}/\d+_ugoira\d+x\d+\.zip\z!i
|
||||||
data[:is_ugoira] = true
|
data[:is_ugoira] = true
|
||||||
data[:ugoira_frame_data] = source.ugoira_frame_data
|
data[:ugoira_frame_data] = source.ugoira_frame_data
|
||||||
data[:ugoira_width] = source.ugoira_width
|
|
||||||
data[:ugoira_height] = source.ugoira_height
|
|
||||||
data[:ugoira_content_type] = source.ugoira_content_type
|
data[:ugoira_content_type] = source.ugoira_content_type
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -5,17 +5,11 @@ class PixivUgoiraService
|
|||||||
service = new()
|
service = new()
|
||||||
service.load(
|
service.load(
|
||||||
:is_ugoira => true,
|
:is_ugoira => true,
|
||||||
:ugoira_width => post.image_width,
|
|
||||||
:ugoira_height => post.image_height,
|
|
||||||
:ugoira_frame_data => post.pixiv_ugoira_frame_data.data
|
:ugoira_frame_data => post.pixiv_ugoira_frame_data.data
|
||||||
)
|
)
|
||||||
service.generate_resizes(post.file_path, post.large_file_path, post.preview_file_path, false)
|
service.generate_resizes(post.file_path, post.large_file_path, post.preview_file_path, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
def process(post)
|
|
||||||
save_frame_data(post)
|
|
||||||
end
|
|
||||||
|
|
||||||
def save_frame_data(post)
|
def save_frame_data(post)
|
||||||
PixivUgoiraFrameData.create(:data => @frame_data, :content_type => @content_type, :post_id => post.id)
|
PixivUgoiraFrameData.create(:data => @frame_data, :content_type => @content_type, :post_id => post.id)
|
||||||
end
|
end
|
||||||
@@ -33,11 +27,24 @@ class PixivUgoiraService
|
|||||||
FileUtils.touch([output_path, preview_path])
|
FileUtils.touch([output_path, preview_path])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def calculate_dimensions(source_path)
|
||||||
|
folder = Zip::File.new(source_path)
|
||||||
|
tempfile = Tempfile.new("ugoira-dimensions")
|
||||||
|
|
||||||
|
begin
|
||||||
|
folder.first.extract(tempfile.path) {true}
|
||||||
|
image_size = ImageSpec.new(tempfile.path)
|
||||||
|
@width = image_size.width
|
||||||
|
@height = image_size.height
|
||||||
|
ensure
|
||||||
|
tempfile.close
|
||||||
|
tempfile.unlink
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def load(data)
|
def load(data)
|
||||||
if data[:is_ugoira]
|
if data[:is_ugoira]
|
||||||
@frame_data = data[:ugoira_frame_data]
|
@frame_data = data[:ugoira_frame_data]
|
||||||
@width = data[:ugoira_width]
|
|
||||||
@height = data[:ugoira_height]
|
|
||||||
@content_type = data[:ugoira_content_type]
|
@content_type = data[:ugoira_content_type]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
module Sources
|
module Sources
|
||||||
class Site
|
class Site
|
||||||
attr_reader :url, :strategy
|
attr_reader :url, :strategy
|
||||||
delegate :get, :referer_url, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :page_count, :file_url, :ugoira_frame_data, :ugoira_width, :ugoira_height, :to => :strategy
|
delegate :get, :referer_url, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :page_count, :file_url, :ugoira_frame_data, :to => :strategy
|
||||||
|
|
||||||
def self.strategies
|
def self.strategies
|
||||||
[Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie]
|
[Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie]
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ require 'csv'
|
|||||||
module Sources
|
module Sources
|
||||||
module Strategies
|
module Strategies
|
||||||
class Pixiv < Base
|
class Pixiv < Base
|
||||||
attr_reader :zip_url, :ugoira_frame_data, :ugoira_width, :ugoira_height, :ugoira_content_type
|
attr_reader :zip_url, :ugoira_frame_data, :ugoira_content_type
|
||||||
|
|
||||||
def self.url_match?(url)
|
def self.url_match?(url)
|
||||||
url =~ /^https?:\/\/(?:\w+\.)?pixiv\.net/
|
url =~ /^https?:\/\/(?:\w+\.)?pixiv\.net/
|
||||||
@@ -45,7 +45,7 @@ module Sources
|
|||||||
agent.get(URI.parse(normalized_url)) do |page|
|
agent.get(URI.parse(normalized_url)) do |page|
|
||||||
@artist_name, @profile_url = get_profile_from_page(page)
|
@artist_name, @profile_url = get_profile_from_page(page)
|
||||||
@pixiv_moniker = get_moniker_from_page(page)
|
@pixiv_moniker = get_moniker_from_page(page)
|
||||||
@zip_url, @ugoira_frame_data, @ugoira_width, @ugoira_height, @ugoira_content_type = get_zip_url_from_page(page)
|
@zip_url, @ugoira_frame_data, @ugoira_content_type = get_zip_url_from_page(page)
|
||||||
@tags = get_tags_from_page(page)
|
@tags = get_tags_from_page(page)
|
||||||
@page_count = get_page_count_from_page(page)
|
@page_count = get_page_count_from_page(page)
|
||||||
|
|
||||||
@@ -194,15 +194,7 @@ module Sources
|
|||||||
frame_data = data["frames"]
|
frame_data = data["frames"]
|
||||||
content_type = data["mime_type"]
|
content_type = data["mime_type"]
|
||||||
|
|
||||||
if javascript =~ /illustSize\s*=\s*\[\s*(\d+)\s*,\s*(\d+)\s*\]/
|
return [zip_url, frame_data, content_type]
|
||||||
image_width = $1.to_i
|
|
||||||
image_height = $2.to_i
|
|
||||||
else
|
|
||||||
image_width = 600
|
|
||||||
image_height = 600
|
|
||||||
end
|
|
||||||
|
|
||||||
return [zip_url, frame_data, image_width, image_height, content_type]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class Upload < ActiveRecord::Base
|
|||||||
post.distribute_files
|
post.distribute_files
|
||||||
if post.save
|
if post.save
|
||||||
CurrentUser.increment!(:post_upload_count)
|
CurrentUser.increment!(:post_upload_count)
|
||||||
ugoira_service.process(post) if is_ugoira?
|
ugoira_service.save_frame_data(post) if is_ugoira?
|
||||||
update_attributes(:status => "completed", :post_id => post.id)
|
update_attributes(:status => "completed", :post_id => post.id)
|
||||||
else
|
else
|
||||||
update_attribute(:status, "error: " + post.errors.full_messages.join(", "))
|
update_attribute(:status, "error: " + post.errors.full_messages.join(", "))
|
||||||
@@ -250,6 +250,7 @@ class Upload < ActiveRecord::Base
|
|||||||
self.image_width = video.width
|
self.image_width = video.width
|
||||||
self.image_height = video.height
|
self.image_height = video.height
|
||||||
elsif is_ugoira?
|
elsif is_ugoira?
|
||||||
|
ugoira_service.calculate_dimensions(file_path)
|
||||||
self.image_width = ugoira_service.width
|
self.image_width = ugoira_service.width
|
||||||
self.image_height = ugoira_service.height
|
self.image_height = ugoira_service.height
|
||||||
else
|
else
|
||||||
@@ -418,6 +419,10 @@ class Upload < ActiveRecord::Base
|
|||||||
self.uploader_id = CurrentUser.user.id
|
self.uploader_id = CurrentUser.user.id
|
||||||
self.uploader_ip_addr = CurrentUser.ip_addr
|
self.uploader_ip_addr = CurrentUser.ip_addr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def uploader_name
|
||||||
|
User.id_to_name(uploader_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module VideoMethods
|
module VideoMethods
|
||||||
@@ -491,10 +496,6 @@ class Upload < ActiveRecord::Base
|
|||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
include ApiMethods
|
include ApiMethods
|
||||||
|
|
||||||
def uploader_name
|
|
||||||
User.id_to_name(uploader_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def presenter
|
def presenter
|
||||||
@presenter ||= UploadPresenter.new(self)
|
@presenter ||= UploadPresenter.new(self)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -34,11 +34,6 @@ module Sources
|
|||||||
should "capture the frame data" do
|
should "capture the frame data" do
|
||||||
assert_equal([{"file"=>"000000.jpg", "delay"=>200}, {"file"=>"000001.jpg", "delay"=>200}, {"file"=>"000002.jpg", "delay"=>200}, {"file"=>"000003.jpg", "delay"=>200}, {"file"=>"000004.jpg", "delay"=>250}], @site.ugoira_frame_data)
|
assert_equal([{"file"=>"000000.jpg", "delay"=>200}, {"file"=>"000001.jpg", "delay"=>200}, {"file"=>"000002.jpg", "delay"=>200}, {"file"=>"000003.jpg", "delay"=>200}, {"file"=>"000004.jpg", "delay"=>250}], @site.ugoira_frame_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "capture the image dimensions" do
|
|
||||||
assert_equal(60, @site.ugoira_width)
|
|
||||||
assert_equal(60, @site.ugoira_height)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "fetching source data for a new manga image" do
|
context "fetching source data for a new manga image" do
|
||||||
|
|||||||
Reference in New Issue
Block a user