#!/bin/bash -e # Copyright (C) 2008 David Mandelberg NAME="`basename "$0"`" GST_LAUNCH="gst-launch-0.10 -t" MODE="loop" MUSIC="$HOME" COUNT=-1 normalize_uri () { RET="$1" case "$1" in /*) ;; *) RET="`pwd`/$RET" ;; esac printf "%s" "$RET" } play_file () { FILE="`normalize_uri "$1"`" test x"$COUNT" = x0 && exit 0 echo "Attempting to play file: $FILE..." $GST_LAUNCH playbin uri="file://$FILE" test x"$COUNT" = x"-1" || let COUNT-- } TMP="`getopt -o hrslc: -l help,random,sequential,loop,count: -n "$NAME" -- "$@"`" eval set -- "$TMP" while true; do case "$1" in -h|--help) echo "$NAME [-r|-s|-l] [-c NUMBER] [-h] [FILE...]" echo "-r | --random: play files in random order" echo "-s | --sequential: play files once in order" echo "-l | --loop: play files continuously in order [DEFAULT]" echo "-c | --count NUMBER: play NUMBER files, then stop" echo "-h | --help: show this message" exit ;; -r|--random) MODE="rand" shift ;; -s|--sequential) MODE="seq" shift ;; -l|--loop) MODE="loop" shift ;; -c|--count) COUNT="$2" shift 2 ;; --) shift break ;; *) echo "Internal error parsing options." exit 1 ;; esac done echo "Building list of files..." PLS="`mktemp`" for i in "$@"; do find "$i" -type f -print \ | sort -dfn \ >> "$PLS" done case "$MODE" in rand) echo "Randomizing order of list of files..." TMP="`mktemp`" while read LINE; do printf "%05d%05d:%s\n" "$RANDOM" "$RANDOM" "$LINE" >> "$TMP" done < "$PLS" sort < "$TMP" | cut -c 12- > "$PLS" rm -f "$TMP" unset TMP ;; esac while test x"$COUNT" != x0; do while read LINE; do play_file "$LINE" done < "$PLS" test x"$MODE" = xseq && break done