From owner-freebsd-questions@FreeBSD.ORG Sun Dec 26 20:07:27 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7F678106566B for ; Sun, 26 Dec 2010 20:07:27 +0000 (UTC) (envelope-from xaero@xaerolimit.net) Received: from mail-ew0-f54.google.com (mail-ew0-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 1ABA48FC12 for ; Sun, 26 Dec 2010 20:07:26 +0000 (UTC) Received: by ewy24 with SMTP id 24so4162092ewy.13 for ; Sun, 26 Dec 2010 12:07:26 -0800 (PST) Received: by 10.213.106.11 with SMTP id v11mr3232038ebo.38.1293394045804; Sun, 26 Dec 2010 12:07:25 -0800 (PST) MIME-Version: 1.0 Received: by 10.213.112.145 with HTTP; Sun, 26 Dec 2010 12:07:05 -0800 (PST) In-Reply-To: References: From: Chris Brennan Date: Sun, 26 Dec 2010 15:07:05 -0500 Message-ID: To: bf1783@gmail.com Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Frank Shute , freebsd-questions@freebsd.org Subject: Re: randomising tracks: scripting question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Dec 2010 20:07:27 -0000 On Sun, Dec 26, 2010 at 2:04 PM, b. f. 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 , 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-