Actually, you're right. I tried the code I posted again, and it worked, returning the 5. I'm not sure why that didn't work, but it was definitely returning a 0 at the time. Ho hum.
Also, I've never considered sending a fraction to the mplayer -ss argument - I'm presuming it allows a fractional value? I'll test it out to make sure
BTW, for anyone who's interested, here's an example of the current script:
Code:
#!/bin/bash
#~ A script to parse an rss feed, and play any files found within.
#~ It keeps a record of files played, and will replay files that are not on the list.
#~ It currently doesn`t cache the feed, so that`s my next job (not too difficult)
#~ and I'd also like it to remember the last position and play from there
#~ when the script is run again.
# This script is specific to my current setup - I have a google reader feed for spoken word podcasts
# and a feed for music podcasts, so once the podcasts are downloaded to a location on my home
# network by gPodder, my home feed checks the specified directory (along with any files downloaded
# from BBC iPlayer via get_iplayer) and creates a new rss feed for my N95 (and other gadgets) to pick up.
# This script is for my work machine to run when I'm working and just want the latest podcasts/iplayer
# recordings to play in the background.
#~ Wayfarer Boy, Aug 2009
# Work out whether the player is playing spoken word or music (any argument is considered music)
IP="10.0.0.11" # IP of the rss feed
if [[ $# -lt 1 ]]
then
URL='http://$IP/podcasts/'
else
URL='http://$IP/podcasts/?type=music'
fi
PREFIX='http://$IP/podcasts/' # Prefix for the location of the audio file
PLAYED='/home/$USER/scripts/podcasts-played' # Location of played list
OUTPUT='/home/$USER/scripts/podcasts-output' # Location of temporary mplayer output
# Make sure played and temp output files are there
touch $PLAYED
touch $OUTPUT
# Reset counter
COUNT=1
# Put something here about checking the cache or downloading the newer rss file
# Download podcast rss feed and parse for Artist, Album and Filename
# (removing spaces to make sure it loops correctly).
# This parsing is specific to the feed I'm subscribed to,
# so other feeds may be different in their layout
for FILE in `wget -q $URL -O - | \
sed -n -e 's/.*<tr bgcolor="\#EEEEEE"><td align="left"><a href="\.\/\.\/\([^"]*\)">\([^<]*\)<\/a><\/td><td align="left"><a\([^>]*\)>\([^<]*\)<.*/\1~\2~\4/p' | \
tr ' ' '|'`
do
FILENAME=$PREFIX`echo "$FILE" | cut -d '~' -f 1`
if [[ ! `grep "$FILENAME" "$PLAYED"` ]]
then
ARTIST=`echo "$FILE" | cut -d '~' -f 2 | tr '|' ' ' | sed -n -e 's/ / /g'`
ALBUM=`echo "$FILE" | cut -d '~' -f 3 | tr '|' ' ' | sed -n -e 's/ //g'`
echo Playing $COUNT: $ARTIST - $ALBUM # Echo what is playing
COUNT=$((COUNT+1))
mplayer -cache-min 50 "$FILENAME" &> $OUTPUT # Play file
# Find out if mplayer exited correctly (ie, finished the file or was skipped)
# or if it was exited (CTRL-C or stream lost)
EXIT=`tail $PLAYED -n 1`
if [[ "$EXIT" == "Exiting... (End of file)" ]]
then
echo "$FILENAME" >> $PLAYED # Add filename to 'played' list
rm $OUTPUT # Remove the mplayer output file
else
# Put something here about saving the last position
exit 0 # Exit the loop and exit the script
fi
fi
done
exit 0
Bookmarks