1

I'm trying to scan a large hard drive (think 17TBs) to find a storage estimate for video files within specific folders. In addition, I am trying to find specific unique properties of the video files. The purpose of this is to make a case for a digital asset management system that can support the video files that we have going back to 2009. I'm using mediainfo to inspect each video.

I have the file size/storage count working, but i'm having trouble adding the hashes of video properties to an array in my loop. My goal is for media info to look at the specific properties of each video, put them into a hash and add that hash to an array. Then, once I have collected all the hashes of video properties, I would call uniq! on the array so that it would show me the unique video properties.

The output of my code currently returns the video properties for the last video over and over again. I can't see what I'm doing wrong. Any advice?

require 'yaml'

#!/usr/bin/ruby

library_path = ARGV[0]

files_list = Dir.glob("#{library_path}/**/*")
total_capture_scatch_and_exports_size = 0

video_audit = Hash.new()
video_info = []
codecs = Hash.new()




files_list.each do |filepath|
filename = File.basename(filepath.to_s)
  filepath.chomp!
  puts filename
  folders_to_scan = ["/capture scratch/", "/capturescratch/", "/capture-scratch/", "/capture_scratch/", "exports", "export"]

  file_size = File.size(filepath)
  file_extension = File.extname(filepath)
  if 
    folders_to_scan.any? { |folder| filepath.downcase.include? folder }

      if 
        File.file?(filepath) && filename[0] != "." && file_extension != ".TIFF" && file_extension != ".TIF" && file_extension != ".tif" && file_extension != ".tiff" && file_extension != ".jpg" && file_extension != ".jpeg" && file_extension != ".JPG" && file_extension != ".JPEG"
            duration = %x[mediainfo --Inform="General;%Duration/String3%" '#{filepath}'].chomp!
            format = %x[mediainfo --Inform="General;%Format%" '#{filepath}'].chomp!
            commercial_name = %x[mediainfo --Inform="General;%Format_Commercial_IfAny%" '#{filepath}'].chomp!
            format_profile = %x[mediainfo --Inform="General;%Format_Profile%" '#{filepath}'].chomp!
            writing_library = %x[mediainfo --Inform="General;%Encoded_Library%" '#{filepath}'].chomp!


            video_audit[:filepath] = filepath
            video_audit[:filename] = filename   
            video_audit[:duration] = duration
            video_audit[:file_size] = file_size
            video_audit[:format] = format
            video_audit[:commercial_name] = commercial_name
            video_audit[:format_profile] = format_profile
            video_audit[:writing_library] = writing_library
            video_audit[:file_extension] = file_extension

            codecs[:filename] = filename
            codecs[:format] = format
            codecs[:commercial_name] = commercial_name
            codecs[:format_profile] = format_profile
            codecs[:writing_library] = writing_library
            codecs[:file_extension] = file_extension    
      end   

  end
  puts video_audit.to_yaml
  puts codecs
  video_info << codecs
  total_capture_scatch_and_exports_size += file_size

end
puts "THE VIDEO INFO IS=======>>>> #{video_info}"
puts "THE UNIQUE CODECS ARE: #{video_info.uniq!}"
#1000**3 is for gigabytes (this is how finder on OSX calculates storage on the Drobo Harddrives)use 1024**3 ofr gibibytes
puts "The total filesize is : #{total_capture_scatch_and_exports_size/(1000**3).to_f} GB"
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Maile Thiesen
  • 131
  • 2
  • 7

1 Answers1

0

I figured it out. I was creating new hashes outside of the loop. A new hash needed to be created for each iteration so that it could then be added to the video_info array. Then I needed to remove the bang operator when I called uniq on video_info at the end of the script. Here's my final code:

require 'json'

#developed by Maile Thiesen
#!/usr/bin/ruby

library_path = ARGV[0]

files_list = Dir.glob("#{library_path}/**/*")
total_capture_scatch_and_exports_size = 0
counter = 0

video_info = []

files_list.each do |filepath|
filename = File.basename(filepath.to_s)
  codecs = {}
  filepath.chomp!
  folders_to_scan = ["/capture scratch/", "/capturescratch/", "/capture-scratch/", "/capture_scratch/", "exports", "export"]

  file_size = File.size(filepath)
  file_extension = File.extname(filepath)
  if 
      folders_to_scan.any? { |folder| filepath.downcase.include? folder }

      if 
          File.file?(filepath) && filename[0] != "." && file_extension != ".TIFF" && file_extension != ".TIF" && file_extension != ".tif" && file_extension != ".tiff" && file_extension != ".jpg" && file_extension != ".jpeg" && file_extension != ".JPG" && file_extension != ".JPEG"
              duration = %x[mediainfo --Inform="General;%Duration/String3%" '#{filepath}'].chomp!
              format = %x[mediainfo --Inform="General;%Format%" '#{filepath}'].chomp!
              commercial_name = %x[mediainfo --Inform="General;%Format_Commercial_IfAny%" '#{filepath}'].chomp!
              format_profile = %x[mediainfo --Inform="General;%Format_Profile%" '#{filepath}'].chomp!
              writing_library = %x[mediainfo --Inform="General;%Encoded_Library%" '#{filepath}'].chomp!

              codecs[:format] = format
              codecs[:commercial_name] = commercial_name
              codecs[:format_profile] = format_profile
              codecs[:writing_library] = writing_library
            codecs[:file_extension] = file_extension    
            total_capture_scatch_and_exports_size += file_size

            counter += 1
            video_info << codecs
      end    

  end

end
puts "THE UNIQUE CODECS ARE: #{JSON.pretty_generate(video_info.uniq)}"
puts "THE TOTAL FILESIZE IS : #{total_capture_scatch_and_exports_size/(1000**3).to_f} GB"
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Maile Thiesen
  • 131
  • 2
  • 7