Created
May 18, 2022 14:32
-
-
Save threedaymonk/7b3310f8dd67189c69cfb3d315bbd26d to your computer and use it in GitHub Desktop.
Analyse directories of films by quality
This file contains 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
Film = Struct.new(:path, :w, :h, :size) do | |
def pixels | |
w * h | |
end | |
end | |
films = [] | |
Dir['*'].each do |dir| | |
next unless File.directory?(dir) | |
Dir.chdir(dir) do | |
begin | |
size = Dir['**/*'].map { |f| File.size(f) rescue 0 }.inject(&:+) | |
biggest = Dir['**/*'].sort_by { |f| File.size(f) rescue 0 }.last | |
dimensions = `ffprobe "#{biggest}" 2>&1 | grep Video`[/\b\d{3,4}x\d{3,4}\b/] | |
next unless dimensions | |
w, h = dimensions.split(/x/).map(&:to_i) | |
films << Film.new(dir, w, h, size) | |
rescue => e | |
$stderr.puts dir | |
raise e | |
end | |
end | |
end | |
films.sort_by(&:pixels).reverse.each do |film| | |
puts format("%d\t%d\t%d\t%d\t%s", film.w, film.h, film.pixels, film.size, film.path) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment