2016-10-05 6 views
1

私は大容量のハードディスクドライブ(17 TBと思う)をスキャンして、特定のフォルダ内のビデオファイルのストレージ見積もりを見つけようとしています。また、私はビデオファイルの特定の固有のプロパティを見つけることを試みています。これは、私たちが2009年に行ったビデオファイルをサポートできるデジタル資産管理システムのケースを作ることです。mediainfoを使用して各ビデオを検査しています。Ruby mediainfo固有のプロパティを見つける

ファイルサイズ/ストレージ数が問題ありませんが、ループの配列にビデオプロパティのハッシュを追加できません。私の目標は、メディア情報が各ビデオの特定のプロパティを見てハッシュに入れ、そのハッシュを配列に追加することです。それでは、ビデオプロパティのすべてのハッシュを収集したら、uniqを呼び出します。私はユニークなビデオのプロパティを表示するように配列上に。

私のコードの出力は、最後のビデオのビデオプロパティを何度も何度も何度も返します。私は何が間違っているのか分かりません。何かアドバイス?

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" 

答えて

0

私はそれを理解しました。私はループの外で新しいハッシュを作成していました。 video_info配列に追加できるように、各イテレーションごとに新しいハッシュを作成する必要がありました。次に、スクリプトの最後にvideo_infoでuniqを呼び出したときに、bang演算子を削除する必要がありました。最終的なコードは次のとおりです。

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" 
関連する問題