Permalink
Browse files

basic support for text streams

  • Loading branch information...
1 parent f378cc7 commit 38946cbe44c5a12db83f90914418b3211076b118 @derobo derobo committed with Apr 22, 2010
Showing with 101 additions and 3 deletions.
  1. +9 −2 lib/mediainfo.rb
  2. +41 −0 test/fixtures/subtitle.xml
  3. +44 −0 test/mediainfo_subtilte_test.rb
  4. +7 −1 test/mediainfo_test.rb
View
@@ -107,7 +107,7 @@ def self.version
# AttrReaders depends on this.
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]
attr_reader :streams
@@ -342,6 +342,13 @@ class ImageStream < Stream
def frame_size; "#{width}x#{height}" if width or height; 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
mediainfo_attr_reader :stream_id, "ID"
@@ -431,7 +438,7 @@ def inspect
super.sub(/@raw_response=".+?", @/, %{@raw_response="...", @})
end
-private
+ private
def mediainfo!
@last_command = "#{path} #{@escaped_full_filename} --Output=XML"
run_command!
@@ -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>
@@ -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
@@ -90,7 +90,13 @@ class MediainfoTest < ActiveSupport::TestCase
:menu_stream_id,
:menu_tagged_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|

0 comments on commit 38946cb

Please sign in to comment.