Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/paperclip/av/transcoder/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Paperclip
module Av
module Transcoder
VERSION = "0.6.3"
VERSION = "0.6.4"
end
end
end
10 changes: 10 additions & 0 deletions lib/paperclip/paperclip_processors/transcoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def make
@cli.add_source(@file.path)
@cli.add_destination(dst.path)
@cli.reset_input_filters

if output_is_image?
@time = @time.call(@meta, @options) if @time.respond_to?(:call)
@cli.filter_seek @time
end

if @convert_options.present?
if @convert_options[:input]
@convert_options[:input].each do |h|
Expand Down Expand Up @@ -94,6 +100,10 @@ def format_geometry geometry
return unless geometry.present?
return geometry.gsub(/[#!<>)]/, '')
end

def output_is_image?
[email protected]_s.match(/jpe?g|png|gif$/)
end
end

class Attachment
Expand Down
4 changes: 2 additions & 2 deletions paperclip-av-transcoder.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rails", ">= 4.0.0"
spec.add_development_dependency "sqlite3"
spec.add_development_dependency "coveralls"

spec.add_dependency "paperclip", ">=2.5.2"
spec.add_dependency "av", "~> 0.8.1"
spec.add_dependency "av", "~> 0.9.0"
end
8 changes: 6 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class Document < ActiveRecord::Base
ac: 2
}
}
},
thumb: {
format: 'jpg',
time: 0
}
},
processors: [:transcoder]
Expand All @@ -53,8 +57,8 @@ class Document < ActiveRecord::Base
styles: {
small: "100x100"
},
processors: [:transcoder, :thumbnail]
processors: [:transcoder, :thumbnail]

do_not_validate_attachment_file_type :video
do_not_validate_attachment_file_type :image
end
11 changes: 6 additions & 5 deletions spec/transcoder/transcoder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
describe Paperclip::Transcoder do
let(:supported) { File.new(Dir.pwd + '/spec/support/assets/sample.mp4') }
let(:unsupported) { File.new(File.expand_path('spec/support/assets/image.png')) }

let(:destination) { Pathname.new("#{Dir.tmpdir}/transcoder/") }

describe "supported formats" do
let(:subject) { Paperclip::Transcoder.new(supported) }
let(:document) { Document.create(video: Rack::Test::UploadedFile.new(supported, 'video/mp4')) }

describe ".transcode" do
it { expect(File.exists?(document.video.path(:small))).to eq true }
it { expect(File.exists?(document.video.path(:thumb))).to eq true }
end
end

describe "unsupported formats" do
let(:subject) { Paperclip::Transcoder.new(unsupported) }
let(:document) { Document.create(image: Rack::Test::UploadedFile.new(unsupported, 'image/png')) }
describe ".transcode" do
it { expect(File.exists?(document.image.path(:small))).to eq true }
end
end

end