Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

total track numbers of albums based from huge mp3 list?

Status
Not open for further replies.

johfiner

Programmer
Feb 19, 2006
3
US
hey there, i'm writing a script to organize my mp3s and tag them correctly, and i like my id3v2 tags to have a track number that's formatted like this: 05/16, or 08/16, etc., the last number being the total number of tracks on that album.

right now the script traverses sub-directories of a given directory, finds the mp3s, and adds them to a large list. then it goes through the list and opens the mp3s, removes all superfluous info, and re-tags them with lowercase tags.

so as far as i can tell, the only way to accurately get the total number of tracks on each album is to open all of the mp3 files first, create a database with hashes that conatin the artist, album, and a counter for the number of mp3s that have the same artst & album name.

then, after i have that, i can open each file yet again and write the completed tag with the total number of tracks in the track # field
 
the point of my post is..

is this the most efficient way to do it, or can you guys think of another way?
 
It might be easier for us to judge efficiency if you post your code.
 
well i decided just to make a hash file with artist+album as the key and the total # of mp3s with that same artst & album name. here's that code:

Code:
	foreach $song (@fulldirfiles) {
   	$mp3 = MP3::Tag->new($song);
      ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
      if (exists $artalb{lc($artist . "." . $album)}) {
      	$artalb{lc($artist . "." . $album)} = ($artalb{lc($artist . "." . $album)} + 1);
      } else {
      	$artalb{lc($artist . "." . $album)} = 1;
      }
      $mp3->close();
   }
 
save yourself some processing time by using the lc() function once:

Code:
    foreach $song (@fulldirfiles) {
       $mp3 = MP3::Tag->new($song);
      ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
      my $key = lc("$artist.$album");  
      if (exists $artalb{$key}) {
          $artalb{$key} = ($artalb{$key} + 1);
      } else {
          $artalb{$key} = 1;
      }
      $mp3->close();
   }


and this might do what your code is doing if I understand it correctly:

Code:
    foreach $song (@fulldirfiles) {
       $mp3 = MP3::Tag->new($song);
      ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
      $artalb{lc("$artist.$album")}++;
      $mp3->close();
   }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top