Skip to content

Instantly share code, notes, and snippets.

@ohac
Forked from matchy256/rec_radiko.sh
Created May 6, 2018 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohac/3a25067e2b95fd151cfa3aa5248ad4a6 to your computer and use it in GitHub Desktop.
Save ohac/3a25067e2b95fd151cfa3aa5248ad4a6 to your computer and use it in GitHub Desktop.
簡易Radiko録音スクリプト
#!/bin/bash
set -x
set -e
#pid=$$
pid="1" # TODO
date=`date '+%Y-%m-%d-%H_%M'`
playerurl=http://radiko.jp/apps/js/flash/myplayer-release.swf
playerfile="player.swf"
keyfile="authkey.png"
#channel=$1
channel="JOAB" # TODO
if [ ! -f $playerfile ]; then
wget -q -O $playerfile $playerurl
fi
if [ ! -f $keyfile ]; then
swfextract -b 12 $playerfile -o $keyfile
fi
a1fms="auth1_fms_${pid}"
rm -f $a1fms
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 \
-O $a1fms \
https://radiko.jp/v2/api/auth1_fms
authtoken=`perl -ne 'print $1 if(/x-radiko-authtoken: ([\w-]+)/i)' $a1fms`
offset=`perl -ne 'print $1 if(/x-radiko-keyoffset: (\d+)/i)' $a1fms`
length=`perl -ne 'print $1 if(/x-radiko-keylength: (\d+)/i)' $a1fms`
partialkey=`dd if=$keyfile bs=1 skip=${offset} count=${length} 2> /dev/null | base64`
a2fms="auth2_fms"
rm -f $a2fms
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 \
-O $a2fms \
https://radiko.jp/v2/api/auth2_fms
cxml="${channel}.xml"
rm -f $cxml
wget -q "http://radiko.jp/v2/station/stream/$cxml"
stream_url=`echo "cat /url/item[1]/text()" | xmllint --shell $cxml | tail -2 | head -1`
url_parts=(`echo ${stream_url} | perl -pe 's!^(.*)://(.*?)/(.*)/(.*?)$/!$1://$2 $3 $4!'`)
rtmpdump -q \
-r ${url_parts[0]} \
--app ${url_parts[1]} \
--playpath ${url_parts[2]} \
-W $playerurl \
-C S:"" -C S:"" -C S:"" -C S:$authtoken \
--live \
--flv "${channel}_${date}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment