lameid3.pl 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #
  2. # From: Per Bolmstedt <tomten@kol14.com>
  3. #
  4. # AC> If someone has scripts that read input ID3 tags and convert
  5. # AC> them to args for lame (which then encodes the tags into the
  6. # AC> output files), let me know, too!
  7. #
  8. # This is easy peasy using Perl. Especially using Chris Nandor's excellent
  9. # MP3::Info package (available on CPAN). Here's a program I just wrote that
  10. # I think does what you want. Invoke it with "<program> <file> [options]"
  11. # (where the options can include an output filename), like for example:
  12. #
  13. # lameid3.pl HQ.mp3 LQ.mp3 -fv
  14. #
  15. # (Note how the syntax differs from that of Lame's.) The program will
  16. # extract ID3 tags from the input file and invoke Lame with arguments for
  17. # including them. (This program has not undergone any real testing..)
  18. use MP3::Info;
  19. use strict;
  20. my %flds = (
  21. TITLE => 'tt',
  22. ARTIST => 'ta',
  23. ALBUM => 'tl',
  24. YEAR => 'ty',
  25. COMMENT => 'tc',
  26. GENRE => 'tg',
  27. TRACKNUM => 'tn'
  28. );
  29. my $f = shift @ARGV;
  30. my $s = "lame ${f} " . &makeid3args( $f ) . join ' ', @ARGV;
  31. print STDERR "[${s}]\n";
  32. system( $s );
  33. sub makeid3args( $ )
  34. {
  35. my $s;
  36. if ( my $tag = get_mp3tag( @_->[ 0 ] ) )
  37. {
  38. for ( keys %flds )
  39. {
  40. if ( $tag->{ $_ } )
  41. {
  42. $s .= sprintf(
  43. "--%s \"%s\" ",
  44. %flds->{ $_ },
  45. $tag->{ $_ } );
  46. }
  47. }
  48. }
  49. return $s || "";
  50. }