When listening to my MP3 collection I like some variety so I have winamp/mpg123 set onto random play.
Sometimes I would like the music to complement my mood so I set about writing a quick program to create a playlist for each genre:
#! /usr/bin/perl # mp3genre.pl - Program to generate playlist files by genre use File::Find; use MP3::Info; use MP3::Info qw(:genres); use strict; use_winamp_genres(); my %songsdb; my $searchdir=$ARGV[0] or die "Enter the starting directory as a param +eter"; print "Scanning $searchdir and subdirectories for mp3s\n"; find (\&readtag,$searchdir); mkdir "genres" if !-e "genres"; foreach my $genre (keys %songsdb){ my $genreclean=$genre; $genreclean =~ s#(/|\\)#-#g; print "writing $genreclean.m3u\n"; open OUTFILE,">genres/$genreclean.m3u" or die " can't open $genre. +m3u for output"; print OUTFILE join("\n",@{$songsdb{$genre}}); close OUTFILE; } print "\nAll done, give me a cookie.\n"; sub readtag{ my $file=$File::Find::name; if ($file =~ m/\.mp3$/){ my $tag = get_mp3tag($file); push @{$songsdb{$tag->{GENRE}||"none"}},$file; } };

Usage is
mp3genre.pl directory
The program will search the given directory (and all subdirectories), create a "genres" folder and save a playlist for each genre in it with the filename "genre.m3u".

Any comments/criticism on the coding are welcome - thanks.

Replies are listed 'Best First'.
Re: Play MP3s to match your mood.
by nimdokk (Vicar) on Jan 21, 2004 at 13:33 UTC
    This looks a lot like something I've been thinking about writing, except mine would be making playlists for a Shoutcast server. Will have to play around with this.


    "Ex Libris un Peut de Tout"
Re: Play MP3s to match your mood.
by mjamesruggiero (Acolyte) on Feb 07, 2004 at 01:22 UTC
    Very cool. I'll give it a try.