Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

MP3 Playlist generator

by Viking (Beadle)
on Jul 06, 2000 at 06:25 UTC ( #21269=sourcecode: print w/replies, xml ) Need Help??
Category: Audio Related Programs
Author/Contact Info Viking / viking@linuxfreak.com
Description: This generates MP3 playlists from a given directory. It handles sub directories too. Useful for mpg123 or xmms.
#!/usr/bin/perl -w

# mp3playlist.pl by Viking

use strict;

if ($ARGV[0]) {
        &parsedir($ARGV[0]);
} else {
        print "mp3playlist.pl by Viking\n";
        print "usage: mp3playlist.pl <dir>\n";
}

sub parsedir {

        # get current directory
        my $currentdir = $_[0];

        # create dir listing
        opendir DIR, $currentdir;
        my @dirlist = readdir DIR;
        close DIR;

        # loop thru dir listing
        for (@dirlist) {

                # ignore "." and ".."
                if (!(/^\.{1,2}$/)) {

                        # get file mode
                        my $mode = (stat "$currentdir/$_")[2];

                        # if directory recurse routine with new direct
+ory
                        if ($mode =~ /^1/) {
                                &parsedir("$currentdir/$_");
                        # if mp3 file print path and name
                        } elsif (/\.mp3$/) {
                                print "$currentdir/$_\n";
                        }
                }
        }
}
Replies are listed 'Best First'.
RE: MP3 Playlist generator
by davorg (Chancellor) on Jul 06, 2000 at 12:19 UTC

    This seems to be becoming a recurrent theme around these parts - but recursive file search stuff like this is a lot easier with File::Find. You'd do it something like this (untested code):

    use strict; use File::Find; if ($ARGV[0]) { find(\&wanted, $ARGV[0]); } else { print "mp3playlist.pl by Viking (& davorg)\n"; print "usage: mp3playlist.pl <dir>\n"; } sub wanted { return unless -f; return unless /\.mp3$/; print "$File::Find::name\n"; }
    --
    <http://www.dave.org.uk>

    European Perl Conference - Sept 22/24 2000, ICA, London
    <http://www.yapc.org/Europe/>
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://21269]
help
Chatterbox?
[Discipulus]: see Re: from txt file to array erix
[erix]: yeah, I ask for the text (I don't see signatures)
[Discipulus]: dear brother karl has "Furthermore I consider that Donald Trump must be impeached as soon as possible" in his sig
[erix]: ah, thanks Discipulus
[1nickt]: erix perhaps you could kindly point out your technique to roho and everyone will be happy.
[Discipulus]: but i'm also animalist, so i' hirted by 1nickt's sig: The way forward always starts with a mammal test... grin..
[erix]: I might if I did remember. It's probably somewhere in the site docs
[uhClem]: I don't favor that sort of thing around here but the place for our politics is wherever we live.
[uhClem]: And besides, the objection to it was off-topic.
[Discipulus]: 1nickt hide signature is a positive action; i think is not a solution here

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2017-06-22 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (519 votes). Check out past polls.