vidibus-fileinfo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.rdoc +79 -0
- data/Rakefile +20 -0
- data/lib/vidibus/fileinfo/base.rb +33 -0
- data/lib/vidibus/fileinfo/processor/image.rb +40 -0
- data/lib/vidibus/fileinfo/processor/video.rb +30 -0
- data/lib/vidibus/fileinfo/version.rb +5 -0
- data/lib/vidibus/fileinfo.rb +96 -0
- data/lib/vidibus-fileinfo.rb +6 -0
- data/spec/files/Jim-Marshall.jpg +0 -0
- data/spec/files/RevAppTest.mp4 +0 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/files.rb +9 -0
- data/spec/support/stubs.rb +4 -0
- data/spec/vidibus/fileinfo/base_spec.rb +65 -0
- data/spec/vidibus/fileinfo/processor/image_spec.rb +38 -0
- data/spec/vidibus/fileinfo/processor/video_spec.rb +57 -0
- data/spec/vidibus/fileinfo_spec.rb +131 -0
- data/vidibus-fileinfo.gemspec +31 -0
- metadata +223 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format nested
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Andre Pankratz
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
= Vidibus::Fileinfo
|
2
|
+
|
3
|
+
Returns various information on image and video files.
|
4
|
+
|
5
|
+
This gem is part of the open source service-oriented {video framework}[http://vidibus.org] Vidibus.
|
6
|
+
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
Add the dependency to the Gemfile of your application:
|
11
|
+
|
12
|
+
gem "vidibus-fileinfo"
|
13
|
+
|
14
|
+
Then call bundle install on your console.
|
15
|
+
|
16
|
+
|
17
|
+
== System requirements
|
18
|
+
|
19
|
+
In order to perform the file inspection, ImageMagick and FFmpeg executables are required.
|
20
|
+
|
21
|
+
Unless ruby already knows about those tools, you'll have to define the path somewhere.
|
22
|
+
In a Rails environment, a good place would be your development.rb and production.rb.
|
23
|
+
|
24
|
+
Example for development environment on OSX:
|
25
|
+
|
26
|
+
# Set path to ImageMagick and FFmpeg executables
|
27
|
+
ENV["PATH"] = "#{ENV["PATH"]}:/opt/local/bin"
|
28
|
+
|
29
|
+
Example for production environment on Debian:
|
30
|
+
|
31
|
+
# Set path to ImageMagick and FFmpeg executables
|
32
|
+
ENV["PATH"] = "#{ENV["PATH"]}:/usr/bin/"
|
33
|
+
|
34
|
+
|
35
|
+
== Usage
|
36
|
+
|
37
|
+
Obtaining information from a file is easy:
|
38
|
+
|
39
|
+
Fileinfo("path/to/myfile.png")
|
40
|
+
# => {:width => 300, height => 200, ... }
|
41
|
+
|
42
|
+
|
43
|
+
=== Image files
|
44
|
+
|
45
|
+
For images, a hash with following data will be returned:
|
46
|
+
|
47
|
+
:width # width of image
|
48
|
+
:height # height of image
|
49
|
+
:size # file size in bytes
|
50
|
+
:bit # depth in bit
|
51
|
+
:content_type # content type of image, e.g. "jpeg"
|
52
|
+
|
53
|
+
This gem currently support these image formats:
|
54
|
+
|
55
|
+
jpg, jpeg, png, gif
|
56
|
+
|
57
|
+
|
58
|
+
=== Video files
|
59
|
+
|
60
|
+
For videos, a different hash will be returned:
|
61
|
+
|
62
|
+
:width # width of video
|
63
|
+
:height # height of video
|
64
|
+
:size # file size in bytes
|
65
|
+
:duration # duration of video in seconds
|
66
|
+
:fps # frames per second
|
67
|
+
:bitrate # overall bit rate (video + audio)
|
68
|
+
:video_codec # codec of video stream, e.g. "h264"
|
69
|
+
:audio_codec # codec of audio stream, e.g. "aac"
|
70
|
+
:audio_sample_rate # sample rate of audio stream, e.g. 48000
|
71
|
+
|
72
|
+
These video formats are currently supported:
|
73
|
+
|
74
|
+
avi, flv, h261, h263, h264, ipod, m4v, mov, mp4, mpeg, mxf, ogg
|
75
|
+
|
76
|
+
|
77
|
+
== Copyright
|
78
|
+
|
79
|
+
Copyright (c) 2011 Andre Pankratz. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "bundler"
|
2
|
+
require "rake/rdoctask"
|
3
|
+
require "rspec"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
Rspec::Core::RakeTask.new(:rcov) do |t|
|
8
|
+
t.pattern = "spec/**/*_spec.rb"
|
9
|
+
t.rcov = true
|
10
|
+
t.rcov_opts = ["--exclude", "^spec,/gems/"]
|
11
|
+
end
|
12
|
+
|
13
|
+
Rake::RDocTask.new do |rdoc|
|
14
|
+
require File.expand_path("../lib/vidibus/fileinfo/version.rb", __FILE__)
|
15
|
+
rdoc.rdoc_dir = "rdoc"
|
16
|
+
rdoc.title = "vidibus-sysinfo #{Vidibus::Fileinfo::VERSION}"
|
17
|
+
rdoc.rdoc_files.include("README*")
|
18
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
19
|
+
rdoc.options << "--charset=utf-8"
|
20
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Vidibus
|
2
|
+
module Fileinfo
|
3
|
+
class Base
|
4
|
+
attr_accessor :path, :processor
|
5
|
+
|
6
|
+
def initialize(path)
|
7
|
+
@path = path
|
8
|
+
check_file
|
9
|
+
load_processor
|
10
|
+
end
|
11
|
+
|
12
|
+
def format
|
13
|
+
@format ||= Fileinfo.format(@path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def mime_type
|
17
|
+
@mime_type ||= Mime::Type.lookup_by_extension(format)
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def check_file
|
23
|
+
raise FileAccessError unless File.exist?(@path)
|
24
|
+
raise NoFileError unless File.file?(@path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_processor
|
28
|
+
@processor = Fileinfo.processor(format)
|
29
|
+
extend @processor
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Vidibus
|
2
|
+
module Fileinfo
|
3
|
+
module Processor
|
4
|
+
module Image
|
5
|
+
FORMATS = %w[jpg jpeg png gif]
|
6
|
+
|
7
|
+
# Extracts image data through ImageMagick.
|
8
|
+
def data
|
9
|
+
raise PathError unless @path
|
10
|
+
@data ||= begin
|
11
|
+
result = perform or raise DataError
|
12
|
+
values = result.to_s.split(" ")
|
13
|
+
raise DataError unless values.size > 5
|
14
|
+
dimensions = values[2].split('x').map {|d| d.to_i}
|
15
|
+
raise DataError unless dimensions.any?
|
16
|
+
{
|
17
|
+
:content_type => values[1].downcase,
|
18
|
+
:width => dimensions[0],
|
19
|
+
:height => dimensions[1],
|
20
|
+
:bit => values[4].to_i,
|
21
|
+
:size => File.size(@path)
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def perform
|
29
|
+
result = `#{command}`
|
30
|
+
raise DataError unless $? == 0
|
31
|
+
result
|
32
|
+
end
|
33
|
+
|
34
|
+
def command
|
35
|
+
"identify #{@path}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Vidibus
|
2
|
+
module Fileinfo
|
3
|
+
module Processor
|
4
|
+
module Video
|
5
|
+
FORMATS = %w[avi flv h261 h263 h264 ipod m4v mov mp4 mpeg mxf ogg]
|
6
|
+
|
7
|
+
# Extracts image data through RVideo, which uses FFmpeg.
|
8
|
+
def data
|
9
|
+
raise PathError unless @path
|
10
|
+
@data ||= begin
|
11
|
+
rvideo = RVideo::Inspector.new(:file => path)
|
12
|
+
raise DataError unless rvideo
|
13
|
+
info = {
|
14
|
+
:width => rvideo.width().to_i,
|
15
|
+
:height => rvideo.height().to_i,
|
16
|
+
:duration => rvideo.duration().to_f/1000,
|
17
|
+
:size => File.size(path),
|
18
|
+
:fps => rvideo.fps().to_f
|
19
|
+
}
|
20
|
+
raise DataError unless info[:width] > 0 and info[:height] > 0 and info[:duration] > 0
|
21
|
+
[:bitrate, :audio_sample_rate, :audio_codec, :video_codec].each do |m|
|
22
|
+
info[m] = rvideo.send(m)
|
23
|
+
end
|
24
|
+
info
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require "fileinfo/base"
|
2
|
+
require "fileinfo/processor/image"
|
3
|
+
require "fileinfo/processor/video"
|
4
|
+
|
5
|
+
module Vidibus
|
6
|
+
module Fileinfo
|
7
|
+
|
8
|
+
class Error < StandardError; end
|
9
|
+
class FileAccessError < Error; end
|
10
|
+
class NoFileError < Error; end
|
11
|
+
class NoFormatError < Error; end
|
12
|
+
class UnitError < Error; end
|
13
|
+
class UnsupportedFormatError < Error; end
|
14
|
+
class ProcessorError < Error; end
|
15
|
+
class PathError < ProcessorError; end
|
16
|
+
class DataError < ProcessorError; end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
|
20
|
+
# Returns a list of available processors.
|
21
|
+
def processors
|
22
|
+
@processors ||= [Processor::Image, Processor::Video]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns a list of processable formats.
|
26
|
+
def formats
|
27
|
+
@formats ||= mapping.keys.sort
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns a processor class for given format.
|
31
|
+
# If no processor matches, an UnsupportedFormatError will be raised.
|
32
|
+
def processor(format)
|
33
|
+
mapping[format.to_s] or raise UnsupportedFormatError
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the format of a given file path.
|
37
|
+
# If no format can be detected, a NoFormatError will be raised.
|
38
|
+
def format(path)
|
39
|
+
if path =~ /(?:\.)([a-z0-9]+)$/i
|
40
|
+
$1.downcase
|
41
|
+
else
|
42
|
+
raise NoFormatError
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Converts given size string with unit to bytes number.
|
47
|
+
#
|
48
|
+
# Example:
|
49
|
+
# Vidibus::Fileinfo.bytes("0.23 MB") #=> 241172
|
50
|
+
#
|
51
|
+
def bytes(value)
|
52
|
+
if value.is_a?(String)
|
53
|
+
value =~ /([\d\.]+)\s*(\w*)/i
|
54
|
+
size = $1.to_f
|
55
|
+
unit = $2.strip.upcase if $2
|
56
|
+
power = case unit
|
57
|
+
when "B", "" : 0
|
58
|
+
when "K", "KB": 1
|
59
|
+
when "M", "MB": 2
|
60
|
+
when "G", "GB": 3
|
61
|
+
when "T", "TB": 4
|
62
|
+
else raise UnitError
|
63
|
+
end
|
64
|
+
factor = 1024**power
|
65
|
+
(size*factor).round
|
66
|
+
elsif value.is_a?(Float)
|
67
|
+
value.round
|
68
|
+
elsif value.is_a?(Integer)
|
69
|
+
value
|
70
|
+
else
|
71
|
+
raise ArgumentError
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
protected
|
76
|
+
|
77
|
+
def mapping
|
78
|
+
@mapping ||= begin
|
79
|
+
map = {}
|
80
|
+
processors.each do |processor|
|
81
|
+
for format in processor::FORMATS
|
82
|
+
map[format] = processor
|
83
|
+
end
|
84
|
+
end
|
85
|
+
map
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Shorthand for Vidibus::Fileinfo::Base.new
|
93
|
+
# Returns data hash.
|
94
|
+
def Fileinfo(path)
|
95
|
+
Vidibus::Fileinfo::Base.new(path).data
|
96
|
+
end
|
Binary file
|
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
|
+
|
4
|
+
require "rubygems"
|
5
|
+
require "rspec"
|
6
|
+
require "rr"
|
7
|
+
require "vidibus-fileinfo"
|
8
|
+
|
9
|
+
require "support/stubs"
|
10
|
+
require "support/files"
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.mock_with :rr
|
14
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Vidibus::Fileinfo::Base do
|
4
|
+
let(:subject) {Vidibus::Fileinfo::Base}
|
5
|
+
let(:jpg_info) {subject.new(jpg_path)}
|
6
|
+
|
7
|
+
describe "initializing" do
|
8
|
+
it "should require one param" do
|
9
|
+
expect {subject.new}.to raise_error(ArgumentError)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise an error if file is not accessible" do
|
13
|
+
expect {
|
14
|
+
subject.new("something")
|
15
|
+
}.to raise_error(Vidibus::Fileinfo::FileAccessError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should raise an error if file is a directory" do
|
19
|
+
expect {
|
20
|
+
subject.new(File.dirname(__FILE__))
|
21
|
+
}.to raise_error(Vidibus::Fileinfo::NoFileError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should raise an error if file format is not supported" do
|
25
|
+
stub_file("/what.ever")
|
26
|
+
expect {
|
27
|
+
subject.new("/what.ever")
|
28
|
+
}.to raise_error(Vidibus::Fileinfo::UnsupportedFormatError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should pass if file is valid" do
|
32
|
+
subject.new(jpg_path).should be_true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should allow access to the processor's methods" do
|
36
|
+
jpg_info.should respond_to(:data)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#format" do
|
41
|
+
it "should return the current file's format" do
|
42
|
+
mock(Vidibus::Fileinfo).format(jpg_path) {"jpg"}
|
43
|
+
jpg_info.format
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#mime_type" do
|
48
|
+
it "should return the current file's mime type" do
|
49
|
+
mock(Mime::Type).lookup_by_extension("jpg") {"image/jpeg"}
|
50
|
+
jpg_info.mime_type
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#path" do
|
55
|
+
it "should return the current file's path" do
|
56
|
+
jpg_info.path.should eql(jpg_path)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#processor" do
|
61
|
+
it "should return the matching processor for given file" do
|
62
|
+
jpg_info.processor.should eql(Vidibus::Fileinfo::Processor::Image)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Vidibus::Fileinfo::Processor::Image do
|
4
|
+
let(:subject) {Vidibus::Fileinfo::Base.new(jpg_path)}
|
5
|
+
|
6
|
+
describe "FORMATS" do
|
7
|
+
it "should include various image formats" do
|
8
|
+
Vidibus::Fileinfo::Processor::Image::FORMATS.should eql(%w[jpg jpeg png gif])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#data" do
|
13
|
+
it "should require @path to be defined" do
|
14
|
+
subject.instance_variable_set("@path", nil)
|
15
|
+
expect {subject.data}.to raise_error(Vidibus::Fileinfo::PathError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should raise an error if ImageMagick fails to extract any data" do
|
19
|
+
stub(subject).perform {""}
|
20
|
+
expect {subject.data}.to raise_error(Vidibus::Fileinfo::DataError)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise an error if ImageMagick fails to extract dimensions" do
|
24
|
+
stub(subject).perform {"Something"}
|
25
|
+
expect {subject.data}.to raise_error(Vidibus::Fileinfo::DataError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return a hash of image attributes" do
|
29
|
+
subject.data.should eql({
|
30
|
+
:content_type => "jpeg",
|
31
|
+
:width => 30,
|
32
|
+
:height => 23,
|
33
|
+
:bit => 8,
|
34
|
+
:size => 14822
|
35
|
+
})
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Vidibus::Fileinfo::Processor::Video do
|
4
|
+
let(:subject) {Vidibus::Fileinfo::Base.new(mp4_path)}
|
5
|
+
|
6
|
+
describe "FORMATS" do
|
7
|
+
it "should include various image formats" do
|
8
|
+
Vidibus::Fileinfo::Processor::Video::FORMATS.should eql(%w[avi flv h261 h263 h264 ipod m4v mov mp4 mpeg mxf ogg])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#data" do
|
13
|
+
it "should require @path to be defined" do
|
14
|
+
subject.instance_variable_set("@path", nil)
|
15
|
+
expect {subject.data}.to raise_error(Vidibus::Fileinfo::PathError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should call RVideo::Inspector.new" do
|
19
|
+
mock(RVideo::Inspector).new(:file => mp4_path) {OpenStruct.new(:width => "10", :height => "10", :duration => "10")}
|
20
|
+
subject.data
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise an error if RVideo::Inspector returns nothing" do
|
24
|
+
stub(RVideo::Inspector).new(:file => mp4_path) {}
|
25
|
+
expect {subject.data}.to raise_error(Vidibus::Fileinfo::DataError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should raise an error if RVideo::Inspector fails to extract height" do
|
29
|
+
stub(RVideo::Inspector).new(:file => mp4_path) {OpenStruct.new(:width => "10", :height => nil, :duration => "10")}
|
30
|
+
expect {subject.data}.to raise_error(Vidibus::Fileinfo::DataError)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should raise an error if RVideo::Inspector fails to extract width" do
|
34
|
+
stub(RVideo::Inspector).new(:file => mp4_path) {OpenStruct.new(:width => nil, :height => "10", :duration => "10")}
|
35
|
+
expect {subject.data}.to raise_error(Vidibus::Fileinfo::DataError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should raise an error if RVideo::Inspector fails to extract duration" do
|
39
|
+
stub(RVideo::Inspector).new(:file => mp4_path) {OpenStruct.new(:width => "10", :height => "10", :duration => nil)}
|
40
|
+
expect {subject.data}.to raise_error(Vidibus::Fileinfo::DataError)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return a hash of image attributes" do
|
44
|
+
subject.data.should eql({
|
45
|
+
:video_codec => "mpeg4",
|
46
|
+
:audio_codec => "aac",
|
47
|
+
:audio_sample_rate => 48000,
|
48
|
+
:height => 405,
|
49
|
+
:width => 720,
|
50
|
+
:fps => 25.0,
|
51
|
+
:duration => 1.92,
|
52
|
+
:bitrate => 602,
|
53
|
+
:size => 144631
|
54
|
+
})
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Vidibus::Fileinfo do
|
4
|
+
let(:subject) {Vidibus::Fileinfo}
|
5
|
+
|
6
|
+
describe ".processors" do
|
7
|
+
it "should return a list of available processor classes" do
|
8
|
+
subject.processors.should eql([Vidibus::Fileinfo::Processor::Image, Vidibus::Fileinfo::Processor::Video])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".formats" do
|
13
|
+
it "should return a list of processable file formats" do
|
14
|
+
subject.formats.should eql(%w[avi flv gif h261 h263 h264 ipod jpeg jpg m4v mov mp4 mpeg mxf ogg png])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".processor" do
|
19
|
+
it "should require a format" do
|
20
|
+
expect {subject.processor}.to raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return the image processor for an image format" do
|
24
|
+
subject.processor("jpg").should eql(Vidibus::Fileinfo::Processor::Image)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return the video processor for a video format" do
|
28
|
+
subject.processor("mp4").should eql(Vidibus::Fileinfo::Processor::Video)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should raise an error for unsupported file formats" do
|
32
|
+
expect {
|
33
|
+
subject.processor("xxx")
|
34
|
+
}.to raise_error(Vidibus::Fileinfo::UnsupportedFormatError)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe ".format" do
|
39
|
+
it "should require a path" do
|
40
|
+
expect {subject.format}.to raise_error(ArgumentError)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return the format of a given file path" do
|
44
|
+
subject.format("/my/face.jpg").should eql("jpg")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return the format in lower case" do
|
48
|
+
subject.format("/my/face.JPG").should eql("jpg")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should raise an error if no format can be detected" do
|
52
|
+
expect {
|
53
|
+
subject.format("/my/face")
|
54
|
+
}.to raise_error(Vidibus::Fileinfo::NoFormatError)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe ".bytes" do
|
59
|
+
it "should require a value" do
|
60
|
+
expect {subject.bytes}.to raise_error(ArgumentError)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return input number" do
|
64
|
+
subject.bytes(1).should eql(1)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should return a rounded input float" do
|
68
|
+
subject.bytes(1.5).should eql(2)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should parse '18942'" do
|
72
|
+
subject.bytes("18942").should eql(18942)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should parse '135 B'" do
|
76
|
+
subject.bytes("135 B").should eql(135)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should parse '1 kB'" do
|
80
|
+
subject.bytes("1 kB").should eql(1024)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should parse '2KB'" do
|
84
|
+
subject.bytes("2KB").should eql(2048)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should parse '2.4k'" do
|
88
|
+
subject.bytes("2.4k").should eql(2458)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should parse '0.23 MB'" do
|
92
|
+
subject.bytes("0.23 MB").should eql(241172)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should parse '5 M'" do
|
96
|
+
subject.bytes("5 M").should eql(5242880)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should parse '1.4gb'" do
|
100
|
+
subject.bytes("1.4482gb").should eql(1554992910)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should parse '4G'" do
|
104
|
+
subject.bytes("4G").should eql(4294967296)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should parse '0.0002 TB'" do
|
108
|
+
subject.bytes("0.0002 TB").should eql(219902326)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should parse '4t'" do
|
112
|
+
subject.bytes("4t").should eql(4398046511104)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should raise an error for unsupported values" do
|
116
|
+
expect {subject.bytes([4.5])}.to raise_error(ArgumentError)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should raise an error for unsupported units" do
|
120
|
+
expect {subject.bytes("5.2 flop/s")}.to raise_error(Vidibus::Fileinfo::UnitError)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "Fileinfo" do
|
126
|
+
it "should be a shorthand for Vidibus::Fileinfo::Base.new and return file data" do
|
127
|
+
mock(Vidibus::Fileinfo::Base).new("/my/face.jpg") {OpenStruct.new}
|
128
|
+
stub.any_instance_of(OpenStruct).data {{:some => "thing"}}
|
129
|
+
Fileinfo("/my/face.jpg").should eql({:some => "thing"})
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/vidibus/fileinfo/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "vidibus-fileinfo"
|
6
|
+
s.version = Vidibus::Fileinfo::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = "Andre Pankratz"
|
9
|
+
s.email = "andre@vidibus.com"
|
10
|
+
s.homepage = "https://github.com/vidibus/vidibus-fileinfo"
|
11
|
+
s.summary = "Returns information about an image or video file."
|
12
|
+
s.description = "Gets width, height, bits and other figures."
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "vidibus-fileinfo"
|
16
|
+
|
17
|
+
s.add_dependency "actionpack", "~> 3.0.4"
|
18
|
+
s.add_dependency "vidibus-core_extensions"
|
19
|
+
s.add_dependency "open4"
|
20
|
+
s.add_dependency "newbamboo-rvideo"
|
21
|
+
|
22
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
23
|
+
s.add_development_dependency "rake"
|
24
|
+
s.add_development_dependency "rspec", "~> 2.0.0.beta.20"
|
25
|
+
s.add_development_dependency "rr"
|
26
|
+
s.add_development_dependency "relevance-rcov"
|
27
|
+
|
28
|
+
s.files = `git ls-files`.split("\n")
|
29
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
30
|
+
s.require_path = 'lib'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,223 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vidibus-fileinfo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andre Pankratz
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-09 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: actionpack
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 4
|
34
|
+
version: 3.0.4
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: vidibus-core_extensions
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: open4
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: newbamboo-rvideo
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
type: :runtime
|
78
|
+
version_requirements: *id004
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: bundler
|
81
|
+
prerelease: false
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 23
|
88
|
+
segments:
|
89
|
+
- 1
|
90
|
+
- 0
|
91
|
+
- 0
|
92
|
+
version: 1.0.0
|
93
|
+
type: :development
|
94
|
+
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rake
|
97
|
+
prerelease: false
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
type: :development
|
108
|
+
version_requirements: *id006
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: rspec
|
111
|
+
prerelease: false
|
112
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 62196427
|
118
|
+
segments:
|
119
|
+
- 2
|
120
|
+
- 0
|
121
|
+
- 0
|
122
|
+
- beta
|
123
|
+
- 20
|
124
|
+
version: 2.0.0.beta.20
|
125
|
+
type: :development
|
126
|
+
version_requirements: *id007
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: rr
|
129
|
+
prerelease: false
|
130
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
hash: 3
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
version: "0"
|
139
|
+
type: :development
|
140
|
+
version_requirements: *id008
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
name: relevance-rcov
|
143
|
+
prerelease: false
|
144
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
153
|
+
type: :development
|
154
|
+
version_requirements: *id009
|
155
|
+
description: Gets width, height, bits and other figures.
|
156
|
+
email: andre@vidibus.com
|
157
|
+
executables: []
|
158
|
+
|
159
|
+
extensions: []
|
160
|
+
|
161
|
+
extra_rdoc_files: []
|
162
|
+
|
163
|
+
files:
|
164
|
+
- .gitignore
|
165
|
+
- .rspec
|
166
|
+
- Gemfile
|
167
|
+
- LICENSE
|
168
|
+
- README.rdoc
|
169
|
+
- Rakefile
|
170
|
+
- lib/vidibus-fileinfo.rb
|
171
|
+
- lib/vidibus/fileinfo.rb
|
172
|
+
- lib/vidibus/fileinfo/base.rb
|
173
|
+
- lib/vidibus/fileinfo/processor/image.rb
|
174
|
+
- lib/vidibus/fileinfo/processor/video.rb
|
175
|
+
- lib/vidibus/fileinfo/version.rb
|
176
|
+
- spec/files/Jim-Marshall.jpg
|
177
|
+
- spec/files/RevAppTest.mp4
|
178
|
+
- spec/spec_helper.rb
|
179
|
+
- spec/support/files.rb
|
180
|
+
- spec/support/stubs.rb
|
181
|
+
- spec/vidibus/fileinfo/base_spec.rb
|
182
|
+
- spec/vidibus/fileinfo/processor/image_spec.rb
|
183
|
+
- spec/vidibus/fileinfo/processor/video_spec.rb
|
184
|
+
- spec/vidibus/fileinfo_spec.rb
|
185
|
+
- vidibus-fileinfo.gemspec
|
186
|
+
has_rdoc: true
|
187
|
+
homepage: https://github.com/vidibus/vidibus-fileinfo
|
188
|
+
licenses: []
|
189
|
+
|
190
|
+
post_install_message:
|
191
|
+
rdoc_options: []
|
192
|
+
|
193
|
+
require_paths:
|
194
|
+
- lib
|
195
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
196
|
+
none: false
|
197
|
+
requirements:
|
198
|
+
- - ">="
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
hash: 3
|
201
|
+
segments:
|
202
|
+
- 0
|
203
|
+
version: "0"
|
204
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
|
+
none: false
|
206
|
+
requirements:
|
207
|
+
- - ">="
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
hash: 23
|
210
|
+
segments:
|
211
|
+
- 1
|
212
|
+
- 3
|
213
|
+
- 6
|
214
|
+
version: 1.3.6
|
215
|
+
requirements: []
|
216
|
+
|
217
|
+
rubyforge_project: vidibus-fileinfo
|
218
|
+
rubygems_version: 1.3.7
|
219
|
+
signing_key:
|
220
|
+
specification_version: 3
|
221
|
+
summary: Returns information about an image or video file.
|
222
|
+
test_files: []
|
223
|
+
|