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
|
||||
data[:is_ugoira] = true
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
@@ -5,17 +5,11 @@ class PixivUgoiraService
|
||||
service = new()
|
||||
service.load(
|
||||
:is_ugoira => true,
|
||||
:ugoira_width => post.image_width,
|
||||
:ugoira_height => post.image_height,
|
||||
:ugoira_frame_data => post.pixiv_ugoira_frame_data.data
|
||||
)
|
||||
service.generate_resizes(post.file_path, post.large_file_path, post.preview_file_path, false)
|
||||
end
|
||||
|
||||
def process(post)
|
||||
save_frame_data(post)
|
||||
end
|
||||
|
||||
def save_frame_data(post)
|
||||
PixivUgoiraFrameData.create(:data => @frame_data, :content_type => @content_type, :post_id => post.id)
|
||||
end
|
||||
@@ -33,11 +27,24 @@ class PixivUgoiraService
|
||||
FileUtils.touch([output_path, preview_path])
|
||||
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)
|
||||
if data[:is_ugoira]
|
||||
@frame_data = data[:ugoira_frame_data]
|
||||
@width = data[:ugoira_width]
|
||||
@height = data[:ugoira_height]
|
||||
@content_type = data[:ugoira_content_type]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
module Sources
|
||||
class Site
|
||||
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
|
||||
[Strategies::Pixiv, Strategies::NicoSeiga, Strategies::DeviantArt, Strategies::Nijie]
|
||||
|
||||
@@ -5,7 +5,7 @@ require 'csv'
|
||||
module Sources
|
||||
module Strategies
|
||||
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)
|
||||
url =~ /^https?:\/\/(?:\w+\.)?pixiv\.net/
|
||||
@@ -45,7 +45,7 @@ module Sources
|
||||
agent.get(URI.parse(normalized_url)) do |page|
|
||||
@artist_name, @profile_url = get_profile_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)
|
||||
@page_count = get_page_count_from_page(page)
|
||||
|
||||
@@ -194,15 +194,7 @@ module Sources
|
||||
frame_data = data["frames"]
|
||||
content_type = data["mime_type"]
|
||||
|
||||
if javascript =~ /illustSize\s*=\s*\[\s*(\d+)\s*,\s*(\d+)\s*\]/
|
||||
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]
|
||||
return [zip_url, frame_data, content_type]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ class Upload < ActiveRecord::Base
|
||||
post.distribute_files
|
||||
if post.save
|
||||
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)
|
||||
else
|
||||
update_attribute(:status, "error: " + post.errors.full_messages.join(", "))
|
||||
@@ -250,6 +250,7 @@ class Upload < ActiveRecord::Base
|
||||
self.image_width = video.width
|
||||
self.image_height = video.height
|
||||
elsif is_ugoira?
|
||||
ugoira_service.calculate_dimensions(file_path)
|
||||
self.image_width = ugoira_service.width
|
||||
self.image_height = ugoira_service.height
|
||||
else
|
||||
@@ -418,6 +419,10 @@ class Upload < ActiveRecord::Base
|
||||
self.uploader_id = CurrentUser.user.id
|
||||
self.uploader_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def uploader_name
|
||||
User.id_to_name(uploader_id)
|
||||
end
|
||||
end
|
||||
|
||||
module VideoMethods
|
||||
@@ -491,10 +496,6 @@ class Upload < ActiveRecord::Base
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def uploader_name
|
||||
User.id_to_name(uploader_id)
|
||||
end
|
||||
|
||||
def presenter
|
||||
@presenter ||= UploadPresenter.new(self)
|
||||
end
|
||||
|
||||
@@ -34,11 +34,6 @@ module Sources
|
||||
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)
|
||||
end
|
||||
|
||||
should "capture the image dimensions" do
|
||||
assert_equal(60, @site.ugoira_width)
|
||||
assert_equal(60, @site.ugoira_height)
|
||||
end
|
||||
end
|
||||
|
||||
context "fetching source data for a new manga image" do
|
||||
|
||||
Reference in New Issue
Block a user