Skip to content

Instantly share code, notes, and snippets.

@hakunin
Created August 23, 2010 08:08
Show Gist options
  • Save hakunin/545045 to your computer and use it in GitHub Desktop.
Save hakunin/545045 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
AUDIO_EXTENSIONS =
Hash[*
"flac ogg mp3 wav ape".
split.
map { |f| ['.'+f,true] }.
flatten
]
search = ARGV.join('\ ')
songs = `locate #{search}`.split("\n")
albums = {}
songs.each { |s|
if AUDIO_EXTENSIONS[File.extname(s)]
d = File.dirname(s)
albums[d] ||= 0
albums[d] += 1
end
}
albums.reject! { |a, songs| songs < 3 }
albums = albums.keys
path = albums[(rand*albums.length).floor].
gsub(/ /, "\\ ").
gsub(/\(/, "\\(").
gsub(/\)/, "\\)").
gsub(/\[/, "\\[").
gsub(/\]/, "\\]")
exec "mplayer #{path}/*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment