Skip to content

Commit

Permalink
Adding a MediaInfo response for info action
Browse files Browse the repository at this point in the history
  • Loading branch information
knaveofdiamonds committed Dec 2, 2009
1 parent 80754da commit 756b87a
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/encoding-dot-com.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

1 change: 1 addition & 0 deletions lib/encoding_dot_com/facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def info(media_id)
response = make_request("GetMediaInfo") do |q|
q.mediaid media_id
end
MediaInfo.new(response)
end

private
Expand Down
25 changes: 25 additions & 0 deletions lib/encoding_dot_com/media_info.rb
Original file line number Diff line number Diff line change
@@ -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
66 changes: 66 additions & 0 deletions spec/facade_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.