Main Page/Stuff/Ripping Karaoke CDs/write mp3 songlist.pl

From phurvitz
Jump to: navigation, search

<source lang=perl>

  1. ! /usr/bin/perl

use MP3::Tag;

  1. list all files

chdir "c:/program files/karafun/songs"; @mp3files = `ls *.mp3`;

  1. print @mp3files;
  1. a list of titles & artists

@titleartists = (); @artisttitles = ();

for $f (@mp3files) {

  chomp $f;
  $mp3 = MP3::Tag->new($f);
  ($title, $artist, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
  $artisttitle = "$artist\t$title\t$album";
  push (@artisttitles, $artisttitle);
  $titleartist = "$title\t$artist\t$album";
  push (@titleartists, $titleartist);

}

open (LIST, ">c:/program files/karafun/songs/songlist.txt"); @sorted = sort { lc($a) cmp lc($b) } @titleartists; print LIST "Title\tArtist\tAlbum\n"; print LIST "=====================\n"; for $t (@sorted) {

  print LIST "$t\n";

}

print LIST "\n\n\n\n";

@sorted = sort { lc($a) cmp lc($b) } @artisttitles; print LIST "Artist\tTitle\tAlbum\n"; print LIST "=====================\n"; for $t (@sorted) {

  print LIST "$t\n";

}

close LIST; </source>