Skip to content

Instantly share code, notes, and snippets.

@southrop
Last active October 6, 2016 05: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 southrop/898f54bc38e8a70f73f43abcbce19d9f to your computer and use it in GitHub Desktop.
Save southrop/898f54bc38e8a70f73f43abcbce19d9f to your computer and use it in GitHub Desktop.

Program Schedule

http://radiko.jp/epg/epgapi.php?area_id=JP13&mode=&station_id=TBS

area_id=

Code Region
JP13 Tokyo
JP27 Osaka

mode=

Keyword Result
now current program
today Schedule for today
tomorrow Schedule for tomorrow
(blank) Schedule for one week

station_id=

Tokyo
Code Radio Station
TBS TBS
QRR 文化放送
LFR ニッポン放送
NSB ラジオNIKKEI
INT INTERFM
FMT TOKYO FM
FMJ J-Wave
Osaka
Code Radio Station
ABC 朝日放送
MBS 毎日放送
OBC ラジオ大阪
CCL FMこころ
802 FM802
FMO FM大阪

etc

Stream URLS

Tokyo

Radio Station URL
TBSラジオ rtmp://radiko.smartstream.ne.jp:1935/TBS%2f_defInst_/simul-stream
文化放送 rtmp://radiko.smartstream.ne.jp:1935/QRR%2f_defInst_/simul-stream
ニッポン放送 rtmp://radiko.smartstream.ne.jp:1935/LFR%2f_defInst_/simul-stream
ラジオNIKKEI rtmp://radiko.smartstream.ne.jp:1935/NSB%2f_defInst_/simul-stream
INTERFM rtmp://radiko.smartstream.ne.jp:1935/INT%2f_defInst_/simul-stream
TOKYO FM rtmp://radiko.smartstream.ne.jp:1935/FMT%2f_defInst_/simul-stream
J-WAVE rtmp://radiko.smartstream.ne.jp:1935/FMJ%2f_defInst_/simul-stream

Osaka

Radio Station URL
朝日放送 rtmp://radiko.smartstream.ne.jp:1935/ABC%2f_defInst_/simul-stream
毎日放送 rtmp://radiko.smartstream.ne.jp:1935/MBS%2f_defInst_/simul-stream
ラジオ大阪 rtmp://radiko.smartstream.ne.jp:1935/OBC%2f_defInst_/simul-stream
FMこころ rtmp://radiko.smartstream.ne.jp:1935/CCL%2f_defInst_/simul-stream
FM802 rtmp://radiko.smartstream.ne.jp:1935/802%2f_defInst_/simul-stream
FM大阪 rtmp://radiko.smartstream.ne.jp:1935/FMO%2f_defInst_/simul-stream
#!/bin/bash
pid=$$
date=`date '+%Y-%m-%d-%H_%M'`
radiodate=`TZ=RST-4 date +%Y%m%d`
playerurl=http://radiko.jp/player/swf/player_3.0.0.01.swf
playerfile="./player.swf"
keyfile="./authkey.png"
filename=""
if [ $# -eq 2 ]; then
channel=$1
DURATION=`expr $2 \* 60`
outdir="./"
elif [ $# -eq 3 ]; then
channel=$1
DURATION=`expr $2 \* 60`
outdir=$3
elif [ $# -eq 4 ]; then
channel=$1
DURATION=`expr $2 \* 60`
outdir=$3
filename=$4
else
echo "usage : $0 channel_name duration(minuites) [output_path] [file_basename]"
exit 1
fi
#
# get player
#
if [ ! -f $playerfile ]; then
wget -q -O $playerfile $playerurl > /dev/null
if [ $? -ne 0 ]; then
echo "failed get player"
exit 1
fi
fi
#
# get keydata (need swftool)
#
if [ ! -f $keyfile ]; then
swfextract -b 14 $playerfile -o $keyfile
if [ ! -f $keyfile ]; then
echo "failed get keydata"
exit 1
fi
fi
if [ -f auth1_fms_${pid} ]; then
rm -f auth1_fms_${pid}
fi
#
# access auth1_fms
#
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 \
-O auth1_fms_${pid} \
https://radiko.jp/v2/api/auth1_fms > /dev/null
if [ $? -ne 0 ]; then
echo "failed auth1 process"
exit 1
fi
#
# get partial key
#
authtoken=`perl -ne 'print $1 if(/x-radiko-authtoken: ([\w-]+)/i)' auth1_fms_${pid}`
offset=`perl -ne 'print $1 if(/x-radiko-keyoffset: (\d+)/i)' auth1_fms_${pid}`
length=`perl -ne 'print $1 if(/x-radiko-keylength: (\d+)/i)' auth1_fms_${pid}`
partialkey=`dd if=$keyfile bs=1 skip=${offset} count=${length} 2> /dev/null | base64`
echo "authtoken: ${authtoken} \noffset: ${offset} length: ${length} \npartialkey: $partialkey"
rm -f auth1_fms_${pid}
if [ -f auth2_fms_${pid} ]; then
rm -f auth2_fms_${pid}
fi
#
# access auth2_fms
#
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 \
-O auth2_fms_${pid} \
https://radiko.jp/v2/api/auth2_fms > /dev/null
if [ $? -ne 0 -o ! -f auth2_fms_${pid} ]; then
echo "failed auth2 process"
exit 1
fi
echo "authentication success"
areaid=`perl -ne 'print $1 if(/^([^,]+),/i)' auth2_fms_${pid}`
echo "areaid: $areaid"
rm -f auth2_fms_${pid}
#
# get stream-url
#
if [ -f ${channel}.xml ]; then
rm -f ${channel}.xml
fi
wget -q "http://radiko.jp/v2/station/stream/${channel}.xml"
stream_url=`echo "cat /url/item[1]/text()" | xmllint --shell ${channel}.xml | tail -2 | head -1`
url_parts=(`echo ${stream_url} | perl -pe 's!^(.*)://(.*?)/(.*)/(.*?)$/!$1://$2 $3 $4!'`)
rm -f ${channel}.xml
#
# rtmpdump
#
rtmpdump -v \
-r ${url_parts[0]} \
--app ${url_parts[1]} \
--playpath ${url_parts[2]} \
-W $playerurl \
-C S:"" -C S:"" -C S:"" -C S:$authtoken \
--live \
--stop ${DURATION} \
--flv "./${channel}_${date}.flv" > /dev/null
#ffmpeg -loglevel quiet -y -i "/tmp/${channel}_${date}" -acodec libmp3lame -ab 64k "${outdir}/${filename}_${radiodate}.mp3" > /dev/null && rm -f "/tmp/${channel}_${date}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment