Created
March 10, 2011 10:43
-
-
Save TheLinx/863931 to your computer and use it in GitHub Desktop.
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 lua | |
require("cue") -- https://github.com/TheLinx/LuaCue/ | |
if not (arg[1] and arg[2]) then | |
print("usage: cuetoflacs.lua in.cue out-dir") | |
os.exit() | |
end | |
dir = arg[1]:match("(.+/).+") or "./" | |
if arg[3] then | |
run = print | |
else | |
run = os.execute | |
end | |
local fhand = assert(io.open(arg[1], "r")) | |
local sheet = cue.decode(fhand) | |
s = ('ffmpeg -i "%s%s"'):format(dir, sheet.filename) -- prepare our command line | |
for k, v in pairs(sheet.tracks) do | |
local sstart, send = v.indices[1], sheet.tracks[k+1] and sheet.tracks[k+1].indices[1] -- get our indices | |
print(("converting track #%02d - %s"):format(k, v.title)) -- verbosity | |
local title = v.title:lower():gsub("[^%w- ]", ""):gsub(" .", string.upper):gsub(" ", "") -- apply my fascist file naming conventions | |
title = title:sub(1,1):upper()..title:sub(2) -- it needs two steps. | |
local fname = ("%s%02d-%s.flac"):format(arg[2], k, title) -- houston, we have a file name | |
run(("%s -ss %s%s '%s' > /dev/null 2>&1"):format(s, sstart, (send and " -t "..(send - sstart) or ""), fname)) -- ffmpeg out the file. | |
run(('metaflac --set-tag="ARTIST=%s" --set-tag="TITLE=%s" --set-tag="ALBUM=%s" --set-tag="TRACKNUMBER=%d" --set-tag="TOTALTRACKS=%d" %s --remove-tag=ENCODER'):format(v.performer, v.title, sheet.title, k, #sheet.tracks, fname)) -- apply vorbis comments. | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment