#!/usr/bin/env ruby args = ARGV.reverse paranoia = true f_tags = "./lst" def usage() puts " usage: #{__FILE__} [-x] [filename] -x: don't use cdparanoia filename: the file where to find the tags the tag file must be formated in order to contain a soundfile group of tags per line as this: : the accepted tags are: artist, album, year, comment and genre, plus the title number for the title infos. e.g.: artist: roger album: the musette big back 1: acordeon hardcore 2: psychimamie etc." exit end class F_tags attr_reader :infos def initialize(filename) begin f_tags = File.open(filename) rescue puts "error while opening the tag file:" puts $! exit end titles = [] artist = album = year = comment = genre = "unknown" title_count = 0 while (line = f_tags.gets) puts line.inspect # debug if not line[/^ *$/] case line[/^\w+: /] when "artist: ", "artiste: " then artist = $'.chomp when "album: " then album = $'.chomp when "year: ", "année: " then year = $'.chomp when "comment: ", "commentaire: " then comment = $'.chomp when "genre: " then genre = $'.chomp else tag, data = $&, $' if tag[/^\d+/] titles << data title_count += 1 else puts "invalid tag: #{tag}" exit end end end end f_tags.close @infos = { "artist" => artist, "album" => album, "year" => year, "comment" => comment, "genre" => genre, "count" => title_count, "titles" => titles } end end while args != [] argument = args[args.length - 1] case argument when "-x" then paranoia = false else File.exist?(argument) ? f_tags = argument : usage end args.pop end tags = F_tags.new(f_tags) %x(cdparanoia -B) if paranoia fichiers = Dir.new('.').entries.delete_if { |f| ! f[/\.wav/] } if fichiers.length != tags.infos['count'] and tags.infos['count'] != 0 puts "error: the number of extracted titles and the one get from the tagsfile do not match" exit end fichiers.each { |fichier| numero = fichier[/\d{2}/] opt_title = "" opt_title << "-t #{tags.infos['titles'][numero.to_i-1] }" if tags.infos['count'] != 0 puts %Q*%x(oggenc -q8 -N #{numero} -a "#{tags.infos['artist']}" -G "#{tags.infos['genre']}" -d "#{tags.infos['year']}" -l "#{tags.infos['album']}" -c "#{tags.infos['comment']}" "#{opt_title}" -o #{numero}.ogg #{fichier})* # debug %x(oggenc -q8 -N #{numero} -a "#{tags.infos['artist']}" -G "#{tags.infos['genre']}" -d "#{tags.infos['year']}" -l "#{tags.infos['album']}" -c "#{tags.infos['comment']}" "#{opt_title}" -o #{numero}.ogg #{fichier}) }