timehandel has asked for the wisdom of the Perl Monks concerning the following question:
#!perl use warnings; use strict; use MP3::Tag; use File::Find; use File::Copy; use Cwd; my $cwd = getcwd; # Arbeitsverzeichnis + my $mp3dir = $cwd; # Default print "Pfad angeben wo die MP3's sind!!! [keine Eingabe - Aktuelles Ve +rzeichnis]\n"; while (my $input = <STDIN>) { last if $input !~ /\S/; # leere Eingabe chomp($input); if (-d $input) { # Verzeichnis existiert? $mp3dir = $input; last; } print "Verzeichnis '$input' existiert nicht. Nochmal versuchen.\n" +; } find(\&wanted, $mp3dir); # Achtung: Rekursive Suche sub wanted { return unless /\.mp3$/i; # alles was keine *.mp3 Endung + hat wird # nicht beachtet my $filename = $_; my $fullpath = $File::Find::name; return if (-d $fullpath); # Verzeichnisse mit '.mp3' weg +lassen if ($mp3 = MP3::Tag->new($fullpath)) { print "$_ (Tags: ", join(", ",$mp3->get_tags),")\n"; my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo(); print "* Song: $title\n" . "* Track: $track\n" . "* Artist: $artist\n" . "* Album: $album\n" . "* Comment: $comment\n"; my $targetdir = make_dirname_from_tags($artist, $album); if (! $targetdir) { print "Fehler beim Erzeugen des Ordnernamens!\n"; return; } if (! -d $targetdir) { # existiert noch nicht? if (! mkdir("$cwd/$targetdir")) { warn "Kann Ordner '$cwd/$targetdir' nicht anlegen: $!" +; return; } } move($fullpath, "$cwd/$targetdir/$filename"); or die "Could not move '$filename' zu '$cwd/$targetdir/':$!"; } } sub make_dirname_from_tags { # Hier diejenigen Zeichen in den Tags ersetzen, die für Ordner-/Datein +amen # verboten sind. my @tags = @_; return if ! @tags; for my $tag (@tags) { $tag =~ s/[:,]/_/g; # Zeichenklasse noch anpassen } return(join ' - ', @tags); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: mp3 id3
by ww (Archbishop) on Jun 11, 2012 at 13:32 UTC | |
by timehandel (Initiate) on Jun 11, 2012 at 13:45 UTC | |
by ww (Archbishop) on Jun 11, 2012 at 13:53 UTC | |
by timehandel (Initiate) on Jun 11, 2012 at 14:47 UTC | |
by ww (Archbishop) on Jun 11, 2012 at 16:04 UTC | |
| |
|
Re: mp3 id3
by phenom (Chaplain) on Jun 11, 2012 at 12:44 UTC | |
by timehandel (Initiate) on Jun 11, 2012 at 12:52 UTC | |
|
Re: mp3 id3
by tinita (Parson) on Jun 11, 2012 at 13:21 UTC |