mediainfo 0.7.1 → 0.7.2
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/Changelog +4 -0
- data/README.markdown +36 -15
- data/lib/mediainfo.rb +67 -11
- data/mediainfo.gemspec +10 -11
- data/test/mediainfo_multiple_streams_test.rb +11 -1
- data/test/mediainfo_subtilte_test.rb +44 -0
- data/test/mediainfo_test.rb +19 -1
- metadata +18 -15
data/Changelog
CHANGED
data/README.markdown
CHANGED
@@ -3,23 +3,47 @@
|
|
3
3
|
Mediainfo is a class wrapping [the mediainfo CLI](http://mediainfo.sourceforge.net).
|
4
4
|
|
5
5
|
## Installation
|
6
|
-
|
6
|
+
|
7
7
|
$ gem install mediainfo
|
8
|
-
|
8
|
+
|
9
9
|
## Usage
|
10
|
-
|
10
|
+
|
11
11
|
info = Mediainfo.new "/path/to/file"
|
12
|
-
|
12
|
+
|
13
13
|
That will issue the system call to `mediainfo` and parse the output.
|
14
14
|
You can specify an alternate path if necessary:
|
15
|
-
|
15
|
+
|
16
16
|
Mediainfo.path = "/opt/local/bin/mediainfo"
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
|
18
|
+
Once you have an info object, you can start inspecting streams and general metadata.
|
19
|
+
|
20
|
+
info.streams.count # 2
|
21
|
+
info.audio? # true
|
22
|
+
info.video? # true
|
23
|
+
info.image? # false
|
24
|
+
|
25
|
+
When inspecting specific types of streams, you have a couple general API options. The
|
26
|
+
first approach assumes one stream of a given type, a common scenario in many video files,
|
27
|
+
for example.
|
28
|
+
|
29
|
+
info.video.count # 1
|
30
|
+
info.audio.count # 1
|
31
|
+
info.video.duration # 120 (seconds)
|
32
|
+
|
33
|
+
Sometimes you'll have more than one stream of a given type. Quicktime files can often
|
34
|
+
contain artifacts like this from somebody editing a more 'normal' file.
|
35
|
+
|
36
|
+
info = Mediainfo.new "funky.mov"
|
37
|
+
|
38
|
+
info.video? # true
|
39
|
+
info.video.count # 2
|
40
|
+
info.video.duration # raises SingleStreamAPIError !
|
41
|
+
info.video[0].duration # 120
|
42
|
+
info.video[1].duration # 10
|
43
|
+
|
44
|
+
For some more usage examples, please see the very reasonable test suite accompanying the source code
|
45
|
+
for this library. It contains a bunch of relevant usage examples. More docs in the future.. contributions
|
46
|
+
*very* welcome!
|
23
47
|
|
24
48
|
Moving on, REXML is used as the XML parser by default. If you'd like, you can
|
25
49
|
configure Mediainfo to use Hpricot or Nokogiri instead using one of
|
@@ -41,10 +65,6 @@ a variety of information about a file. Some attributes may be present
|
|
41
65
|
for some files where others are not, but any supported attribute
|
42
66
|
should at least return `nil`.
|
43
67
|
|
44
|
-
For a list of all possible attributes supported:
|
45
|
-
|
46
|
-
Mediainfo.supported_attributes
|
47
|
-
|
48
68
|
## Requirements
|
49
69
|
|
50
70
|
This requires at least the following version of the Mediainfo CLI:
|
@@ -61,3 +81,4 @@ generate XML output, and is no longer supported.
|
|
61
81
|
* Peter Vandenberk - [http://github.com/pvdb](http://github.com/pvdb)
|
62
82
|
* Ned Campion - [http://github.com/nedcampion](http://github.com/nedcampion)
|
63
83
|
* Daniel Jagszent - [http://github.com/d--j](http://github.com/d--j)
|
84
|
+
* Robert Mrasek - [http://github.com/derobo](http://github.com/derobo)
|
data/lib/mediainfo.rb
CHANGED
@@ -8,20 +8,49 @@ require "mediainfo/attr_readers"
|
|
8
8
|
Mediainfo is a class wrapping [the mediainfo CLI](http://mediainfo.sourceforge.net).
|
9
9
|
|
10
10
|
## Installation
|
11
|
-
|
12
|
-
$ gem install mediainfo
|
13
|
-
|
11
|
+
|
12
|
+
$ gem install mediainfo
|
13
|
+
|
14
14
|
## Usage
|
15
|
-
|
15
|
+
|
16
16
|
info = Mediainfo.new "/path/to/file"
|
17
|
-
|
17
|
+
|
18
18
|
That will issue the system call to `mediainfo` and parse the output.
|
19
19
|
You can specify an alternate path if necessary:
|
20
|
-
|
20
|
+
|
21
21
|
Mediainfo.path = "/opt/local/bin/mediainfo"
|
22
|
-
|
22
|
+
|
23
|
+
Once you have an info object, you can start inspecting streams and general metadata.
|
24
|
+
|
25
|
+
info.streams.count # 2
|
26
|
+
info.audio? # true
|
27
|
+
info.video? # true
|
28
|
+
info.image? # false
|
29
|
+
|
30
|
+
When inspecting specific types of streams, you have a couple general API options. The
|
31
|
+
first approach assumes one stream of a given type, a common scenario in many video files,
|
32
|
+
for example.
|
33
|
+
|
34
|
+
info.video.count # 1
|
35
|
+
info.audio.count # 1
|
36
|
+
info.video.duration # 120 (seconds)
|
37
|
+
|
38
|
+
Sometimes you'll have more than one stream of a given type. Quicktime files can often
|
39
|
+
contain artifacts like this from somebody editing a more 'normal' file.
|
40
|
+
|
41
|
+
info = Mediainfo.new "funky.mov"
|
42
|
+
|
43
|
+
info.video? # true
|
44
|
+
info.video.count # 2
|
45
|
+
info.video.duration # raises SingleStreamAPIError !
|
46
|
+
info.video[0].duration # 120
|
47
|
+
info.video[1].duration # 10
|
48
|
+
|
49
|
+
For some more usage examples, please see the very reasonable test suite accompanying the source code
|
50
|
+
for this library. It contains a bunch of relevant usage examples. More docs in the future.. contributions
|
51
|
+
*very* welcome!
|
23
52
|
|
24
|
-
|
53
|
+
Moving on, REXML is used as the XML parser by default. If you'd like, you can
|
25
54
|
configure Mediainfo to use Hpricot or Nokogiri instead using one of
|
26
55
|
the following approaches:
|
27
56
|
|
@@ -62,6 +91,7 @@ class Mediainfo
|
|
62
91
|
class Error < StandardError; end
|
63
92
|
class ExecutionError < Error; end
|
64
93
|
class IncompatibleVersionError < Error; end
|
94
|
+
class UnknownVersionError < Error; end
|
65
95
|
|
66
96
|
def self.delegate(method_name, stream_type = nil)
|
67
97
|
if stream_type == :general
|
@@ -72,13 +102,17 @@ class Mediainfo
|
|
72
102
|
end
|
73
103
|
|
74
104
|
def self.version
|
75
|
-
@version ||= `#{
|
105
|
+
@version ||= `#{version_command}`[/v([\d.]+)/, 1]
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.version_command
|
109
|
+
"#{path} --Version"
|
76
110
|
end
|
77
111
|
|
78
112
|
# AttrReaders depends on this.
|
79
113
|
def self.supported_attributes; @supported_attributes ||= []; end
|
80
114
|
|
81
|
-
SECTIONS = [:general, :video, :audio, :image]
|
115
|
+
SECTIONS = [:general, :video, :audio, :image, :menu, :text]
|
82
116
|
NON_GENERAL_SECTIONS = SECTIONS - [:general]
|
83
117
|
|
84
118
|
attr_reader :streams
|
@@ -313,6 +347,20 @@ class Mediainfo
|
|
313
347
|
|
314
348
|
def frame_size; "#{width}x#{height}" if width or height; end
|
315
349
|
end
|
350
|
+
|
351
|
+
class TextStream < Stream
|
352
|
+
mediainfo_attr_reader :stream_id, "ID"
|
353
|
+
mediainfo_attr_reader :format
|
354
|
+
mediainfo_attr_reader :codec_id, "Codec ID"
|
355
|
+
mediainfo_attr_reader :codec_info, "Codec ID/Info"
|
356
|
+
end
|
357
|
+
|
358
|
+
class MenuStream < Stream
|
359
|
+
mediainfo_attr_reader :stream_id, "ID"
|
360
|
+
mediainfo_date_reader :encoded_date
|
361
|
+
mediainfo_date_reader :tagged_date
|
362
|
+
mediainfo_int_reader :delay
|
363
|
+
end
|
316
364
|
|
317
365
|
Mediainfo::SECTIONS.each do |stream_type|
|
318
366
|
class_eval %{
|
@@ -328,6 +376,14 @@ class Mediainfo
|
|
328
376
|
###
|
329
377
|
|
330
378
|
def initialize(full_filename = nil)
|
379
|
+
unless mediainfo_version
|
380
|
+
raise UnknownVersionError,
|
381
|
+
"Unable to determine mediainfo version. " +
|
382
|
+
"We tried: #{self.class.version_command} " +
|
383
|
+
"Are you sure mediainfo is installed at #{self.class.path.inspect}? " +
|
384
|
+
"Set Mediainfo.path = /where/is/mediainfo if it is not in your PATH."
|
385
|
+
end
|
386
|
+
|
331
387
|
if mediainfo_version < "0.7.25"
|
332
388
|
raise IncompatibleVersionError,
|
333
389
|
"Your version of mediainfo, #{mediainfo_version}, " +
|
@@ -395,7 +451,7 @@ class Mediainfo
|
|
395
451
|
super.sub(/@raw_response=".+?", @/, %{@raw_response="...", @})
|
396
452
|
end
|
397
453
|
|
398
|
-
private
|
454
|
+
private
|
399
455
|
def mediainfo!
|
400
456
|
@last_command = "#{path} #{@escaped_full_filename} --Output=XML"
|
401
457
|
run_command!
|
data/mediainfo.gemspec
CHANGED
@@ -2,28 +2,27 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{mediainfo}
|
5
|
-
s.version = "0.7.
|
5
|
+
s.version = "0.7.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date = %q{
|
8
|
+
s.authors = [%q{Seth Thomas Rasmussen}]
|
9
|
+
s.date = %q{2011-05-13}
|
10
10
|
s.description = %q{Mediainfo is a class wrapping the mediainfo CLI (http://mediainfo.sourceforge.net)}
|
11
11
|
s.email = %q{sethrasmussen@gmail.com}
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
s.files = [
|
12
|
+
s.extra_rdoc_files = [%q{LICENSE}, %q{README.markdown}, %q{lib/mediainfo.rb}, %q{lib/mediainfo/attr_readers.rb}, %q{lib/mediainfo/string.rb}]
|
13
|
+
s.files = [%q{Changelog}, %q{LICENSE}, %q{Manifest}, %q{README.markdown}, %q{Rakefile}, %q{index.html.template}, %q{lib/mediainfo.rb}, %q{lib/mediainfo/attr_readers.rb}, %q{lib/mediainfo/string.rb}, %q{mediainfo.gemspec}, %q{test/mediainfo_awaywego_test.rb}, %q{test/mediainfo_broken_embraces_test.rb}, %q{test/mediainfo_dinner_test.rb}, %q{test/mediainfo_hats_test.rb}, %q{test/mediainfo_multiple_streams_test.rb}, %q{test/mediainfo_omen_image_test.rb}, %q{test/mediainfo_string_test.rb}, %q{test/mediainfo_subtilte_test.rb}, %q{test/mediainfo_test.rb}, %q{test/mediainfo_vimeo_test.rb}, %q{test/test_helper.rb}]
|
14
14
|
s.homepage = %q{http://greatseth.github.com/mediainfo}
|
15
|
-
s.rdoc_options = [
|
16
|
-
s.require_paths = [
|
15
|
+
s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Mediainfo}, %q{--main}, %q{README.markdown}]
|
16
|
+
s.require_paths = [%q{lib}]
|
17
17
|
s.rubyforge_project = %q{mediainfo}
|
18
|
-
s.rubygems_version = %q{1.
|
18
|
+
s.rubygems_version = %q{1.8.2}
|
19
19
|
s.summary = %q{Mediainfo is a class wrapping the mediainfo CLI (http://mediainfo.sourceforge.net)}
|
20
|
-
s.test_files = [
|
20
|
+
s.test_files = [%q{test/mediainfo_awaywego_test.rb}, %q{test/mediainfo_broken_embraces_test.rb}, %q{test/mediainfo_dinner_test.rb}, %q{test/mediainfo_hats_test.rb}, %q{test/mediainfo_multiple_streams_test.rb}, %q{test/mediainfo_omen_image_test.rb}, %q{test/mediainfo_string_test.rb}, %q{test/mediainfo_subtilte_test.rb}, %q{test/mediainfo_test.rb}, %q{test/mediainfo_vimeo_test.rb}, %q{test/test_helper.rb}]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
23
|
s.specification_version = 3
|
25
24
|
|
26
|
-
if Gem::Version.new(Gem::
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
26
|
else
|
28
27
|
end
|
29
28
|
else
|
@@ -8,7 +8,7 @@ class MediainfoMultipleStreamsTest < ActiveSupport::TestCase
|
|
8
8
|
|
9
9
|
### GENERAL
|
10
10
|
|
11
|
-
test_stream_type_queries :expect => [:audio, :video]
|
11
|
+
test_stream_type_queries :expect => [:audio, :video, :menu]
|
12
12
|
|
13
13
|
test "format" do
|
14
14
|
assert_equal "MPEG-4", @info.format
|
@@ -513,4 +513,14 @@ class MediainfoMultipleStreamsTest < ActiveSupport::TestCase
|
|
513
513
|
### IMAGE
|
514
514
|
|
515
515
|
mediainfo_test_not_an_image
|
516
|
+
|
517
|
+
### MENU
|
518
|
+
|
519
|
+
test "menu" do
|
520
|
+
assert @info.menu?
|
521
|
+
assert @info.menu.stream_id
|
522
|
+
assert @info.menu.encoded_date
|
523
|
+
assert @info.menu.tagged_date
|
524
|
+
assert @info.menu.delay
|
525
|
+
end
|
516
526
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "mediainfo_test_helper"
|
3
|
+
|
4
|
+
class MediainfoSubtitleTest < ActiveSupport::TestCase
|
5
|
+
def setup
|
6
|
+
@info = mediainfo_mock "subtitle"
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'text streams count' do
|
10
|
+
assert_equal 4, @info.text.count
|
11
|
+
end
|
12
|
+
|
13
|
+
test "text 1 stream id" do
|
14
|
+
assert_equal "1", @info.text[0].stream_id
|
15
|
+
end
|
16
|
+
|
17
|
+
test "text 1 Format" do
|
18
|
+
assert_equal "ASS", @info.text[0].format
|
19
|
+
end
|
20
|
+
|
21
|
+
test "text 1 Codec ID" do
|
22
|
+
assert_equal "S_TEXT/ASS", @info.text[0].codec_id
|
23
|
+
end
|
24
|
+
|
25
|
+
test "text 1 Codec ID info" do
|
26
|
+
#assert_equal "Advanced Sub Station Alpha", @info.text[0].codec_id_info
|
27
|
+
end
|
28
|
+
|
29
|
+
test "text 2 stream id" do
|
30
|
+
assert_equal "2", @info.text[1].stream_id
|
31
|
+
end
|
32
|
+
|
33
|
+
test "text 1 Format" do
|
34
|
+
assert_equal "SSA", @info.text[1].format
|
35
|
+
end
|
36
|
+
|
37
|
+
test "text 1 Codec ID" do
|
38
|
+
assert_equal "S_TEXT/SSA", @info.text[1].codec_id
|
39
|
+
end
|
40
|
+
|
41
|
+
test "text 1 Codec ID info" do
|
42
|
+
#assert_equal "Sub Station Alpha", @info.text[1].codec_id_info
|
43
|
+
end
|
44
|
+
end
|
data/test/mediainfo_test.rb
CHANGED
@@ -83,7 +83,20 @@ class MediainfoTest < ActiveSupport::TestCase
|
|
83
83
|
:image_format,
|
84
84
|
|
85
85
|
:image_width,
|
86
|
-
:image_height
|
86
|
+
:image_height,
|
87
|
+
|
88
|
+
### MENU
|
89
|
+
|
90
|
+
:menu_stream_id,
|
91
|
+
:menu_tagged_date,
|
92
|
+
:menu_encoded_date,
|
93
|
+
:menu_delay,
|
94
|
+
|
95
|
+
### TEXT
|
96
|
+
:text_codec_id,
|
97
|
+
:text_codec_info,
|
98
|
+
:text_format,
|
99
|
+
:text_stream_id
|
87
100
|
]
|
88
101
|
|
89
102
|
Mediainfo.supported_attributes.each do |attribute|
|
@@ -131,4 +144,9 @@ class MediainfoTest < ActiveSupport::TestCase
|
|
131
144
|
Mediainfo.any_instance.stubs(:mediainfo_version).returns("0.7.10")
|
132
145
|
assert_raises(Mediainfo::IncompatibleVersionError) { Mediainfo.new }
|
133
146
|
end
|
147
|
+
|
148
|
+
test "fails obviously when CLI is not installed" do
|
149
|
+
Mediainfo.any_instance.stubs(:mediainfo_version).returns(nil)
|
150
|
+
assert_raises(Mediainfo::UnknownVersionError) { Mediainfo.new }
|
151
|
+
end
|
134
152
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mediainfo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 7
|
8
|
-
- 1
|
9
|
-
version: 0.7.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.7.2
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Seth Thomas Rasmussen
|
@@ -14,8 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
18
|
-
default_executable:
|
13
|
+
date: 2011-05-13 00:00:00 Z
|
19
14
|
dependencies: []
|
20
15
|
|
21
16
|
description: Mediainfo is a class wrapping the mediainfo CLI (http://mediainfo.sourceforge.net)
|
@@ -41,7 +36,17 @@ files:
|
|
41
36
|
- lib/mediainfo/attr_readers.rb
|
42
37
|
- lib/mediainfo/string.rb
|
43
38
|
- mediainfo.gemspec
|
44
|
-
|
39
|
+
- test/mediainfo_awaywego_test.rb
|
40
|
+
- test/mediainfo_broken_embraces_test.rb
|
41
|
+
- test/mediainfo_dinner_test.rb
|
42
|
+
- test/mediainfo_hats_test.rb
|
43
|
+
- test/mediainfo_multiple_streams_test.rb
|
44
|
+
- test/mediainfo_omen_image_test.rb
|
45
|
+
- test/mediainfo_string_test.rb
|
46
|
+
- test/mediainfo_subtilte_test.rb
|
47
|
+
- test/mediainfo_test.rb
|
48
|
+
- test/mediainfo_vimeo_test.rb
|
49
|
+
- test/test_helper.rb
|
45
50
|
homepage: http://greatseth.github.com/mediainfo
|
46
51
|
licenses: []
|
47
52
|
|
@@ -56,24 +61,21 @@ rdoc_options:
|
|
56
61
|
require_paths:
|
57
62
|
- lib
|
58
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
59
65
|
requirements:
|
60
66
|
- - ">="
|
61
67
|
- !ruby/object:Gem::Version
|
62
|
-
segments:
|
63
|
-
- 0
|
64
68
|
version: "0"
|
65
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
66
71
|
requirements:
|
67
72
|
- - ">="
|
68
73
|
- !ruby/object:Gem::Version
|
69
|
-
segments:
|
70
|
-
- 1
|
71
|
-
- 2
|
72
74
|
version: "1.2"
|
73
75
|
requirements: []
|
74
76
|
|
75
77
|
rubyforge_project: mediainfo
|
76
|
-
rubygems_version: 1.
|
78
|
+
rubygems_version: 1.8.2
|
77
79
|
signing_key:
|
78
80
|
specification_version: 3
|
79
81
|
summary: Mediainfo is a class wrapping the mediainfo CLI (http://mediainfo.sourceforge.net)
|
@@ -85,6 +87,7 @@ test_files:
|
|
85
87
|
- test/mediainfo_multiple_streams_test.rb
|
86
88
|
- test/mediainfo_omen_image_test.rb
|
87
89
|
- test/mediainfo_string_test.rb
|
90
|
+
- test/mediainfo_subtilte_test.rb
|
88
91
|
- test/mediainfo_test.rb
|
89
92
|
- test/mediainfo_vimeo_test.rb
|
90
93
|
- test/test_helper.rb
|