Skip to content

Commit

Permalink
basic support for text streams
Browse files Browse the repository at this point in the history
  • Loading branch information
derobo authored and greatseth committed Apr 27, 2010
1 parent f378cc7 commit 38946cb
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 3 deletions.
11 changes: 9 additions & 2 deletions lib/mediainfo.rb
Expand Up @@ -107,7 +107,7 @@ def self.version
# AttrReaders depends on this. # AttrReaders depends on this.
def self.supported_attributes; @supported_attributes ||= []; end def self.supported_attributes; @supported_attributes ||= []; end


SECTIONS = [:general, :video, :audio, :image, :menu] SECTIONS = [:general, :video, :audio, :image, :menu, :text]
NON_GENERAL_SECTIONS = SECTIONS - [:general] NON_GENERAL_SECTIONS = SECTIONS - [:general]


attr_reader :streams attr_reader :streams
Expand Down Expand Up @@ -342,6 +342,13 @@ class ImageStream < Stream


def frame_size; "#{width}x#{height}" if width or height; end def frame_size; "#{width}x#{height}" if width or height; end
end end

class TextStream < Stream
mediainfo_attr_reader :stream_id, "ID"
mediainfo_attr_reader :format
mediainfo_attr_reader :codec_id, "Codec ID"
mediainfo_attr_reader :codec_info, "Codec ID/Info"
end


class MenuStream < Stream class MenuStream < Stream
mediainfo_attr_reader :stream_id, "ID" mediainfo_attr_reader :stream_id, "ID"
Expand Down Expand Up @@ -431,7 +438,7 @@ def inspect
super.sub(/@raw_response=".+?", @/, %{@raw_response="...", @}) super.sub(/@raw_response=".+?", @/, %{@raw_response="...", @})
end end


private private
def mediainfo! def mediainfo!
@last_command = "#{path} #{@escaped_full_filename} --Output=XML" @last_command = "#{path} #{@escaped_full_filename} --Output=XML"
run_command! run_command!
Expand Down
41 changes: 41 additions & 0 deletions test/fixtures/subtitle.xml
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<Mediainfo>
<File>
<track type="General">
<Complete_name>/home/derobo/mkv_with_subtitle.mkv</Complete_name>
<Format>Matroska</Format>
<File_size>4.37 GiB</File_size>
<Duration>1h 28mn</Duration>
<Overall_bit_rate>7 061 Kbps</Overall_bit_rate>
<Writing_application>mkvmerge v2.4.0 ('Fumbling Towards Ecstasy') built on Oct 11 2008 20:13:15</Writing_application>
<Writing_library>libebml v0.7.7 + libmatroska v0.8.1</Writing_library>
</track>
<track type="Text">
<ID>1</ID>
<Format>ASS</Format>
<Codec_ID>S_TEXT/ASS</Codec_ID>
<Codec_ID_Info>Advanced Sub Station Alpha</Codec_ID_Info>
<Language>English</Language>
</track>
<track type="Text">
<ID>2</ID>
<Format>SSA</Format>
<Codec_ID>S_TEXT/SSA</Codec_ID>
<Codec_ID_Info>Sub Station Alpha</Codec_ID_Info>
</track>
<track type="Text">
<ID>3</ID>
<Format>UTF-8</Format>
<Codec_ID>S_TEXT/UTF8</Codec_ID>
<Codec_ID_Info>UTF-8 Plain Text</Codec_ID_Info>
<Language>French</Language>
</track>
<track type="Text">
<ID>4</ID>
<Format>VobSub</Format>
<Codec_ID>S_VOBSUB</Codec_ID>
<Codec_ID_Info>The same subtitle format used on DVDs</Codec_ID_Info>
<Language>English</Language>
</track>
</File>
</Mediainfo>
44 changes: 44 additions & 0 deletions test/mediainfo_subtilte_test.rb
@@ -0,0 +1,44 @@
require "test_helper"
require "mediainfo_test_helper"

class MediainfoSubtitleTest < ActiveSupport::TestCase
def setup
@info = mediainfo_mock "subtitle"
end

test 'text streams count' do
assert_equal 4, @info.text.count
end

test "text 1 stream id" do
assert_equal "1", @info.text[0].stream_id
end

test "text 1 Format" do
assert_equal "ASS", @info.text[0].format
end

test "text 1 Codec ID" do
assert_equal "S_TEXT/ASS", @info.text[0].codec_id
end

test "text 1 Codec ID info" do
#assert_equal "Advanced Sub Station Alpha", @info.text[0].codec_id_info
end

test "text 2 stream id" do
assert_equal "2", @info.text[1].stream_id
end

test "text 1 Format" do
assert_equal "SSA", @info.text[1].format
end

test "text 1 Codec ID" do
assert_equal "S_TEXT/SSA", @info.text[1].codec_id
end

test "text 1 Codec ID info" do
#assert_equal "Sub Station Alpha", @info.text[1].codec_id_info
end
end
8 changes: 7 additions & 1 deletion test/mediainfo_test.rb
Expand Up @@ -90,7 +90,13 @@ class MediainfoTest < ActiveSupport::TestCase
:menu_stream_id, :menu_stream_id,
:menu_tagged_date, :menu_tagged_date,
:menu_encoded_date, :menu_encoded_date,
:menu_delay :menu_delay,

### TEXT
:text_codec_id,
:text_codec_info,
:text_format,
:text_stream_id
] ]


Mediainfo.supported_attributes.each do |attribute| Mediainfo.supported_attributes.each do |attribute|
Expand Down

0 comments on commit 38946cb

Please sign in to comment.