#!/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 style, plus the track 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 tracks = [] artist = album = year = comment = style = "unknown" track_count = 0 while (line = f_tags.gets) if not line[/^ *$/] case line[/^\w+: /] when "artist: ", "artiste: " then artist = $' when "album: " then album = $' when "year: ", "année: " then year = $' when "comment: ", "commentaire: " then comment = $' when "style: " then style = $' else tag, data = $&, $' if data[/^\d{2}/] tracks << $& track_count += 1 else puts "invalid tag: #{tag}" exit end end end end f_tags.close @infos = { "artist" => artist, "album" => album, "year" => year, "comment" => comment, "style" => style, "count" => track_count, "tracks" => tracks } 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'] puts "error: the number of extracted tracks and the one get from the tagsfile do not match" exit end fichiers.each { |fichier| numero = fichier[/\d{2}/] %x(oggenc -q8 \ -N #{numero} \ -a #{tags.infos['artist']} \ -g #{tags.infos['style']} \ -d #{tags.infos['year']} \ -t #{tags.infos['tracks'][numero-1]} \ -l #{tags.infos['album']} \ -c #{tags.infos['comment']} \ #{fichier}) }