Skip to content

Instantly share code, notes, and snippets.

@fukubaya
Created October 25, 2012 16:58
Show Gist options
  • Save fukubaya/3954034 to your computer and use it in GitHub Desktop.
Save fukubaya/3954034 to your computer and use it in GitHub Desktop.
Get auth token from radiko server
#!/bin/sh
playerurl=http://radiko.jp/player/swf/player_3.0.0.01.swf
#
# access auth1_fms
#
auth1_fms=`/usr/local/bin/wget -q \
--header="pragma: no-cache" \
--header="X-Radiko-App: pc_1" \
--header="X-Radiko-App-Version: 2.0.1" \
--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 14 /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_1" \
--header="X-Radiko-App-Version: 2.0.1" \
--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}"
@fukubaya
Copy link
Author

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