Bo hit me with the 25 random songs meme. Who wants to push buttons when you can write a program?
#! /usr/bin/perl
use warnings;
use strict;
use File::Find;
use constant CHOOSE_N => 25;
@ARGV = "." unless @ARGV;
my @mp3;
my $matches = sub {
push @mp3 => $File::Find::name
if /\.mp3$/i;
};
find $matches => @ARGV;
# Fisher-Yates-Knuth
for (my $n = $#mp3; $n >= 1; $n--) {
my $k = int rand($n+1);
@mp3[$k,$n] = @mp3[$n,$k];
}
for (1 .. CHOOSE_N) {
last unless @mp3;
my $song = shift @mp3;
# e.g., .../Music/Bob Marley/Kaya/08 - Crisis.mp3
if ($song =~ m!^.*/([^/]+)/[^/]+/\d+\s+-\s+(.+)\.!) {
my($artist,$title) = ($1,$2);
print qq{$_. "$title," $artist\n};
}
}
The output:
- "The End," The Doors
- "Misty Morning," Bob Marley
- "My Mood Swings," Elvis Costello
- "Concerto Emperor: II. Adagio un poco moto," Ludwig van Beethoven
- "What's the Matter Here?," 10,000 Maniacs
- "Trench Town Rock," Bob Marley
- "Final Hour," Lauryn Hill
- "These Are Days," 10,000 Maniacs
- "Want-Ad Blues," John Lee Hooker
- "Loser," Beck
- "Sonata Pathétique: II. Adagio cantabile" Ludwig van Beethoven
- "Peer Gynt Suite No. 2: Ingrid's Lament," Edvard Grieg
- "4 Better or 4 Worse (interlude)," The Pharcyde
- "Bonita Applebum," A Tribe Called Quest
- "Hard Hearted Woman," John Lee Hooker
- "Jeremy," Pearl Jam
- "Toccata and Fugue in D minor," Johann Sebastian Bach
- "Ya Mama," The Pharcyde
- "Pennyroyal Tea," Nirvana
- "Concerto in C minor for Violin and Oboe," Johann Sebastian Bach
- "Sex Type Thing," Stone Temple Pilots
- "Drive," R.E.M.
- "People Are Strange," The Doors
- "Vivrant Thing - Violator (feat. Q-Tip)," A Tribe Called Quest
- "The New Pollution," Beck
No comments:
Post a Comment