Skip to content

Instantly share code, notes, and snippets.

@threedaymonk
Created May 18, 2022 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save threedaymonk/7b3310f8dd67189c69cfb3d315bbd26d to your computer and use it in GitHub Desktop.
Save threedaymonk/7b3310f8dd67189c69cfb3d315bbd26d to your computer and use it in GitHub Desktop.
Analyse directories of films by quality
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