The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl
use strict;
use LEOCHARRE::Dir ':all';
use LEOCHARRE::CLI2 ':all';
use Cwd;
use Carp;
our $VERSION = sprintf "%d.%02d", q$Revision: 1.1.1.1 $ =~ /(\d+)/g;
use File::Which 'which';
which($_) or die("missing $_?") for qw(faad lame mplayer);


my @files = grep { /\.m4a$/i } argv_files();
@files or die("No files selected.");


for my $abs_m4a (@files){
   
   my $abs_mp3 = $abs_m4a;
   $abs_mp3=~s/\.m4a$/\.mp3/i or die;
   my $abs_wav = $abs_m4a;
   $abs_wav=~s/\.m4a$/\.wav/i or die;

   # can we get artist, album, track etc info from m4a?



   system( sprintf 'mplayer -ao pcm:file=%s %s',sq($abs_wav), sq($abs_m4a) ) == 0
      or die("$?,$!");
   
   system( sprintf 'lame -h -b 192 %s %s', sq($abs_wav), sq($abs_mp3) ) == 0
      or die("$?,$!");

   unlink $abs_wav;

   print "$abs_mp3\n";

   


}


exit;

sub usage {q{m4a2mp3 [OPTION].. FILE..
Convert m4a FILE to mp3.

   -d       debug on
   -h       help
   -v       version and exit

Try 'man m4a2mp3' for more info.
}}


__END__

=pod

=head1 NAME

m4a2mp3 - Convert m4a FILES to mp3.

=head1 DESCRIPTION

We seek id3 tags artist, song, and album to copy over to the mp3 version.

=head1 USAGE

m4a2mp3 [OPTION].. FILE..

   -d       debug on
   -h       help
   -v       version and exit

=head2 EXAMPLE USAGE

For files a.m4a b.m4a and c.m4a, create a.mp3 b.mp3 c.mp3 - in same directory they are in.
   m4a2mp3 ./*m4a
   m4a2mp3 a.m4a b.m4a and c.m4a

For file a.m4a, convert it to super.mp3
   m4a2mp3 a.m4a super.mp3

=head1 AUTHOR

Leo Charre leocharre at cpan dot org

=head1 COPYRIGHT

Copyright (c) 2010 Leo Charre. All rights reserved.

=head1 LICENSE

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".

=head1 DISCLAIMER

This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the "GNU General Public License" for more details.
   
=cut