Class: TranscodingMachine::Server::ExifToolIntegrator
- Inherits:
-
Object
- Object
- TranscodingMachine::Server::ExifToolIntegrator
- Defined in:
- lib/transcoding_machine/server/media_file_attributes.rb
Constant Summary collapse
- BINARY =
["exiftool"]
- OPTIONS =
["-q", "-q", "-s", "-t"]
- TIMEOUT =
60
Instance Attribute Summary collapse
-
#aspect_ratio ⇒ Object
Returns the value of attribute aspect_ratio.
-
#height ⇒ Object
Returns the value of attribute height.
-
#poster_time ⇒ Object
Returns the value of attribute poster_time.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(file_path) ⇒ ExifToolIntegrator
constructor
A new instance of ExifToolIntegrator.
Constructor Details
#initialize(file_path) ⇒ ExifToolIntegrator
Returns a new instance of ExifToolIntegrator.
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 |
# File 'lib/transcoding_machine/server/media_file_attributes.rb', line 530 def initialize(file_path) commandline = [] commandline += BINARY commandline += OPTIONS commandline += [file_path] puts "trying to run: #{commandline.join(' ')}" result = begin timeout(TIMEOUT) do Open3.popen3(*commandline) do |i, o, e| o.read end end rescue Timeout::Error => e puts "Timeout reached when inspecting #{file_path} with ExifTool" raise e end @values = Hash.new result.split(/\n/).each do |line| line.strip! if match = line.match(/([^\t]+)\t(.+)/) @values[match[1].underscore] = match[2] end end unless @values['aspect_ratio'].blank? aspect_ratio_match = @values['aspect_ratio'].match(/\d+:\d+/) aspect_ratio_match = aspect_ratio_match[0] if aspect_ratio_match case aspect_ratio_match when "16:9", "16/9" @aspect_ratio = MediaFileAttributes::ASPECT_RATIO_16_BY_9 when "4:3", "4/3" @aspect_ratio = MediaFileAttributes::ASPECT_RATIO_4_BY_3 end end unless @values['poster_time'].blank? poster_time_match = @values['poster_time'].match(/(\d+\.\d+)s/) @poster_time = poster_time_match[1].to_f if poster_time_match end unless @values['image_height'].blank? @height = @values['image_height'].to_i end unless @values['image_width'].blank? @width = @values['image_width'].to_i end end |
Instance Attribute Details
#aspect_ratio ⇒ Object
Returns the value of attribute aspect_ratio.
525 526 527 |
# File 'lib/transcoding_machine/server/media_file_attributes.rb', line 525 def aspect_ratio @aspect_ratio end |
#height ⇒ Object
Returns the value of attribute height.
525 526 527 |
# File 'lib/transcoding_machine/server/media_file_attributes.rb', line 525 def height @height end |
#poster_time ⇒ Object
Returns the value of attribute poster_time.
525 526 527 |
# File 'lib/transcoding_machine/server/media_file_attributes.rb', line 525 def poster_time @poster_time end |
#width ⇒ Object
Returns the value of attribute width.
525 526 527 |
# File 'lib/transcoding_machine/server/media_file_attributes.rb', line 525 def width @width end |