#!/usr/bin/perl # Filename: mztool # Author: David Ljung Madison # See License: http://MarginalHacks.com/License # Description: Wrapper to id3tool and vorbiscomment - but uses # the nicer interface of id3tool use strict; ################################################## # Setup the variables ################################################## my $PROGNAME = $0; $PROGNAME =~ s|.*/||; my $MP3TOOL = "id3tool"; my $OGGTOOL = "vorbiscomment"; my $EDITOR = $ENV{EDITOR} || "vi"; my $TMP = "/tmp/$PROGNAME.$$"; ################################################## # Usage ################################################## sub usage { foreach my $msg (@_) { print STDERR "\nERROR: $msg\n"; } print STDERR "Usage:\t$PROGNAME [id3tool options] \n"; print STDERR "\tEdits mp3s or oggs, using the id3tool interface:\n\n"; print STDERR < $TMP"); system("$EDITOR $TMP"); system("$OGGTOOL -w $file -c $TMP"); unlink($TMP); } elsif (!%OGGARGS) { debug("[$OGGTOOL $file]"); system("$OGGTOOL $file"); } else { # Read in current comments my %args = %OGGARGS; open(OGG,"$OGGTOOL $file|") or usage("Can't read ogginfo [$OGGTOOL $file]\n"); while() { $args{$1}=$2 if (/([^=]+)=(.+)/) && !$OGGARGS{$1}; } close OGG; # Build up comment list and do it.. my @args = qw(-w); map { push(@args,"-t","$_=$args{$_}") } keys %args; debug("[$OGGTOOL @args $file]"); my $pid = fork; exec($OGGTOOL,@args,$file) if $pid==0; die("Couldn't fork?: $!\n") unless $pid; wait; } } } else { my @mp3args; while (my $arg=shift(@argcopy)) { if ($arg =~ /^-(#|-set-track=(.+))$/) { my $tr = $2 ? $2 : shift(@argcopy); usage("Track should be a number? [$tr]\n") unless $tr =~ /^\d+$/; push(@mp3args,"-n","Track #$tr"); } else { push(@mp3args,$arg); } } debug("[$MP3TOOL @mp3args]"); exec($MP3TOOL,@mp3args); } } main();