#!/usr/bin/perl # # 2001.01.29 # new stuff... it will REMOVE that fuckin' id3v2 from file if exists # with the wonderful help of MP3::Tag :)~ # # altblue 1999-2001 use strict; use MP3::Info qw(:all); use File::Find; use MP3::Tag; use Term::ANSIColor qw(:constants); ##### Filemask my $filemask ='mp3'; my $comment = "AltBlue's MP3z"; my $genre = 'alternative'; my $various = 'various|soundtrack|misc|\d\d-.*'; ################################## my $directory = $ARGV[0] ? $ARGV[0] : '.'; $|=1; File::Find::finddepth({ wanted => \&process_file, no_chdir => 1, preprocess => sub { return sort @_ }, }, $directory); sub process_file { return unless /\.$filemask$/i; print BOLD CYAN $File::Find::name, RESET '('; my $fsize = -s $File::Find::name; print YELLOW commify($fsize), RESET 'bytes, '; my $Tinfo = get_mp3info($File::Find::name); print YELLOW "$Tinfo->{TIME}", RESET; print 'at ', YELLOW $Tinfo->{BITRATE}, RESET 'kbps/'; print YELLOW $Tinfo->{FREQUENCY}, RESET 'Hz '; if ($Tinfo->{STEREO}) { print YELLOW "stereo", RESET; } else { print MAGENTA "mono", RESET; } print ', layer', YELLOW $Tinfo->{LAYER}, RESET '...'; print BOLD YELLOW "removed ID3v2 tag", RESET if removed_id3v2_tag($File::Find::name); my ($artist,$album,$title) = ('unknown','unknown','unknown'); my $track = 0; my $year = (localtime($^T))[5] + 1900; $File::Find::name =~ m#.*(^|/)(.+?)/(.*?)\.$filemask$#; my ($dir, $file) = ($2, $3); if ($dir eq '.') { $dir = $ENV{'PWD'}; $dir =~ s#^.*/## ; } my $deepscan = 0; if ($dir =~ /^(.*?) - (.*)$/) { ($artist, $album) = ($1,$2); if ($album =~ /^(\d{4})\.(.*)$/) { ($year, $album) = ($1,$2); } $deepscan = 1 if $artist =~ /^$various$/ ; } else { $deepscan = 1; $artist = $dir unless $dir =~ /^$various$/; } if($file =~ /^([\d,+-]+)\.(.*)/) { ($title,$track) = ($2,$1) } else { $title = $file } if ($deepscan && $title =~ /^(.*?) - (.*)$/) { ($artist,$title) = ($1,$2); } $artist = uc $artist; $artist =~ tr/[ãâîþº]/[ÃÂÎÞª]/; $title = lc $title; $title =~ tr/[ÃÂÎÞª]/[ãâîþº]/; $album = lc $album; $album =~ tr/[ÃÂÎÞª]/[ãâîþº]/; # if multiple tracks in the same file... $track =~ s/^(\d+)\D.+$/$1/; set_mp3tag ($File::Find::name, $title, $artist, $album, $year, $comment, $genre, $track) and print BOLD GREEN "OK", RESET $/ or print BOLD RED "FAILED", RESET $/; } sub commify { $_ = reverse "@_"; s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; $_ = scalar reverse; } sub removed_id3v2_tag { my $mp3 = MP3::Tag->new(shift) or return undef; $mp3->getTags(); if (exists $mp3->{ID3v2}) { show_id3v2($mp3->{ID3v2}); $mp3->{ID3v2}->remove_tag(); return 1; } return undef; } sub show_id3v2 { print BOLD YELLOW 'Stripping ID3v2 TAG!', RESET $/; my $id3v2 = shift; my $frameIDs_hash = $id3v2->get_frame_ids; foreach my $frame (keys %$frameIDs_hash) { my ($info, $name) = $id3v2->get_frame($frame); if (ref $info) { print "\t$name ($frame):\n"; while(my ($key,$val)=each %$info) { print "\t\t* $key =>", YELLOW $val, RESET $/; } } else { print "\t$name ($frame):", YELLOW $info, RESET $/; } } }