Skip to content

Instantly share code, notes, and snippets.

@jvmvik
Created January 20, 2019 02:04
Show Gist options
  • Save jvmvik/67ae3da955c4204e16551ceda1ab1c9d to your computer and use it in GitHub Desktop.
Save jvmvik/67ae3da955c4204e16551ceda1ab1c9d to your computer and use it in GitHub Desktop.
Rip Audio CD on Linux / Debian / Ubuntu in command line
#!/usr/bin/env ruby
#
# Convert CD to mp3 on Linux
#
# reference: https://www.cyberciti.biz/faq/linux-ripping-and-encoding-audio-files/
#
# Run extraction with
# cdparanoia -B
#
# Convert wav to mp3 with lame
#
# Dependency
# - lame
# - cdparanoia
#
# How to run ?
#
# Run this script where you want to extract the CD audio.
wav_files = Dir.glob('*.wav')
if wav_files.size == 0
puts "no wave file found"
puts "extract cd audio to wave files"
puts `cdparanoia -B`
wav_files = Dir.glob('*.wav')
if wav_files.size == 0
puts "oops no wav files extracted!"
exit 1
end
end
wav_files.each do |path|
mp3_path = path.gsub(/\.wav$/, '.mp3')
mp3_final_path = mp3_path.gsub('.cdda', '')
if File.exist?(mp3_final_path)
puts "skip #{path}"
next
end
print "> #{path}..."
`lame #{path}`
`mv #{mp3_path} #{mp3_final_path}`
puts "done"
end
puts "all files extracted"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment