Skip to content
Browse files

Adding a MediaInfo response for info action

  • Loading branch information...
1 parent 80754da commit 756b87ad84ed4612b6e8b9a927046914747ba513 @knaveofdiamonds knaveofdiamonds committed
Showing with 94 additions and 0 deletions.
  1. +2 −0 lib/encoding-dot-com.rb
  2. +1 −0 lib/encoding_dot_com/facade.rb
  3. +25 −0 lib/encoding_dot_com/media_info.rb
  4. +66 −0 spec/facade_spec.rb
View
2 lib/encoding-dot-com.rb
@@ -6,3 +6,5 @@
require 'encoding_dot_com/thumbnail_format'
require 'encoding_dot_com/flv_vp6_format'
require 'encoding_dot_com/media_list_item'
+require 'encoding_dot_com/media_info'
+
View
1 lib/encoding_dot_com/facade.rb
@@ -59,6 +59,7 @@ def info(media_id)
response = make_request("GetMediaInfo") do |q|
q.mediaid media_id
end
+ MediaInfo.new(response)
end
private
View
25 lib/encoding_dot_com/media_info.rb
@@ -0,0 +1,25 @@
+require 'parsedate'
+
+module EncodingDotCom
+ # Represents a video or image in the encoding.com queue
+ class MediaInfo
+ attr_reader :bitrate, :duration, :video_codec, :video_bitrate, :frame_rate, :size, :pixel_aspect_ratio, :display_aspect_ratio, :audio_codec, :audio_sample_rate, :audio_channels
+
+ # Creates a MediaInfo object, given a <response> Nokogiri::XML::Node
+ #
+ # See the encoding.com documentation for GetMediaInfo action for more details
+ def initialize(node)
+ @bitrate = (node / "bitrate").text
+ @duration = (node / "duration").text.to_f
+ @video_codec = (node / "video_codec").text
+ @video_bitrate = (node / "video_bitrate").text
+ @frame_rate = (node / "frame_rate").text.to_f
+ @size = (node / "size").text
+ @pixel_aspect_ratio = (node / "pixel_aspect_ratio").text
+ @display_aspect_ratio = (node / "display_aspect_ratio").text
+ @audio_codec = (node / "audio_codec").text
+ @audio_sample_rate = (node / "audio_sample_rate").text.to_i
+ @audio_channels = (node / "audio_channels").text.to_i
+ end
+ end
+end
View
66 spec/facade_spec.rb
@@ -181,5 +181,71 @@ def expect_response_xml(response_xml)
expect_xml_with_xpath("/query/mediaid[text()='5678']")
@facade.cancel(5678)
end
+
+ describe "returned media info object" do
+ before :each do
+ expect_response_xml(<<-END
+ <?xml version="1.0"?>
+ <response>
+ <bitrate>1807k</bitrate>
+ <duration>6464.83</duration>
+ <video_codec>mpeg4</video_codec>
+ <video_bitrate>1679k</video_bitrate>
+ <frame_rate>23.98</frame_rate>
+ <size>640x352</size>
+ <pixel_aspect_ratio>1:1</pixel_aspect_ratio>
+ <display_aspect_ratio>20:11</display_aspect_ratio>
+ <audio_codec>ac3</audio_codec>
+ <audio_sample_rate>48000</audio_sample_rate>
+ <audio_channels>2</audio_channels>
+ </response>
+ END
+ )
+ end
+
+ it "should have a bitrate" do
+ @facade.info(1234).bitrate.should == "1807k"
+ end
+
+ it "should have a duration" do
+ @facade.info(1234).duration.should == 6464.83
+ end
+
+ it "should have a video_codec" do
+ @facade.info(1234).video_codec.should == "mpeg4"
+ end
+
+ it "should have a video_bitrate" do
+ @facade.info(1234).video_bitrate.should == "1679k"
+ end
+
+ it "should have a frame rate" do
+ @facade.info(1234).frame_rate.should == 23.98
+ end
+
+ it "should have a size" do
+ @facade.info(1234).size.should == "640x352"
+ end
+
+ it "should hava a pixel aspect ratio" do
+ @facade.info(1234).pixel_aspect_ratio.should == "1:1"
+ end
+
+ it "should have a display aspect ratio" do
+ @facade.info(1234).display_aspect_ratio.should == "20:11"
+ end
+
+ it "should have an audio codec" do
+ @facade.info(1234).audio_codec.should == "ac3"
+ end
+
+ it "should have an audio sample rate" do
+ @facade.info(1234).audio_sample_rate.should == 48_000
+ end
+
+ it "should have audio channels" do
+ @facade.info(1234).audio_channels.should == 2
+ end
+ end
end
end

0 comments on commit 756b87a

Please sign in to comment.
Something went wrong with that request. Please try again.