Category: | Audio Related Programs |
Author/Contact Info | xunker <xunker@pyxidis.org> |
Description: | Short Desciption: Produces an .M3U style playlist from a specified path More Detail: There have been a few other playlist makers posted, but I've given this one the moniker "better" because it's generates useful WinAMP-style .M3U playlists, not just a list of .mp3 files. It finds all MP3 files below a given path, and stores both the file path and the ID3 info (if availble; if not, it uses the filename) in the output M3U file. To-do's:
This was written for my in-car MP3 player/computer, so when I download new music to it, one double-click will refresh/rebuilt/sort the default playlist, adding the new music just downloaded. Before I did this I had to open the direcotry in WinAMP, sort it and save it. That's a pain with a screen that's a mere 2.2 inches diagonal. It's not too optimized, but it can still process an archive of 1,300 files in about 1 minute (Pentium 133, 32 Meg, Win2k Pro). Requires MP3::Info to be installed. |
#!c:\perl\bin\perl.exe -w
#
# WinAMP M3U Sorted Playlist Generator version .0.1 ("Bob") December 2
+001
# <xunker@pyxidis.org>
#
use strict;
use File::Find;
use MP3::Info;
my $Debug = 0;
my $usage = "listmaker.pl <source dir> <output file> [<verbose>]\n";
my ($source_path, $output_filename, $verbose) = @ARGV;
die $usage unless (($source_path) && ($output_filename));
die "that path doesn't exist, hombre" unless (-e $source_path);
unlink $output_filename if (-e $output_filename);
my @files; my %shortname;
sub addFile {
$shortname{$File::Find::name} = $_;
return unless -f;
return unless /\.mp3$/;
push @files, $File::Find::name;
print '.' if $verbose;
}
print "\n" if $verbose;
find (\&addFile, $source_path);
@files = sort {uc($a) cmp uc($b)} @files;
open FILE, ">$output_filename"
or die "could not open $output_filename for writing: $!";
print FILE "#EXTM3U\n";
my $counter = 1; my $max = scalar (@files);
foreach my $file (@files) {
my $tag = get_mp3tag($file);
my $info = get_mp3info($file);
my $pair;
if (($tag->{ARTIST}) && ($tag->{TITLE})) {
$pair = $tag->{ARTIST} . ' - ' . $tag->{TITLE};
} else {
$pair = $shortname{$file};
}
print FILE "#EXTINF:"
. int ($info->{SECS})
. ","
. $pair
. "\n";
$file =~ s/\//\\/g; # this is for WinAMP/MS-DOS;
# by default, File::Find returns
# filenames with the forward
# (proper) slash, but I use the
# program in Windows, so...
# If you use a real OS, remove.
print FILE "$file\n";
print "$counter of $max: $pair\n" if $verbose;
$counter++;
}
close FILE;
|
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: M3U Playlist Generator
by PodMaster (Abbot) on Aug 18, 2003 at 06:59 UTC | |
Re: M3U Playlist Generator
by Soul Singin' (Initiate) on Jul 01, 2012 at 20:31 UTC | |
by Anonymous Monk on Jul 01, 2012 at 21:28 UTC | |
by Soul Singin' (Initiate) on Jul 02, 2012 at 05:12 UTC |