Unix shell script for downloading music from MySpace with
rtmpdump
Code:
#!/bin/bash --
echo "MySpace music downloader by 360percents"
if [ -z "$1" ]; then
echo "";echo "Usage: `basename $0` [url]";echo "";
exit
fi
type -P rtmpdump &>/dev/null || {
read -n1 -p "I need a program called rtmpdump, do you wan to install it now? (y/n) "
echo
[[ $REPLY = [yY] ]] && sudo apt-get install rtmpdump || { echo "You didn't answer yes, or installation failed. Install it manually. Exiting...";}
>&2; exit 1; }
echo "[+] Requesting $1"
page=`wget -L "$1" --quiet --user-agent="Mozilla" -O -`
userid=`echo "$page" | grep 'userID' | sed -e 's/.*userID=//' -e 's/".*//' | uniq`
artistid=`echo "$page" | grep 'artid' | sed -e 's/.*artid=//' -e 's/&.*//' | uniq`
echo "[+] Requesting XML playlist"
link="http://musicservices.myspace.com/Modules/MusicServices/Services/MusicPlayerService.ashx?action=getArtistPlaylist&artistId=$artistid&artistUserId=$userid"
xml=`wget --quiet -L "$link" --user-agent="Mozilla" -O -`
songs=`echo "$xml" | tr ">" "\n" | grep 'songId' | tr ' ' "\n" | grep 'songId' | cut -d '"' -f 2`
songcount=`echo "$songs" | wc -l`
echo "[+] Found $songcount songs."
for i in `seq 1 $songcount`
do
songid=`echo "$songs" | sed -n "$i"p`
link="http://musicservices.myspace.com/Modules/MusicServices/Services/MusicPlayerService.ashx?action=getSong&ptype=4&sample=0&songId=$songid"
songpage=`wget -L "$link" --quiet --user-agent="Mozilla" -O -`
title=`echo "$songpage" | tr "<" "\n" | grep 'title' | tr ">" "\n" | grep -v 'title' | sed -e '/^$/d' | sort -u`
rtmp=`echo "$songpage" | tr "<" "\n" | tr ">" "\n" | grep 'rtmp://' | uniq`
echo "Downloading $title..."
rtmpdump -r "$rtmp" -o "$title.flv" -q
done