integrate ugoiras into zip+webm+preview
This commit is contained in:
BIN
test/fixtures/ugoira.zip
vendored
Normal file
BIN
test/fixtures/ugoira.zip
vendored
Normal file
Binary file not shown.
1834
test/fixtures/vcr_cassettes/ugoira-converter.yml
vendored
1834
test/fixtures/vcr_cassettes/ugoira-converter.yml
vendored
File diff suppressed because it is too large
Load Diff
@@ -20,9 +20,8 @@ module Downloads
|
||||
|
||||
should "retry three times" do
|
||||
assert_raises(Errno::ETIMEDOUT) do
|
||||
@download.http_get_streaming {}
|
||||
@download.http_get_streaming(@source) {}
|
||||
end
|
||||
assert_equal(3, @download.tries)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -27,7 +27,27 @@ module Downloads
|
||||
assert_rewritten(source, source)
|
||||
end
|
||||
|
||||
context "An ugoira site for pixiv" do
|
||||
setup do
|
||||
@tempfile = Tempfile.new("danbooru-test")
|
||||
@download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654", @tempfile.path)
|
||||
VCR.use_cassette("ugoira-converter", :record => :new_episodes) do
|
||||
@download.download!
|
||||
end
|
||||
end
|
||||
|
||||
teardown do
|
||||
@tempfile.unlink
|
||||
end
|
||||
|
||||
should "download the zip file and update the source" do
|
||||
assert_equal("http://i1.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip", @download.source)
|
||||
end
|
||||
|
||||
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}], @download.data[:ugoira_frame_data])
|
||||
end
|
||||
end
|
||||
|
||||
# Test an old illustration (one uploaded before 2014-09-16). New
|
||||
# /img-original/ and /img-master/ URLs currently don't work for images
|
||||
@@ -80,6 +100,7 @@ module Downloads
|
||||
assert_downloaded(42, @new_medium_thumbnail, "download-pixiv-old-png-new-medium-thumbnail")
|
||||
|
||||
assert_downloaded(@file_size, @new_full_size_image, "download-pixiv-old-png-new-full-size")
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,36 +3,28 @@ require "test_helper"
|
||||
class PixivUgoiraConverterTest < ActiveSupport::TestCase
|
||||
context "An ugoira converter" do
|
||||
setup do
|
||||
@url = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654"
|
||||
@write_file = Tempfile.new("output")
|
||||
@zipped_body = "#{Rails.root}/test/fixtures/ugoira.zip"
|
||||
@write_file = Tempfile.new("converted")
|
||||
@preview_write_file = Tempfile.new("preview")
|
||||
@frame_data = [
|
||||
{"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}
|
||||
]
|
||||
end
|
||||
|
||||
teardown do
|
||||
@write_file.unlink
|
||||
end
|
||||
|
||||
should "output to gif" do
|
||||
@converter = PixivUgoiraConverter.new(@url, @write_file.path, :gif)
|
||||
VCR.use_cassette("ugoira-converter", :record => :new_episodes) do
|
||||
@converter.process!
|
||||
end
|
||||
assert_operator(File.size(@converter.write_path), :>, 1_000)
|
||||
@preview_write_file.unlink
|
||||
end
|
||||
|
||||
should "output to webm" do
|
||||
@converter = PixivUgoiraConverter.new(@url, @write_file.path, :webm)
|
||||
VCR.use_cassette("ugoira-converter", :record => :new_episodes) do
|
||||
@converter.process!
|
||||
end
|
||||
assert_operator(File.size(@converter.write_path), :>, 1_000)
|
||||
@converter = PixivUgoiraConverter.new
|
||||
@converter.convert(@zipped_body, @write_file.path, @preview_write_file.path, @frame_data)
|
||||
assert_operator(File.size(@write_file.path), :>, 1_000)
|
||||
assert_operator(File.size(@preview_write_file.path), :>, 0)
|
||||
end
|
||||
|
||||
# should "output to apng" do
|
||||
# @converter = PixivUgoiraConverter.new(@url, @write_file.path, :apng)
|
||||
# VCR.use_cassette("ugoira-converter", :record => :new_episodes) do
|
||||
# @converter.process!
|
||||
# end
|
||||
# assert_operator(File.size(@converter.write_path), :>, 1_000)
|
||||
# end
|
||||
end
|
||||
end
|
||||
@@ -12,6 +12,28 @@ module Sources
|
||||
end
|
||||
end
|
||||
|
||||
context "An ugoira source site for pixiv" do
|
||||
setup do
|
||||
VCR.use_cassette("ugoira-converter") do
|
||||
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654")
|
||||
@site.get
|
||||
end
|
||||
end
|
||||
|
||||
should "get the file url" do
|
||||
assert_equal("http://i1.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip", @site.file_url)
|
||||
end
|
||||
|
||||
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
|
||||
setup do
|
||||
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46324488", "source-pixiv-new-manga")
|
||||
|
||||
@@ -105,14 +105,20 @@ class UploadTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@url = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654"
|
||||
@upload = FactoryGirl.create(:source_upload, :source => @url, :tag_string => "ugoira")
|
||||
@output_path = "#{Rails.root}/tmp/test.download.webm"
|
||||
@output_file = Tempfile.new("download")
|
||||
end
|
||||
|
||||
teardown do
|
||||
@output_file.unlink
|
||||
end
|
||||
|
||||
should "process successfully" do
|
||||
VCR.use_cassette("ugoira-converter", :record => :new_episodes) do
|
||||
@upload.download_from_source(@output_path)
|
||||
@upload.download_from_source(@output_file.path)
|
||||
end
|
||||
assert_operator(File.size(@output_path), :>, 1_000)
|
||||
assert_operator(File.size(@output_file.path), :>, 1_000)
|
||||
assert_equal("application/zip", @upload.file_header_to_content_type(@output_file.path))
|
||||
assert_equal("zip", @upload.content_type_to_file_ext(@upload.file_header_to_content_type(@output_file.path)))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -229,6 +235,27 @@ class UploadTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "process completely for an ugoira" do
|
||||
@upload = FactoryGirl.create(:source_upload,
|
||||
:source => "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654",
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
)
|
||||
VCR.use_cassette("ugoira-converter", :record => :new_episodes) do
|
||||
assert_difference(["Post.count", "PixivUgoiraFrameData.count"]) do
|
||||
@upload.process!
|
||||
end
|
||||
post = Post.last
|
||||
assert_not_nil(post.pixiv_ugoira_frame_data)
|
||||
assert_equal("0d94800c4b520bf3d8adda08f95d31e2", post.md5)
|
||||
assert_equal(60, post.image_width)
|
||||
assert_equal(60, post.image_height)
|
||||
assert_operator(File.size(post.large_file_path), :>, 0)
|
||||
assert_operator(File.size(post.preview_file_path), :>, 0)
|
||||
end
|
||||
end
|
||||
|
||||
should "process completely for an uploaded image" do
|
||||
@upload = FactoryGirl.create(:jpg_upload,
|
||||
:rating => "s",
|
||||
|
||||
Reference in New Issue
Block a user