Subject: Playlist randomization script

From: "Nadav Har'El" <[email-masked]>
Date: Sun, 5 Nov 2000 10:34:58 +0200

If anyone is interested in my simple playlist randomization script (the
one that I've mentioned in previous postings), here it is:

#!/bin/sh
# finds all mp3 files in /home/mp3, sorts these in a random order into a
# temporary file, and then calls 'xmms' to play the files in this order.

TMPFILE=/tmp/playlist`id -u`.m3u

find /home/mp3 -follow -type f -name "*.mp3" | awk '
BEGIN {
        srand();
        nl=0;
}
{
        line[nl++]=$0
}
END {
        while(nl){
                i=int(rand()*nl)
                print line[i]
                line[i]=line[nl-1]
                nl--
        }
}
' >$TMPFILE

exec xmms $TMPFILE

-- 
Nadav Har'El                        |       Sunday, Nov 5 2000, 7 Heshvan 5761
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |This message contains 100% recycled
http://nadav.harel.org.il           |characters.

---

From: Shlomi Fish <[email-masked]>
Date: Sun, 5 Nov 2000 15:24:51 +0200 (IST)

Interesting, but xmms has a shuffle option, which you can turn on.
So you can keep the list ordered, and update it only when a new file is
added or an existing file removed.

Regards,

	Shlomi Fish

On Sun, 5 Nov 2000, Nadav Har'El wrote:

> To unsubscribe from this group, send an email to:
> [email-masked]
> 
> 
> 
> 

----------------------------------------------------------------------
Shlomi Fish        [email-masked] 
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

The prefix "God Said" has the extraordinary logical property of 
converting any statement that follows it into a true one.

---

From: "Nadav Har'El" <[email-masked]>
Date: Sun, 5 Nov 2000 19:20:54 +0200

> added or an existing file removed.

Go stand in the corner! You weren't paying attention! ;)

We were talking about what happens when you have, say, 100 hours of music
in mp3 format, and every day (for example) you start a new xmms process.
Then xmms's shuffle will choose a new shuffled order every time you run it,
and you have a high chance of hearing a few songs today that you've heard
just yesterday. Instead you want to choose a random order for the next 10
days (for example) and assure that you hear different songs on each day. This
is what my script does: it randomizes the list's order, and then you play
it without the shuffle option, and when you quit xmms and start it again
later it will continue in the same song you left off, but more importantly
will continue the same randomized sequence it was playing.

And no, Chen, this wasn't an awk excercise :) I'm way beyond needing more
awk excercise :)

-- 
Nadav Har'El                        |       Sunday, Nov 5 2000, 8 Heshvan 5761
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Why do doctors call what they do
http://nadav.harel.org.il           |practice? Think about it.