Skip to content

Instantly share code, notes, and snippets.

@squarefrog
Created August 15, 2014 10:09
Show Gist options
  • Select an option

  • Save squarefrog/8bb19b0e1edfd1a48d63 to your computer and use it in GitHub Desktop.

Select an option

Save squarefrog/8bb19b0e1edfd1a48d63 to your computer and use it in GitHub Desktop.
Recursively scans the supplied director and prints filenames alongside bitrates
#!/usr/bin/ruby
# Recursively scans the supplied director and prints filenames alongside
# bitrates
# Usage:
# ./bitrate_scanner.rb path/to/folder/to/scan/recursively
# [sudo] gem install ruby-audioinfo
require "audioinfo"
def print_header(file)
dirname = File.dirname(file)
if @olddirname != dirname
separator = "=" * dirname.length
puts "\n\n\n#{separator}\n#{dirname}\n#{separator}\n\n"
@olddirname = dirname
end
end
def scan_folder(path)
Dir.glob("#{path}/**/*.{m4a,mp3}") do |file|
print_header(file)
AudioInfo.open(file) do |info|
filename = File.basename(file)
puts "#{filename} ( #{info.bitrate} kbps )"
end
end
end
@olddirname = ""
path = ARGV[0].chomp("/")
scan_folder(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment