Created
October 11, 2016 13:34
-
-
Save fukubaya/9ec62d7751011f8b5355fecb4b93944b to your computer and use it in GitHub Desktop.
Get auth token from radio server (2016/10)
This file contains hidden or 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/sh | |
#playerurl=http://radiko.jp/player/swf/player_3.0.0.01.swf | |
#playerurl=http://radiko.jp/player/swf/player_4.1.0.00.swf | |
playerurl=http://radiko.jp/apps/js/flash/myplayer-release.swf | |
# | |
# access auth1_fms | |
# | |
auth1_fms=`/usr/local/bin/wget -q \ | |
--header="pragma: no-cache" \ | |
--header="X-Radiko-App: pc_ts" \ | |
--header="X-Radiko-App-Version: 4.0.0" \ | |
--header="X-Radiko-User: test-stream" \ | |
--header="X-Radiko-Device: pc" \ | |
--post-data='\r\n' \ | |
--no-check-certificate \ | |
--save-headers \ | |
https://radiko.jp/v2/api/auth1_fms \ | |
-O -` | |
if [ $? -ne 0 -o ! "${auth1_fms}" ]; then | |
echo "failed auth1 process" 1>&2 | |
exit 1 | |
fi | |
# get keydata | |
# get partial key | |
# | |
authtoken=`echo ${auth1_fms} | perl -ne 'print $1 if(/x-radiko-authtoken: ([\w-]+)/i)'` | |
offset=`echo ${auth1_fms} | perl -ne 'print $1 if(/x-radiko-keyoffset: (\d+)/i)'` | |
length=`echo ${auth1_fms} | perl -ne 'print $1 if(/x-radiko-keylength: (\d+)/i)'` | |
partialkey=`/usr/local/bin/wget -q -O - ${playerurl} 2>/dev/null | \ | |
/opt/local/bin/swfextract -b 12 /dev/stdin -o /dev/stdout | \ | |
dd bs=1 skip=${offset} count=${length} 2> /dev/null | \ | |
/opt/local/bin/base64` | |
if [ $? -ne 0 -o ! "${partialkey}" ]; then | |
echo "failed auth1 process" 1>&2 | |
exit 1 | |
fi | |
# | |
# access auth2_fms | |
# | |
auth2_fms=`/usr/local/bin/wget -q \ | |
--header="pragma: no-cache" \ | |
--header="X-Radiko-App: pc_ts" \ | |
--header="X-Radiko-App-Version: 4.0.0" \ | |
--header="X-Radiko-User: test-stream" \ | |
--header="X-Radiko-Device: pc" \ | |
--header="X-Radiko-Authtoken: ${authtoken}" \ | |
--header="X-Radiko-Partialkey: ${partialkey}" \ | |
--post-data='\r\n' \ | |
--no-check-certificate \ | |
https://radiko.jp/v2/api/auth2_fms \ | |
-O -` | |
if [ $? -ne 0 -o ! "${auth2_fms}" ]; then | |
echo "failed auth2 process" 1>&2 | |
exit 1 | |
fi | |
### echo "authentication success" 1>&2 | |
areaid=`echo ${auth2_fms} | perl -ne 'print $1 if(/^([^,]+),/i)'` | |
### echo "areaid: ${areaid}" 1>&2 | |
echo "${playerurl}" "${authtoken}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment