All pastes #166028 Raw Edit

Stuff

public ruby v1 · immutable
·published 2006-09-10 14:07 UTC
rendered paste body
#!/usr/bin/env rubyrequire 'mp3info'require 'fileutils'case ARGV[0]when 'artist', 'genre', 'comments', 'title', 'album', 'tracknum'    Type_tri = ARGV[0]else    puts "\synopsis: tri_mp3.rb type_tri [chemin]où type_ tri peut être, au choix:    artist, genre, comments, title, album, tracknumtri_mp3 permet de classer des fichiers musicaux en les placant dans un répertoire suivant un critère commun que vousaurez choisi, sur la base d'une balise mp3.  Si 'chemin' n'est pas spécifié, tri_mp3.rb sera lancé dans le répertoire courant."endchemin = ARGV[1]if chemin != nil and File.directory?( chemin )    chemin += '/' if chemin[/\/$/] == nil    repertoire = Dir.new( chemin )else    repertoire = Dir.new( './' )end    str_rep = repertoire.pathrepertoire.each { |fichier|    if File.extname( fichier ) == '.mp3'        puts "traitement de " + fichier + '...'        f_mp3 = Mp3Info.new( fichier )        balise = f_mp3.tag[ Type_tri ]        balise = f_mp3.tag2['TCON'] if Type_tri == 'genre' and balise == nil        balise = 'inconnu' if balise == nil        balise.delete!( "(" + ")" + "*" + "/" + "\\" + "\0" )        puts str_rep + balise        Dir.mkdir( "#{str_rep + balise}" ) if not File.exist?( "#{str_rep + balise}" )        FileUtils.mv( str_rep + fichier, str_rep + balise + '/' + fichier )    end}