commit 6c782693658ae47541d8635b4b80489b452244c4 parent ba5fac9cf1ca63b112973fabbdda405f26c013e9 Author: lostd <lostd@2f30.org> Date: Sat, 24 Aug 2013 13:03:08 +0300 my audio cd creation script Diffstat:
A | mkcdtoc | | | 88 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 88 insertions(+), 0 deletions(-)
diff --git a/mkcdtoc b/mkcdtoc @@ -0,0 +1,88 @@ +#!/usr/bin/env ruby + +# prepare audio files for burning to audio cd with cd-text +# creates a sequence of volume-normalized track??.wav files +# generates a cd.toc file using the original metadata + +require 'rubygems' +require 'taglib' +require 'stringex' +# also needs ffmpeg for decoding +# also needs cdrdao for burning + +if ARGV.empty? + puts 'usage: mkcdtoc file ...' + exit +end +files = ARGV + +# collect all info first +tracks = [] +files.each_with_index do |fname, i| + tracks << TagLib::FileRef.open(fname) do |f| + trk = {} + trk['source'] = fname + # audio cd supports 99 tracks max + trk['dest'] = "track%02d.wav" % (i + 1) + trk['artist'] = f.tag.artist.to_url(:force_downcase => false, + :replace_whitespace_with => ' ') + trk['title'] = f.tag.title.to_url(:force_downcase => false, + :replace_whitespace_with => ' ') + trk + end +end + +# create wave files +tracks.each do |trk| + if File.exists? trk['dest'] + puts "skipping #{trk['dest']} for it exists" + else + puts "generate #{trk['dest']} from #{trk['source']}" + ffopts = '-v quiet -vol 256 -acodec pcm_s16le -ac 2' + cmd = "ffmpeg -i #{trk['source']} #{ffopts} #{trk['dest']}" + `#{cmd}` + unless $?.exitstatus == 0 then + puts "something went wrong while running:\n#{cmd}" + exit 1 + end + end +end + +# create toc file +f = File.open('cd.toc', 'w') + +# generate toc header +f.puts <<PRE +CD_DA +CD_TEXT { + LANGUAGE_MAP { + 0 : EN + } + LANGUAGE 0 { + PERFORMER "" + TITLE "" + } +} +PRE + +# generate toc entries +tracks.each do |trk| +f.puts <<TRK + +TRACK AUDIO +CD_TEXT { + LANGUAGE 0 { + PERFORMER "#{trk['artist']}" + TITLE "#{trk['title']}" + } +} +FILE "#{trk['dest']}" 0 +TRK +end + +f.close + +puts "burn with:" +puts "cdrdao write --speed 1 --eject cd.toc\n" + +# vim:set ts=4 sw=4 et: