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.

In reply to Play MP3s to match your mood. by OhReally

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.