seamus 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Seamus.gemspec +11 -3
- data/VERSION +1 -1
- data/lib/Seamus.rb +8 -0
- data/lib/seamus/inspector/application_inspector.rb +3 -11
- data/lib/seamus/inspector/audio_inspector.rb +7 -10
- data/lib/seamus/inspector/image_inspector.rb +25 -0
- data/lib/seamus/inspector/video_inspector.rb +6 -9
- data/lib/seamus/inspector.rb +15 -0
- data/lib/seamus/processor/audio_processor.rb +0 -7
- data/lib/seamus/processor/image_processor.rb +21 -0
- data/lib/seamus/processor/video_processor.rb +0 -7
- data/lib/seamus/processor.rb +11 -0
- data/spec/Seamus_spec.rb +12 -3
- data/spec/lib/core/numeric_spec.rb +23 -0
- data/spec/lib/seamus/inspector/image_inspector_spec.rb +43 -0
- data/spec/lib/seamus/processor/image_processor_spec.rb +19 -0
- data/spec/spec_helper.rb +1 -1
- metadata +10 -2
data/Seamus.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{seamus}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Scott Burton"]
|
9
|
-
s.date = %q{2009-12-
|
9
|
+
s.date = %q{2009-12-03}
|
10
10
|
s.description = %q{Seamus is not an Irish monk. Instead, it inspects a file and returns whatever metadata it can determine.}
|
11
11
|
s.email = %q{scottburton11@gmail.com}
|
12
12
|
s.extra_rdoc_files = [
|
@@ -30,12 +30,17 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/seamus/inspector.rb",
|
31
31
|
"lib/seamus/inspector/application_inspector.rb",
|
32
32
|
"lib/seamus/inspector/audio_inspector.rb",
|
33
|
+
"lib/seamus/inspector/image_inspector.rb",
|
33
34
|
"lib/seamus/inspector/video_inspector.rb",
|
34
35
|
"lib/seamus/processor.rb",
|
35
36
|
"lib/seamus/processor/application_processor.rb",
|
36
37
|
"lib/seamus/processor/audio_processor.rb",
|
38
|
+
"lib/seamus/processor/image_processor.rb",
|
37
39
|
"lib/seamus/processor/video_processor.rb",
|
38
40
|
"spec/Seamus_spec.rb",
|
41
|
+
"spec/lib/core/numeric_spec.rb",
|
42
|
+
"spec/lib/seamus/inspector/image_inspector_spec.rb",
|
43
|
+
"spec/lib/seamus/processor/image_processor_spec.rb",
|
39
44
|
"spec/spec_helper.rb"
|
40
45
|
]
|
41
46
|
s.homepage = %q{http://github.com/scottburton11/Seamus}
|
@@ -44,7 +49,10 @@ Gem::Specification.new do |s|
|
|
44
49
|
s.rubygems_version = %q{1.3.5}
|
45
50
|
s.summary = %q{Seamus is not an Irish monk}
|
46
51
|
s.test_files = [
|
47
|
-
"spec/
|
52
|
+
"spec/lib/core/numeric_spec.rb",
|
53
|
+
"spec/lib/seamus/inspector/image_inspector_spec.rb",
|
54
|
+
"spec/lib/seamus/processor/image_processor_spec.rb",
|
55
|
+
"spec/Seamus_spec.rb",
|
48
56
|
"spec/spec_helper.rb"
|
49
57
|
]
|
50
58
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/Seamus.rb
CHANGED
@@ -9,10 +9,12 @@ require 'core/numeric'
|
|
9
9
|
require 'seamus/inspector'
|
10
10
|
require 'seamus/inspector/video_inspector'
|
11
11
|
require 'seamus/inspector/audio_inspector'
|
12
|
+
require 'seamus/inspector/image_inspector'
|
12
13
|
require 'seamus/inspector/application_inspector'
|
13
14
|
require 'seamus/processor'
|
14
15
|
require 'seamus/processor/video_processor'
|
15
16
|
require 'seamus/processor/audio_processor'
|
17
|
+
require 'seamus/processor/image_processor'
|
16
18
|
require 'seamus/processor/application_processor'
|
17
19
|
require 'mime_table'
|
18
20
|
|
@@ -74,6 +76,10 @@ module Seamus
|
|
74
76
|
Base64.encode64(md5.digest).strip
|
75
77
|
end
|
76
78
|
|
79
|
+
def content_type
|
80
|
+
MimeTable.lookup_by_extension(extension).to_s
|
81
|
+
end
|
82
|
+
|
77
83
|
def thumbnail(&block)
|
78
84
|
@thumbnail ||= generate_thumbnail
|
79
85
|
if block_given?
|
@@ -100,6 +106,8 @@ module Seamus
|
|
100
106
|
processor.thumbnail
|
101
107
|
rescue ThumbnailError => e
|
102
108
|
return nil
|
109
|
+
rescue NameError
|
110
|
+
return nil
|
103
111
|
end
|
104
112
|
end
|
105
113
|
|
@@ -1,22 +1,14 @@
|
|
1
1
|
module Seamus
|
2
2
|
class ApplicationInspector < Inspector
|
3
|
-
|
4
|
-
def initialize(file_path)
|
5
|
-
@file = File.new(file_path)
|
6
|
-
end
|
7
3
|
|
8
4
|
def stats
|
9
|
-
inspection_attributes
|
5
|
+
inspection_attributes
|
10
6
|
end
|
11
7
|
|
12
8
|
private
|
13
9
|
|
14
|
-
def
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
def inspection_attributes(stat)
|
19
|
-
attr_hash = {"size" => stat.size}
|
10
|
+
def inspection_attributes
|
11
|
+
attr_hash = {"size" => file_stat.size}
|
20
12
|
return attr_hash
|
21
13
|
end
|
22
14
|
|
@@ -1,29 +1,26 @@
|
|
1
1
|
module Seamus
|
2
2
|
class AudioInspector < Inspector
|
3
|
-
|
4
|
-
def initialize(file_path)
|
5
|
-
@file = File.new(file_path)
|
6
|
-
end
|
7
3
|
|
8
4
|
def stats
|
9
|
-
inspection_attributes
|
5
|
+
inspection_attributes
|
10
6
|
end
|
11
7
|
|
12
8
|
private
|
13
9
|
|
14
|
-
def inspection_attributes
|
10
|
+
def inspection_attributes
|
15
11
|
attr_hash = {}
|
16
12
|
["audio?", "audio_bitrate", "audio_channels", "audio_channels_string", "audio_codec", "audio_sample_rate", "audio_sample_units", "bitrate", "bitrate_units", "container", "duration"].each do |attribute|
|
17
|
-
attr_hash[attribute.to_s] =
|
13
|
+
attr_hash[attribute.to_s] = media_stat.send(attribute) if media_stat.respond_to?(attribute)
|
18
14
|
end
|
15
|
+
attr_hash.merge!("size" => file_stat.size)
|
19
16
|
return attr_hash
|
20
17
|
end
|
21
18
|
|
22
|
-
def
|
23
|
-
RVideo::Inspector.new(:raw_response => raw_response
|
19
|
+
def media_stat
|
20
|
+
RVideo::Inspector.new(:raw_response => raw_response)
|
24
21
|
end
|
25
22
|
|
26
|
-
def raw_response
|
23
|
+
def raw_response
|
27
24
|
process = IO.popen("ffmpeg -i '#{file.path}' 2>&1", "r")
|
28
25
|
response = process.read
|
29
26
|
process.close
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'devil'
|
2
|
+
|
3
|
+
module Seamus
|
4
|
+
class ImageInspector < Inspector
|
5
|
+
def stats
|
6
|
+
inspection_attributes
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def inspection_attributes
|
12
|
+
attr_hash = {}
|
13
|
+
["width", "height"].each do |attribute|
|
14
|
+
attr_hash[attribute] ||= image.send(attribute.to_sym) if image.respond_to?(attribute)
|
15
|
+
end
|
16
|
+
attr_hash.merge!("size" => file_stat.size)
|
17
|
+
return attr_hash
|
18
|
+
end
|
19
|
+
|
20
|
+
def image
|
21
|
+
@image ||= Devil.load_image(file.path)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -1,25 +1,22 @@
|
|
1
1
|
module Seamus
|
2
2
|
class VideoInspector < Inspector
|
3
|
-
|
4
|
-
def initialize(file_path)
|
5
|
-
@file = File.new(file_path)
|
6
|
-
end
|
7
|
-
|
3
|
+
|
8
4
|
def stats
|
9
|
-
inspection_attributes
|
5
|
+
inspection_attributes
|
10
6
|
end
|
11
7
|
|
12
8
|
private
|
13
9
|
|
14
|
-
def inspection_attributes
|
10
|
+
def inspection_attributes
|
15
11
|
attr_hash = {}
|
16
12
|
["audio?", "audio_bitrate", "audio_channels", "audio_channels_string", "audio_codec", "audio_sample_rate", "audio_sample_units", "bitrate", "bitrate_units", "container", "duration", "fps", "height", "video?", "video_codec", "video_colorspace", "width"].each do |attribute|
|
17
|
-
attr_hash[attribute.to_s] =
|
13
|
+
attr_hash[attribute.to_s] = media_stat.send(attribute) if media_stat.respond_to?(attribute)
|
18
14
|
end
|
15
|
+
attr_hash.merge!("size" => file_stat.size)
|
19
16
|
return attr_hash
|
20
17
|
end
|
21
18
|
|
22
|
-
def
|
19
|
+
def media_stat
|
23
20
|
RVideo::Inspector.new(:raw_response => raw_response)
|
24
21
|
end
|
25
22
|
|
data/lib/seamus/inspector.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
module Seamus
|
2
2
|
class Inspector
|
3
|
+
attr_reader :file
|
4
|
+
|
5
|
+
def initialize(file_path)
|
6
|
+
@file = File.open(file_path, "r")
|
7
|
+
end
|
3
8
|
|
9
|
+
def stats
|
10
|
+
raise RuntimeError, "method called on base class"
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def file_stat
|
16
|
+
File::Stat.new(file.path)
|
17
|
+
end
|
18
|
+
|
4
19
|
end
|
5
20
|
end
|
@@ -1,12 +1,5 @@
|
|
1
1
|
module Seamus
|
2
2
|
class AudioProcessor < Processor
|
3
|
-
|
4
|
-
attr_reader :file_attributes
|
5
|
-
|
6
|
-
def initialize(file_path, file_attributes)
|
7
|
-
@file = File.open(file_path, "r")
|
8
|
-
@file_attributes = file_attributes
|
9
|
-
end
|
10
3
|
|
11
4
|
def thumbnail
|
12
5
|
raise ThumbnailError, "invalid type for thumbnail"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Seamus
|
2
|
+
class ImageProcessor < Processor
|
3
|
+
require 'devil'
|
4
|
+
|
5
|
+
def thumbnail
|
6
|
+
tmp = thumb_tempfile
|
7
|
+
Devil.load_image(file.path) do |img|
|
8
|
+
img.thumbnail(320)
|
9
|
+
img.save("#{file.path}_#{File.basename(file.path)}_thumb.jpg")
|
10
|
+
end
|
11
|
+
File.open("#{file.path}_#{File.basename(file.path)}_thumb.jpg", "r") do |thumb|
|
12
|
+
tmp.write thumb.read
|
13
|
+
end
|
14
|
+
tmp.close
|
15
|
+
File.unlink("#{file.path}_#{File.basename(file.path)}_thumb.jpg")
|
16
|
+
return tmp
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -1,13 +1,6 @@
|
|
1
1
|
module Seamus
|
2
2
|
class VideoProcessor < Processor
|
3
3
|
|
4
|
-
attr_reader :file_attributes
|
5
|
-
|
6
|
-
def initialize(file_path, file_attributes)
|
7
|
-
@file_attributes = file_attributes
|
8
|
-
@file = File.open(file_path, "r")
|
9
|
-
end
|
10
|
-
|
11
4
|
def thumbnail
|
12
5
|
thumb = thumb_tempfile
|
13
6
|
IO.popen("ffmpeg -y -ss #{start_time} -i '#{@file.path}' -t 00:00:01 -vcodec mjpeg -vframes 1 -an -f rawvideo -s #{dimensions_string} - 2> /dev/null") do |io|
|
data/lib/seamus/processor.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
module Seamus
|
2
2
|
class Processor
|
3
|
+
attr_reader :file, :file_attributes
|
4
|
+
|
5
|
+
def initialize(file_path, file_attributes)
|
6
|
+
@file = File.open(file_path, "r")
|
7
|
+
@file_attributes = file_attributes
|
8
|
+
end
|
9
|
+
|
10
|
+
# nodoc
|
11
|
+
def thumb_tempfile
|
12
|
+
Tempfile.new("#{File.basename(@file.path, File.extname(@file.path))}_thumb.jpg")
|
13
|
+
end
|
3
14
|
|
4
15
|
end
|
5
16
|
end
|
data/spec/Seamus_spec.rb
CHANGED
@@ -1,7 +1,16 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
|
3
|
+
describe Seamus do
|
4
|
+
|
5
|
+
describe "thumbnail" do
|
6
|
+
|
7
|
+
describe "failure" do
|
8
|
+
|
9
|
+
class InspectableFile
|
10
|
+
include Seamus
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
6
15
|
end
|
7
16
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Numeric do
|
4
|
+
describe "evenize" do
|
5
|
+
it "rounds an odd number up to the nearest even number" do
|
6
|
+
127.evenize.should eql(128)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "rounds an odd number down to the nearest even number" do
|
10
|
+
127.evenize("-").should eql(126)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "oddize" do
|
15
|
+
it "rounds an even number up to the nearest odd number" do
|
16
|
+
256.oddize.should eql(257)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "rounds an even number down to the nearest odd number" do
|
20
|
+
256.oddize("-").should eql(255)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/../../../spec_helper.rb"
|
2
|
+
|
3
|
+
describe Seamus::ImageInspector do
|
4
|
+
|
5
|
+
include FakeFS::SpecHelpers
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
FileUtils.touch("./image.jpg")
|
9
|
+
@inspector = Seamus::ImageInspector.new("./image.jpg")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "responds to #stats" do
|
13
|
+
@inspector.should respond_to(:stats)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "stats" do
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
@image = mock(Devil::Image, :width => 100, :height => 100)
|
20
|
+
@file_stat = mock(File::Stat, :size => 100)
|
21
|
+
@inspector.should_receive(:image).any_number_of_times.and_return(@image)
|
22
|
+
@inspector.should_receive(:file_stat).and_return(@file_stat)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns a hash" do
|
26
|
+
@inspector.stats.should be_an_instance_of(Hash)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "assigns :width" do
|
30
|
+
@inspector.stats["width"].should eql(100)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "assigns :height" do
|
34
|
+
@inspector.stats["height"].should eql(100)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "assigns :size" do
|
38
|
+
@inspector.stats["size"].should eql(100)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/../../../spec_helper.rb"
|
2
|
+
|
3
|
+
describe Seamus::ImageProcessor do
|
4
|
+
|
5
|
+
# include FakeFS::SpecHelpers
|
6
|
+
|
7
|
+
# before(:each) do
|
8
|
+
# FileUtils.touch("./image.jpg")
|
9
|
+
# @file_attributes = {"width" => 100, "height" => 100, "size" => 100}
|
10
|
+
# @processor = Seamus::ImageProcessor.new("./image.jpg", @file_attributes)
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# describe "thumbnail" do
|
14
|
+
# it "is an instance of Tempfile" do
|
15
|
+
# @processor.thumbnail.should be_an_instance_of(Tempfile)
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
|
19
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seamus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Burton
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-03 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -39,12 +39,17 @@ files:
|
|
39
39
|
- lib/seamus/inspector.rb
|
40
40
|
- lib/seamus/inspector/application_inspector.rb
|
41
41
|
- lib/seamus/inspector/audio_inspector.rb
|
42
|
+
- lib/seamus/inspector/image_inspector.rb
|
42
43
|
- lib/seamus/inspector/video_inspector.rb
|
43
44
|
- lib/seamus/processor.rb
|
44
45
|
- lib/seamus/processor/application_processor.rb
|
45
46
|
- lib/seamus/processor/audio_processor.rb
|
47
|
+
- lib/seamus/processor/image_processor.rb
|
46
48
|
- lib/seamus/processor/video_processor.rb
|
47
49
|
- spec/Seamus_spec.rb
|
50
|
+
- spec/lib/core/numeric_spec.rb
|
51
|
+
- spec/lib/seamus/inspector/image_inspector_spec.rb
|
52
|
+
- spec/lib/seamus/processor/image_processor_spec.rb
|
48
53
|
- spec/spec_helper.rb
|
49
54
|
has_rdoc: true
|
50
55
|
homepage: http://github.com/scottburton11/Seamus
|
@@ -75,5 +80,8 @@ signing_key:
|
|
75
80
|
specification_version: 3
|
76
81
|
summary: Seamus is not an Irish monk
|
77
82
|
test_files:
|
83
|
+
- spec/lib/core/numeric_spec.rb
|
84
|
+
- spec/lib/seamus/inspector/image_inspector_spec.rb
|
85
|
+
- spec/lib/seamus/processor/image_processor_spec.rb
|
78
86
|
- spec/Seamus_spec.rb
|
79
87
|
- spec/spec_helper.rb
|