Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Winamp random m3u

by OzzyOsbourne (Chaplain)
on Mar 08, 2002 at 15:23 UTC ( #150340=sourcecode: print w/ replies, xml ) Need Help??

Category: Audio Related Programs
Author/Contact Info OzzyOsbourne
Description: Creates a random playlist of the number of songs that you input. Edit a the $dir1 and $out vars.
# Generates a Random playlist of the length you specify...

use strict;
use File::Find;
my ($dir1, $input, @array);
&prep;
find(\&wanted, $dir1);
&outout;

#----------Sub Routines below this line---------------

sub prep {
    print "Enter the number of songs:";
    chomp ($input=<STDIN>);
    $dir1="//server/mp3share/";
}

sub wanted {
    if (/mp3$/){
        push @array, "$File::Find::name\n";
    }
    print'.';
}

sub outout{
    my $out="$dir1/upload/randlist.m3u";
    open OUT, ">$out" or die "Cannot open $out for write :$!";
    for (1..$input){
        
        my $number=int(rand $#array);
        my $result=splice @array, $number,1;
        $result=~s/\//\\/g;    
        print OUT "$result";
    }
    close $out;
}

Comment on Winamp random m3u
Download Code
Re: Winamp random m3u
by thraxil (Prior) on Mar 08, 2002 at 20:31 UTC

    first of all, i'd avoid using global variables (yeah, it's only a small script, but it should be habit).

    second, you can rewrite the:

    $result=~s/\//\\/g;

    as:

    $result =~ s{/}{\\}g;

    to eliminate LTS.

    anders pearson

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://150340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-09-15 05:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (145 votes), past polls