#!/bin/sh

[ "$1" = "" ] && echo "please give me a myspace tv URL" && exit 1

echo -n "Extracting ID... "
ID=`echo "$1" | sed 's/[a-za-Z\:\/\.\?\=\&]//g'`
RET=`echo "$ID" | grep "^[0-9]*$"`
[ "$RET" = "" ] && echo -e "error.\ncannot extract an ID from this URL" && exit 2
echo "done."

URL=`wget "http://mediaservices.myspace.com/services/rss.ashx?type=video&videoID=$ID" -O - -q | grep flv | cut -d\" -f 2`

echo "downloading $URL"
wget "$URL"

RET=$?
[ "$RET" != "0" ] && echo "error while downloading video" && exit 3
echo "download successful"