Last active
October 14, 2016 14:56
-
-
Save milothiesen/f462b88ce6fe7ac7e61681eabba3cb78 to your computer and use it in GitHub Desktop.
Find all unique video codecs in specific directories - requires mediainfo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#developed by Maile Thiesen | |
#!/usr/bin/ruby | |
require 'json' | |
require 'time' | |
require 'nokogiri' | |
library_path = ARGV[0] | |
files_list = Dir.glob("#{library_path}/**/*") | |
total_capture_scatch_and_exports_size = 0 | |
counter = 0 | |
duration_of_all_videos = 0 | |
video_info = [] | |
files_list.each do |filepath| | |
filename = File.basename(filepath.to_s) | |
codecs = {} | |
video_duration = {} | |
filepath.chomp! | |
folders_to_scan = ["/capture scratch/", "/capturescratch/", "/capture-scratch/", "/capture_scratch/", "exports", "export"] | |
file_extensions_to_exclude = [".TIFF", ".TIF", ".tif", ".tiff", ".jpg", ".jpeg", ".JPG", ".JPEG", ".CR2", ".pek", ".PRV", ".caf", ".prproj", ".fcp", ".FCP", ".THM", ".XML", ".BMP"] | |
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_extensions_to_exclude.any? {|extension| filepath.include? extension} | |
# puts filepath | |
xml_mediainfo_output = %x[mediainfo --Output=XML '#{filepath}'] | |
doc = Nokogiri::XML(xml_mediainfo_output) | |
duration = %x[mediainfo --Inform="General;%Duration%" '#{filepath}'].to_i | |
general_format = doc.xpath('//File/track[@type="General"]/Format/text()') | |
video_format = doc.xpath('//File/track[@type="Video"]/Format/text()') | |
general_commercial_name = doc.xpath('//File/track[@type="General"]/Commercial_name/text()') | |
general_format_profile = doc.xpath('//File/track[@type="General"]/Format_profile/text()') | |
general_writing_library = doc.xpath('//File/track[@type="General"]/Writing_library/text()') | |
codecs[:general_format] = general_format | |
codecs[:video_format] = video_format | |
codecs[:general_commercial_name] = general_commercial_name | |
codecs[:general_format_profile] = general_format_profile | |
codecs[:general_writing_library] = general_writing_library | |
codecs[:file_extension] = file_extension | |
video_duration[:duration] = duration | |
total_capture_scatch_and_exports_size += file_size | |
counter += 1 | |
puts "You are on file number #{counter}" | |
video_info << codecs | |
puts "the duration of the video is #{duration}" | |
duration_of_all_videos = duration_of_all_videos + duration | |
puts "the duration of videos counted so far is: #{duration_of_all_videos}" | |
end | |
end | |
end | |
puts "the total duation in milliseconds is: #{duration_of_all_videos}" | |
t = duration_of_all_videos/1000 | |
mm, ss = t.divmod(60) | |
hh, mm = mm.divmod(60) | |
dd, hh = hh.divmod(24) | |
puts "%d days, %d hours, %d minutes and %d seconds" % [dd, hh, mm, ss] | |
unique_codecs = video_info.uniq | |
puts "THE UNIQUE CODECS ARE: #{JSON.pretty_generate(unique_codecs)}" | |
puts "THE TOTAL FILESIZE IS : #{total_capture_scatch_and_exports_size/(1000**3).to_f} GB" | |
open('find_unique_codecs_vs5_output.txt', 'w') do |f| | |
f << "the total duation in milliseconds is: #{duration_of_all_videos}" | |
f << "%d days, %d hours, %d minutes and %d seconds" % [dd, hh, mm, ss] | |
f << "THE UNIQUE CODECS ARE: #{JSON.pretty_generate(video_info.uniq)}" | |
f << "THE TOTAL FILESIZE IS : #{total_capture_scatch_and_exports_size/(1000**3).to_f} GB" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 But you should add a flag that would then save it to a file :)
&& ! [".tiff", ".tif",".jpg",".jpeg"].include? file_extension.downcase