mkcdtoc (1907B)
1 #!/usr/bin/env ruby 2 3 # prepare audio files for burning to audio cd with cd-text 4 # creates a sequence of volume-normalized track??.wav files 5 # generates a cd.toc file using the original metadata 6 7 require 'rubygems' 8 require 'taglib' 9 require 'stringex' 10 # also needs ffmpeg for decoding 11 # also needs cdrdao for burning 12 13 if ARGV.empty? 14 puts 'usage: mkcdtoc file ...' 15 exit 16 end 17 files = ARGV 18 19 # collect all info first 20 tracks = [] 21 files.each_with_index do |fname, i| 22 tracks << TagLib::FileRef.open(fname) do |f| 23 trk = {} 24 trk['source'] = fname 25 # audio cd supports 99 tracks max 26 trk['dest'] = "track%02d.wav" % (i + 1) 27 trk['artist'] = f.tag.artist.to_url(:force_downcase => false, 28 :replace_whitespace_with => ' ') 29 trk['title'] = f.tag.title.to_url(:force_downcase => false, 30 :replace_whitespace_with => ' ') 31 trk 32 end 33 end 34 35 # create wave files 36 tracks.each do |trk| 37 if File.exists? trk['dest'] 38 puts "skipping #{trk['dest']} for it exists" 39 else 40 puts "generate #{trk['dest']} from #{trk['source']}" 41 ffopts = '-v quiet -vol 256 -acodec pcm_s16le -ac 2' 42 cmd = "ffmpeg -i #{trk['source']} #{ffopts} #{trk['dest']}" 43 `#{cmd}` 44 unless $?.exitstatus == 0 then 45 puts "something went wrong while running:\n#{cmd}" 46 exit 1 47 end 48 end 49 end 50 51 # create toc file 52 f = File.open('cd.toc', 'w') 53 54 # generate toc header 55 f.puts <<PRE 56 CD_DA 57 CD_TEXT { 58 LANGUAGE_MAP { 59 0 : EN 60 } 61 LANGUAGE 0 { 62 PERFORMER "" 63 TITLE "" 64 } 65 } 66 PRE 67 68 # generate toc entries 69 tracks.each do |trk| 70 f.puts <<TRK 71 72 TRACK AUDIO 73 CD_TEXT { 74 LANGUAGE 0 { 75 PERFORMER "#{trk['artist']}" 76 TITLE "#{trk['title']}" 77 } 78 } 79 FILE "#{trk['dest']}" 0 80 TRK 81 end 82 83 f.close 84 85 puts "burn with:" 86 puts "cdrdao write --speed 1 --eject cd.toc\n" 87 88 # vim:set ts=4 sw=4 et: