summaryrefslogtreecommitdiff
path: root/m_dl.sh
diff options
context:
space:
mode:
Diffstat (limited to 'm_dl.sh')
-rwxr-xr-xm_dl.sh81
1 files changed, 81 insertions, 0 deletions
diff --git a/m_dl.sh b/m_dl.sh
new file mode 100755
index 0000000..283d273
--- /dev/null
+++ b/m_dl.sh
@@ -0,0 +1,81 @@
+#!/bin/bash
+XSLT_TRACKLIST="`dirname \"$0\"`/tracklist.xsl"
+check() {
+ if ! type ${1} >/dev/null 2>&1; then
+ echo "missing ${1}${2}"
+ exit 2
+ fi
+}
+
+check rtmpdump
+check xsltproc
+check ffmpeg
+check vorbiscomment ": see vorbis-tools package"
+
+getplid() {
+ wget -q -O - "$1" | sed -n -e 'b start; :quit; q; :start; s/.*plid=\([0-9]*\).*/\1/p; t quit'
+}
+
+getfriendid() {
+ wget -q -O - "$1" | sed -n -e 'b start; :quit; q; :start; s/.*friendId=\([0-9]*\).*/\1/p; t quit'
+}
+
+
+eachSong() {
+ for song in `wget -O - -q "http://musicservices.myspace.com/Modules/MusicServices/Services/MusicPlayerService.ashx?action=getPlaylist&friendId=${2}&playlistId=${1}" | xsltproc "${XSLT_TRACKLIST}" -`; do
+ songId=`echo $song | cut -d \; -f 1`
+ albumId=`echo $song | cut -d \; -f 2`
+ releaseId=`echo $song | cut -d \; -f 3`
+ title=`echo $song | cut -d \; -f 4`
+ artist=`echo $song | cut -d \; -f 5`
+ if [ "xx${songId}" == "xx" ] || [ "xx${albumId}" == "xx" ] || [ "xx${releaseId}" == "xx" ] || [ "xx${title}" == "xx" ]; then
+ echo "skip: ${song}" >&2
+ continue
+ fi
+ echo "load: ${song}" >&2
+ if [ "xx${albumId}" == "xx0" ]; then
+ rtmpUrl=`wget -O - -q \
+ "http://musicservices.myspace.com/Modules/MusicServices/Services/MusicPlayerService.ashx?releaseId=${releaseId}&sample=0&el=&action=getSong&songId=${songId}&ptype=4" \
+ | sed -n -e 's/.*<rtmp>rtmp\(.*\)<\/rtmp>.*/rtmpe\1/p'`
+
+ else
+ rtmpUrl=`wget -O - -q \
+ "http://musicservices.myspace.com/Modules/MusicServices/Services/MusicPlayerService.ashx?albumId=${albumId}&sample=0&el=&action=getSong&songId=${songId}&ptype=4" \
+ | sed -n -e 's/.*<rtmp>rtmp\(.*\)<\/rtmp>.*/rtmpe\1/p'`
+ fi
+ if [ "xx${rtmpUrl}" == "xx" ]; then
+ echo "could not find rtmpe URL" >&2
+ else
+ filename=${title}.ogg
+ download "${rtmpUrl}" "${filename}"
+ vorbiscomment -w -t "ARTIST=${artist}" -t "TITLE=${title}" "${filename}"
+ fi
+ done
+ echo done
+}
+
+download() {
+ echo ${1} ${2}
+ if [ -f "${2}" ]; then
+ echo "Skip ${2} - file exist"
+ return
+ else
+ echo "load ${2}"
+ rtmpdump -o - -r "$1" \
+ | ffmpeg -f flv -i - -acodec libvorbis -ab 192k -ar 44100 -vn "${2}"
+ fi
+}
+
+if [ $# -eq 1 ]; then
+ plid=`getplid "$1"`
+ friendId=`getfriendid "$1"`
+ if [ "xx${plid}" == "xx" ] || [ "xx${friendId}" == "xx" ]; then
+ echo "no plid/friendid found for $1" >&2
+ else
+ echo "load all songs from playlist id=$plid friendId=$friendId" >&2
+ eachSong "$plid" "$friendId"
+ fi
+else
+ echo "$0 URL - loads all music files from a myspace profile"
+ echo "URL in form: http://www.myspace.com/PROFILE"
+fi