Last active
December 8, 2015 23:53
-
-
Save raingloom/ab7a0abb71196c69e215 to your computer and use it in GitHub Desktop.
Multi-disk audio CD ripper script using VLC
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
--Rips an audio cd using VLC | |
--Tested on Arch Linux, may or may not work on other Unix systems | |
local outdir="out/Welcome-to-Night-Vale/Book" | |
local fout=outdir.."/Chapter-%04d.mp3" | |
local sessionLimit=math.huge | |
os.execute( "mkdir -vp "..outdir ) | |
local dev="/dev/cdrom" | |
local offset=0 | |
do | |
local f=io.open'offset' | |
if f then | |
offset=assert(tonumber(f:read'*a'),"Invalid saved offset") | |
end | |
print('offset',offset) | |
end | |
local sessionI=1 | |
local globalI=offset+sessionI | |
print('globalI',globalI) | |
local fcmd=[[ | |
cvlc --cdda-track %s cdda://%s ':sout=#transcode{vcodec=none,acodec=mp3,channels=2}:std{access=file,mux=raw,dst=%s}' 'vlc://quit' 2>&1]] | |
--redirect stderr to stdout, there is no other way to read io.popen's errors on the fly | |
while sessionI<=sessionLimit do | |
local out=fout:format( globalI ) | |
local cmd=fcmd:format( sessionI, dev, out ) | |
print( cmd ) | |
local vlcout=io.popen( cmd ) | |
local vlcInvalidTrack=false | |
for line in vlcout:lines() do | |
if line:match'invalid track number' then | |
vlcInvalidTrack=true | |
break | |
end | |
end | |
if vlcInvalidTrack then | |
--clean up | |
os.execute( 'rm -v '.. out) | |
break | |
end | |
sessionI, globalI = sessionI + 1, globalI + 1 | |
end | |
os.execute 'echo End of CD. Please insert the next one! | festival --tts' | |
assert(io.open('offset','w')):write(globalI-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment