Skip to content

Instantly share code, notes, and snippets.

@botanicus
Created March 29, 2017 13:18
Show Gist options
  • Save botanicus/2f90b0e893339916bc3ae0eb93d4d09e to your computer and use it in GitHub Desktop.
Save botanicus/2f90b0e893339916bc3ae0eb93d4d09e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
Dir.chdir(File.dirname(__FILE__))
# IPod-Shuffle-4g ignores aiff files and besides, they are really, really big.
# (The originals are about 10 times bigger than the output mp3 after the conversion.)
# 57M vs. 5,2M
Dir.glob('**/*.aiff').each do |path|
command = "ffmpeg -i '#{path}' '#{path.sub('.aiff', '.mp3')}' && rm '#{path}'"
puts "~ #{command}"; system(command)
end
# The --rename-unicode option of ipod-shuffle-4g.py doesn't work.
OK_FOLDERS = ['1 Lifeflow']
Dir.glob('**/*.mp3').each do |path|
next if OK_FOLDERS.include?(File.dirname(path))
random = Array.new(8) { rand(256) }.pack('C*').unpack('H*').first
extension = path.split('.').last.downcase
new_path = [File.dirname(path), "#{random}.#{extension}"].join('/')
unless path.match(/\/[\w\d]{16}\.mp3$/)
puts "~ Renaming '#{path}' to '#{new_path}'."
File.rename(path, new_path)
end
end
options = %w{--track-gain 33 --auto-dir-playlists --verbose}
system("IPod-Shuffle-4g/ipod-shuffle-4g.py --track-voiceover --rename-unicode #{options.join(' ')} .")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment