Instantly share code, notes, and snippets.
Forked from jimdi/di-fm-premium-account-generator.sh
Last active
June 8, 2018 07:58
-
Star
(1)
1
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save aquigni/9c08fc19cb4ff8b7d4d23d256947c9f0 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#------------------------------------------------------------------------------# | |
#--- MAIN SCRIPT ---# | |
#------------------------------------------------------------------------------# | |
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" | |
############################################################################### | |
### Check Homebrew, install if missing ### | |
############################################################################### | |
# ... | |
### Install deps | |
echo "Installing required depednencies ..." | |
brew install jshon pwgen curl grep --with-default-names | |
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 | |
#------------------------------------------------------------------------------# | |
#--- FUTURE ---# | |
#------------------------------------------------------------------------------# | |
### Emulate (?) iOS AppStore subscription to activate trial via app | |
### LOW PRIORITY — Add DI.fm playlist to iTunes and trigger renaming (!) stations properly. Parse station covers and enable them locally. | |
### AUTOMATE SUBSCR CANCELLING one day before iTunes charging | |
# _then_ | |
### AUTOMATE ALL: generating credentials, activating, cancelling, loop again | |
### TRANSFER all automation to backend server | |
### CREATE simple userspace frontend | |
### CREATE unreally simplest iOS DI.FM++ app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment