Class: Mediainfo
- Inherits:
-
Object
- Object
- Mediainfo
- Extended by:
- Forwardable, AttrReaders
- Defined in:
- lib/mediainfo.rb,
lib/mediainfo/attr_readers.rb
Overview
# Mediainfo
Mediainfo is a class wrapping [the mediainfo CLI](mediainfo.sourceforge.net).
## Installation
$ gem install mediainfo -s http://gemcutter.org
## Usage
info = Mediainfo.new "/path/to/file"
That will issue the system call to ‘mediainfo` and parse the output. You can specify an alternate path if necessary:
Mediainfo.path = "/opt/local/bin/mediainfo"
By default, REXML is used as the XML parser. If you’d like, you can configure Mediainfo to use Hpricot or Nokogiri instead using one of the following approaches:
* define the `MEDIAINFO_XML_PARSER` environment variable to be the
name of the parser as you'd pass to a :gem or :require call.
e.g. `export MEDIAINFO_XML_PARSER=nokogiri`
* assign to Mediainfo.xml_parser after you've loaded the gem,
following the same naming conventions mentioned previously.
e.g. `Mediainfo.xml_parser = "hpricot"`
Once you’ve got an instance setup, you can call numerous methods to get a variety of information about a file. Some attributes may be present for some files where others are not, but any supported attribute should at least return ‘nil`.
For a list of all possible attributes supported:
Mediainfo.supported_attributes
## Requirements
This requires at least the following version of the Mediainfo CLI:
MediaInfo Command line,
MediaInfoLib - v0.7.25
Previous versions of this gem(<= 0.5.1) worked against v0.7.11, which did not generate XML output, and is no longer supported.
Defined Under Namespace
Modules: AttrReaders Classes: AudioStream, Error, ExecutionError, GeneralStream, ImageStream, IncompatibleVersionError, Stream, StreamProxy, VideoStream
Constant Summary collapse
- SECTIONS =
[:general, :video, :audio, :image]
- NON_GENERAL_SECTIONS =
SECTIONS - [:general]
Class Attribute Summary collapse
-
.path ⇒ Object
Returns the value of attribute path.
-
.xml_parser ⇒ Object
Returns the value of attribute xml_parser.
Instance Attribute Summary collapse
-
#escaped_full_filename ⇒ Object
readonly
Returns the value of attribute escaped_full_filename.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#full_filename ⇒ Object
readonly
Returns the value of attribute full_filename.
-
#last_command ⇒ Object
readonly
Returns the value of attribute last_command.
-
#parsed_response ⇒ Object
readonly
Returns the value of attribute parsed_response.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#raw_response ⇒ Object
Returns the value of attribute raw_response.
-
#streams ⇒ Object
readonly
Returns the value of attribute streams.
Class Method Summary collapse
- .default_mediainfo_path! ⇒ Object
- .delegate(method_name, stream_type = nil) ⇒ Object
- .load_xml_parser!(parser = xml_parser) ⇒ Object
-
.supported_attributes ⇒ Object
AttrReaders depends on this.
- .version ⇒ Object
Instance Method Summary collapse
-
#initialize(full_filename = nil) ⇒ Mediainfo
constructor
A new instance of Mediainfo.
- #inspect ⇒ Object
- #mediainfo_version ⇒ Object
-
#size ⇒ Object
Size of source file as reported by File.size.
- #xml_parser ⇒ Object
Methods included from AttrReaders
mediainfo_attr_reader, mediainfo_date_reader, mediainfo_duration_reader, mediainfo_int_reader
Constructor Details
#initialize(full_filename = nil) ⇒ Mediainfo
Returns a new instance of Mediainfo.
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/mediainfo.rb', line 329 def initialize(full_filename = nil) if mediainfo_version < "0.7.25" raise IncompatibleVersionError, "Your version of mediainfo, #{mediainfo_version}, " + "is not compatible with this gem. >= 0.7.25 required." end @streams = [] if full_filename @full_filename = File. full_filename @path = File.dirname @full_filename @filename = File.basename @full_filename raise ArgumentError, "need a path to a video file, got nil" unless @full_filename raise ArgumentError, "need a path to a video file, #{@full_filename} does not exist" unless File.exist? @full_filename @escaped_full_filename = @full_filename.shell_escape self.raw_response = mediainfo! end end |
Class Attribute Details
.path ⇒ Object
Returns the value of attribute path.
360 361 362 |
# File 'lib/mediainfo.rb', line 360 def path @path end |
.xml_parser ⇒ Object
Returns the value of attribute xml_parser.
372 373 374 |
# File 'lib/mediainfo.rb', line 372 def xml_parser @xml_parser end |
Instance Attribute Details
#escaped_full_filename ⇒ Object (readonly)
Returns the value of attribute escaped_full_filename.
324 325 326 |
# File 'lib/mediainfo.rb', line 324 def escaped_full_filename @escaped_full_filename end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
324 325 326 |
# File 'lib/mediainfo.rb', line 324 def filename @filename end |
#full_filename ⇒ Object (readonly)
Returns the value of attribute full_filename.
324 325 326 |
# File 'lib/mediainfo.rb', line 324 def full_filename @full_filename end |
#last_command ⇒ Object (readonly)
Returns the value of attribute last_command.
391 392 393 |
# File 'lib/mediainfo.rb', line 391 def last_command @last_command end |
#parsed_response ⇒ Object (readonly)
Returns the value of attribute parsed_response.
324 325 326 |
# File 'lib/mediainfo.rb', line 324 def parsed_response @parsed_response end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
324 325 326 |
# File 'lib/mediainfo.rb', line 324 def path @path end |
#raw_response ⇒ Object
Returns the value of attribute raw_response.
324 325 326 |
# File 'lib/mediainfo.rb', line 324 def raw_response @raw_response end |
#streams ⇒ Object (readonly)
Returns the value of attribute streams.
84 85 86 |
# File 'lib/mediainfo.rb', line 84 def streams @streams end |
Class Method Details
.default_mediainfo_path! ⇒ Object
386 |
# File 'lib/mediainfo.rb', line 386 def self.default_mediainfo_path!; self.path = "mediainfo"; end |
.delegate(method_name, stream_type = nil) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/mediainfo.rb', line 66 def self.delegate(method_name, stream_type = nil) if stream_type == :general def_delegator :"@#{stream_type}_stream", method_name else def_delegator :"@#{stream_type}_stream", method_name, "#{stream_type}_#{method_name}" end end |
.load_xml_parser!(parser = xml_parser) ⇒ Object
362 363 364 365 366 367 368 369 370 |
# File 'lib/mediainfo.rb', line 362 def load_xml_parser!(parser = xml_parser) begin gem parser require parser rescue Gem::LoadError => e raise Gem::LoadError, "your specified XML parser, #{parser.inspect}, could not be loaded: #{e}" end end |
.supported_attributes ⇒ Object
AttrReaders depends on this.
79 |
# File 'lib/mediainfo.rb', line 79 def self.supported_attributes; @supported_attributes ||= []; end |
.version ⇒ Object
74 75 76 |
# File 'lib/mediainfo.rb', line 74 def self.version @version ||= `#{path} --Version`[/v([\d.]+)/, 1] end |
Instance Method Details
#inspect ⇒ Object
393 394 395 |
# File 'lib/mediainfo.rb', line 393 def inspect super.sub(/@raw_response=".+?", @/, %{@raw_response="...", @}) end |
#mediainfo_version ⇒ Object
389 |
# File 'lib/mediainfo.rb', line 389 def mediainfo_version; self.class.version; end |
#size ⇒ Object
Size of source file as reported by File.size. Returns nil if you haven’t yet fired off the system command.
88 |
# File 'lib/mediainfo.rb', line 88 def size; File.size(@full_filename) if @full_filename; end |
#xml_parser ⇒ Object
384 |
# File 'lib/mediainfo.rb', line 384 def xml_parser; self.class.xml_parser; end |