Created
April 20, 2015 13:31
-
-
Save mtolly/07015636107fe0d3f755 to your computer and use it in GitHub Desktop.
My script for copying and compressing music from an archive to a listening device
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
#!/usr/bin/env ruby | |
# Run from the destination root (somedevice/music/): | |
# .../music.rb audiosource/artist1/album1 audiosource/artist2/album2 ... | |
require 'fileutils' | |
ARGV.each do |dir| | |
dir = File.absolute_path(dir) | |
album = File.basename(dir) | |
artist = File.basename(File.dirname(dir)) | |
dest = "#{artist}/#{album}/" | |
FileUtils.mkdir_p dest | |
Dir.entries(dir).each do |f| | |
case File.extname(f) | |
when '.mp3', '.ogg' | |
FileUtils.cp "#{dir}/#{f}", "#{artist}/#{album}/#{f}" | |
when '.flac' | |
ogg = f.clone | |
ogg['.flac'] = '.ogg' | |
`sox "#{dir}/#{f}" -C 5.5 "#{dest}/#{ogg}" rate 44100` | |
else | |
if File.basename(f, '.*').downcase == 'cover' | |
FileUtils.cp "#{dir}/#{f}", "#{artist}/#{album}/#{f}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment