#!/bin/sh
# myspace.sh - 0.0.1 pre-alpha1
# Copyright (C) 2010 Funatiker
# under the terms of the GNU General Public License
# usage: myspace.sh NAME
# description: downloads the songs from myspace.com/NAME
# dependencies: curl, rtmpdump
#artistId und friendId auslesen
ids=$(curl -s "http://www.myspace.com/$1" | grep profid.*artid | head -n1 | sed 's/&/\n/g' | grep -E "profid|artid" | cut -d\= -f2)
friendId=$(echo $ids | cut -d\ -f1)
artistId=$(echo $ids | cut -d\ -f2)
#Playlists bekommen
for playlistId in $(curl -s "http://musicservices.myspace.com/Modules/MusicServices/Services/MusicPlayerService.ashx?friendId=$friendId&action=getPlaylists" | sed 's/ /\n/g' | grep playlistId | cut -d\" -f2)
do
#IDs der Songs bekommen
for songId in $(curl -s "http://www.myspace.com/Modules/MusicServices/Services/MusicPlayerService.ashx?artistId=$artistId&action=getArtistPlaylist&artistUserId=$friendId&playlistId=$playlistId&ptype=4" | sed 's/ /\n/g' | grep songId | cut -d\" -f2)
do
#rtmp-Link bekommen
rtmp=$(curl -s "http://www.myspace.com/Modules/MusicServices/Services/MusicPlayerService.ashx?songId=$songId&action=getSong&ptype=4" | sed -e 's/rtmp>/\n/g' -e 's/<\///g' -e 's/rtmp/rtmpe/g' | grep rtmp)
#dateinamen festlegen
file=$1"_"$(echo $rtmp | sed 's/\//\n/g' | tail -n1)
# DUMPEN!
rtmpdump -r $rtmp -o $file --swfVfy http://lads.myspacecdn.com/videos/MSMusicPlayer.swf
done
done