Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Dec 2010 15:07:05 -0500
From:      Chris Brennan <xaero@xaerolimit.net>
To:        bf1783@gmail.com
Cc:        Frank Shute <frank@shute.org.uk>, freebsd-questions@freebsd.org
Subject:   Re: randomising tracks: scripting question
Message-ID:  <AANLkTimScqpifh3BcjACzFBnj5nqX7RfoKn3Bq3wN5CR@mail.gmail.com>
In-Reply-To: <AANLkTikBHbJorvRpcMb7ZG3KzAMsTVAfqCQe0RS1N=_Y@mail.gmail.com>
References:  <AANLkTikBHbJorvRpcMb7ZG3KzAMsTVAfqCQe0RS1N=_Y@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Dec 26, 2010 at 2:04 PM, b. f. <bf1783@googlemail.com> wrote:

> Frank Shute wrote:
> >I generally play my tracks of an album like so:
> >
> >for track in $(cat trombone_shorty-backatown.m3u); do
> >mplayer $track
> >done
> >
> >They then play in the correct order.
> >
> >How would I go about randomising the order of play using
> >sh (preferably) or perl?
>
> cat trombone_shorty-backatown.m3u | xargs mplayer ... -shuffle
>
> or
>
> mplayer ... -playlist trombone_shorty-backatown.m3u -shuffle
>
> if they are in a uncommented, one-absolute-path-per-line format
> without extended directives?
>
>

Here is something that I wrote a long time ago in python, works quite well

[code]
#!/usr/bin/env python

def randline(f):
        for i,j in enumerate(file(f, 'rb')):
                if random.randint(0,i) == i:
                        line = j
                eturn line

print randline(text)
[/code]

Name it as you wish then it's ./file.py <INPUT>, granted this will only read
1 (random) line from INPUT and print it, it shouldn't be hard to modify this
for your needs tho, enjoy :)

C-



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTimScqpifh3BcjACzFBnj5nqX7RfoKn3Bq3wN5CR>