Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jimdi/6392cb96dfd502074791955216aea492 to your computer and use it in GitHub Desktop.
Save jimdi/6392cb96dfd502074791955216aea492 to your computer and use it in GitHub Desktop.
Generate di.fm premium account and playlist. Also supports radiotunes.com (ex sky.fm), jazzradio.com, rockradio.com, classicalradio.com
#!/bin/bash
AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
COOKIES="./cookies.txt"
DOMAIN=gmail.com
PLAYLISTDI="di.fm.m3u"
PLAYLISTSKY="sky.fm.m3u"
PLAYLISTJAZZ="jazzradio.m3u"
PLAYLISTROCK="rockradio.m3u"
PLAYLISTCLASSICAL="classicalradio.m3u"
PLAYLISTRADIOTUNES="radiotunes.m3u"
JSONDI="http://listen.di.fm/premium_high.json"
JSONSKY="http://listen.sky.fm/premium_high.json"
JSONJAZZ="http://listen.jazzradio.com/premium_high.json"
JSONROCK="http://listen.rockradio.com/premium_high.json"
JSONCLASSICAL="http://listen.classicalradio.com/premium_high.json"
JSONRADIOTUNES="http://listen.radiotunes.com/premium_high.json"
function rndsleep()
{
sleep .$[ ( $RANDOM % 4 ) + 1 ]s
}
function playlist()
{
playlistfile="$1"
jsonurl="$2"
radioname="$3"
echo "#EXTM3U" > "$playlistfile"
json=$(curl -s "$jsonurl")
nlinks=$(echo "$json" | jshon -l)
num=$(($nlinks-1))
for i in $(seq 0 $num); do
name=$(echo $json | jshon -e $i -e name -u)
playlist=$(echo $json | jshon -e $i -e playlist -u)
json2=$(curl -s $playlist)
playlist2=$(echo $json2 | grep -o -P '(?<=File1=).*(?= Title1)')
echo "#EXTINF:0, $name" >> "$playlistfile"
echo $playlist2?$listen_key >> "$playlistfile"
j=$((i+1))
echo "$j.- $playlist2"
done
echo "$nlinks channels from $radioname written to $playlistfile playlist"
echo ""
}
# check for jshon
which jshon >/dev/null || (echo "install jshon first"; exit 1) || exit 1
# check for pwgen
which pwgen >/dev/null || (echo "install pwgen first"; exit 1) || exit 1
# check for curl
which curl >/dev/null || (echo "install curl first"; exit 1) || exit 1
# generate identity and password
login=$(pwgen -0 $[ ( $RANDOM % 2 ) + 6 ] 1 | tr [A-Z] [a-z])
pass=$(pwgen -0 $[ ( $RANDOM % 2 ) + 6 ] 1 | tr [A-Z] [a-z])
# get csrf-token
csrf_token=$(curl -c $COOKIES -s --request GET "https://www.di.fm/join" --user-agent "$AGENT" \
| awk -F'<input name="authenticity_token" type="hidden" value="' '{ print $2 }' \
| awk -F'"' '{ print $1 }' \
| sed '/^$/d')
rndsleep
# register
curl -b $COOKIES -c $COOKIES -s --request POST "https://www.di.fm/member" -H "X-CSRF-Token: $csrf_token" \
--user-agent "$AGENT" --data "utf8=%E2%9C%93" --data-urlencode "authenticity_token=$csrf_token" \
--data-urlencode "member[email]=$login@$DOMAIN" --data-urlencode "member[password]=$pass" \
--data-urlencode "member[password_confirmation]=$pass" >/dev/null
rndsleep
# subscribe to 7 day premium trial
curl -b $COOKIES -c $COOKIES -s --request GET "https://www.di.fm/member/premium/trial/activate" \
--user-agent "$AGENT" >/dev/null
rndsleep
# get audioaddict config
json=$(curl -b $COOKIES -c $COOKIES -s --request GET "https://www.di.fm" --user-agent "$AGENT" \
| awk -F' this.AudioAddict.API.Config = ' '{ print $2 }' \
| awk -F';' '{ print $1 }' \
| sed '/^$/d')
# set envs
api_key=$(echo "$json" | jshon -e member | jshon -e api_key -u)
listen_key=$(echo "$json" | jshon -e listenKey -u)
id=$(echo "$json" | jshon -e member | jshon -e id)
access=$(echo "$json" | jshon -e access)
echo "access $access"
echo "listen_key $listen_key"
echo "api_key $api_key"
echo "id $id"
echo "login $login@$DOMAIN"
echo "password $pass"
# comment out these if you don't need playlists
playlist "$PLAYLISTDI" "$JSONDI" di.fm
playlist "$PLAYLISTSKY" "$JSONSKY" sky.fm
playlist "$PLAYLISTJAZZ" "$JSONJAZZ" jazzradio.com
playlist "$PLAYLISTROCK" "$JSONROCK" rockradio.com
playlist "$PLAYLISTCLASSICAL" "$JSONCLASSICAL" classicalradio.com
playlist "$PLAYLISTRADIOTUNES" "$JSONRADIOTUNES" radiotunes.com
@SavageCore
Copy link

Your change from "/member" to "/join" in register routine breaks this I believe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment