Monday, November 6, 2006

Perl script to autogenerate playlists from mp3s

I wrote this perl script to autogenerate playlist files (.m3u) for each CD we have. Some servers don't play the songs in CD order, but they will with a playlist.

# assumes mp3 directory structure of g:/mp3/artist/album/tracks.mp3
# generates playlist of format: g:/m3u/artist-album.m3u


opendir(ARTIST, $mp3dir);
@dir = grep !/^\.\.?$/, readdir ARTIST;
foreach $artist (@dir) {
print "\nartist: $artist\n";
@album = grep !/^\.\.?$/, readdir ALBUM;

foreach $album (@album) {
print " album: $album\n";

@track=grep /\.mp3/,readdir TRACK;
foreach $track (@track) {
print " track: $track\n";
closedir TRACK;

# create playlist
$m3u_name=~s/\\ /_/g;
print " m3u: $m3u_name\n\n";
print A $playlist;
closedir ALBUM;

No comments:

Post a Comment