Hallo,
ich hatte vor geraumer Zeit mal ein Problem mit Reg.Expressions, was in diesem Forum durch zwei nette Leute ausgeheblt wurde...
Hier das Resultat des ganzen (auch wenn es noch rel. unschön aussieht):
#!/usr/bin/perl
use MP3::Info; use POSIX qw(locale_h); use locale;
setlocale(LANG,'german');
##########################################
wohin sollen die Daten ?
$base = '/home2/mp3'; # ##########################################
ab wo soll gesucht werden ?
$search = '/'; # ##########################################
################ ################################################################# ################
$a = 1;
system ("find $base -iname \.mp3 > /tmp/mp3.rename"); system ("find $search -iname \.mp3 >> /tmp/mp3.rename");
open (in,"/tmp/mp3.rename"); while ($line = <in>) { $line =~ s/\n//; $mp3_info = get_mp3tag ($line,1,1); $artist = $mp3_info->{ARTIST}; $album = $mp3_info->{ALBUM}; $title = $mp3_info->{TITLE}; $track = $mp3_info->{TRACKNUM};
$known_parts = 0; if ($artist) {$known_parts++;} if ($album) {$known_parts++;} if ($title) {$known_parts++;} if ($track) {$known_parts++;} if ($known_parts) { if (not $artist) {$artist = 'unknown';} if (not $album) {$album = 'unknown';} if (not $title) {$title = 'unknown';} if (not $track) {$track = 99;} }
$artist =~ s// /g; $album =~ s// /g; $title =~ s/_/ /g;
$artist =~ s///-/g; $album =~ s///-/g; $title =~ s///-/g;
$artist =~ s/([0-9])/|$1|/g; $album =~ s/([0-9])/|$1|/g; $title =~ s/([0-9])/|$1|/g;
$artist =~ s/-/|-|/g; $album =~ s/-/|-|/g; $title =~ s/-/|-|/g;
$artist = lc($artist); $album = lc($album); $title = lc($title);
$artist =~ s/\b([a-zA-ZäöüÄÖÜß])/\u$1/g; $album =~ s/\b([a-zA-ZäöüÄÖÜß])/\u$1/g; $title =~ s/\b([a-zA-ZäöüÄÖÜß])/\u$1/g;
$artist =~ s/ //g; $album =~ s/ //g; $title =~ s/ /_/g;
$artist =~ s/|//g; $album =~ s/|//g; $title =~ s/|//g;
if (length($track) < 2) { $track = "0".$track; }
$artist =~ tr/-,.öäüßÖÄÜ&()A-Za-z_0-9//c; $album =~ tr/-,.öäüßÖÄÜ&()A-Za-z_0-9//c; $title =~ tr/-,.öäüßÖÄÜ&()A-Za-z_0-9/_/c; $track =~ tr/0-9//c;
if (length($track) != 2 or $track eq '00') { $track = ''; }
$artist =~ s//_/g; $album =~ s///g; $title =~ s/__//g;
$mp3_qual = get_mp3info ($line);
$vbr = $mp3_qual->{VBR}; $bitrate = int($mp3_qual->{BITRATE});
$minutes = $mp3_qual->{MM}; $seconds = $mp3_qual->{SS}; if (($minutes *100 + $seconds) == 0) { $track = ''; }
if (length($seconds) < 2) { $seconds = '0'.$seconds; }
if ($vbr) { $vbr = 'VBR'; $qual_fak = 2; } else { $vbr = 'CBR'; $qual_fak = 1; }
if ($artist and $album and $title and $track) {
if ( ( $length_hash{$artist.$album.$track} < ($minutes100+$seconds) ) or ( $length_hash{$artist.$album.$track} <= ($minutes100+$seconds) and $bitrate_hash{$artist.$album.$track} < ($bitrate * $qual_fak) ) ) { if ($length_hash{$artist.$album.$track} and $bitrate_hash{$artist.$album.$track}) { system ("rm "$base/$artist/$album/$track""); } $length_hash{$artist.$album.$track} = ($minutes100+$seconds); $bitrate_hash{$artist.$album.$track} = ($bitrate * $qual_fak);
if ($line !~ /$base/) { system ("mkdir -p "$base/$artist/$album""); system ("mv "$line" "$base/$artist/$album/$track_-_$title_-_[$minutes:$seconds-$vbr$bitrate].mp3""); print "$a)\t$artist\t$album\t$title \n"; $a++; } } } } close in;