All pastes #157491 Raw Edit

Someone

public ruby v1 · immutable
·published 2006-09-01 16:28 UTC
rendered paste body
#!/usr/bin/env rubyargs = ARGV.reverseparanoia = truef_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:            <tag>: <data>        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."    exitendclass 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        }    endendwhile args != []    argument = args[args.length - 1]    case argument        when "-x" then paranoia = false        else File.exist?(argument) ? f_tags = argument : usage    end    args.popendtags = F_tags.new(f_tags)%x(cdparanoia -B) if paranoiafichiers = 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"    exitendfichiers.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})}