#!/usr/bin/perl use strict; use vars qw($VERSION @FILES); use Getopt::Std::Strict 'dhvb:'; use LEOCHARRE::DEBUG; use Cwd; use Carp; $VERSION = sprintf "%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)/g; init(); do_one($_) for @FILES; exit; # - - # sub do_one { my $abs = shift; my $bitrate = $opt_b; my $abs_tmp = "$abs.tmp.mp3"; # any tags my($artist,$album,$song); my $out = `id3info "$abs"`; $? and die("error id3info $abs , $?"); if( $out=~/TPE1.+\:(.+)\n/ ){ $artist = $1; $artist=~s/^\s+|\s+$//g; } if ($out=~/TALB.+\:(.+)\n/ ){ $album = $1; $album=~s/^\s+|\s+$//g; } if ($out=~/TIT2.+\:(.+)\n/ ){ $song = $1; $song=~s/^\s+|\s+$//g; } debug("artist $artist, album $album, song $song"); system( 'lame' ,'-b', $bitrate, $abs, $abs_tmp ) == 0 or die($?); if($artist){ system( 'id3tag','--artist',$artist, $abs_tmp) ==0 or die($?) } if($album){ system( 'id3tag','--album',$album, $abs_tmp) ==0 or die($?) } if($song){ system( 'id3tag','--song',$song, $abs_tmp) ==0 or die($?) } system('mv',$abs_tmp,$abs) ==0 or die($?); debug("$abs done."); } exit; sub usage { qq{$0 - reduce mp3 size keeping basic id3 tags DESCRIPTION I had some mp3s in a package that needed to be smaller for portability. I wanted to keep the tags though, the basic artist, album, and song tags- if present. Lame did not do this by default. So.. here. OPTIONS -d debug on -h help -v version and exit -b number bitrate, 18 default AUTHOR Leo Charre leocharre at cpan dot org SEE ALSO }} sub init { $::DEBUG = 1 if $opt_d; $opt_h and print usage() and exit; $opt_v and print $VERSION and exit; for (grep { /\.mp3$/i } @ARGV){ my $abs = Cwd::abs_path($_) or die("cant resolve $_"); -f $abs or die("not file $abs"); push @FILES, $abs; } scalar @FILES or die("no files"); $opt_b ||= 18; }