RTMPDUMPによるradikoの録音(2012/10/28修正)

October 28, 2012 – 10:23 am

2,3日前からradikoの録音ができなくなっていたのに気づいた。

原因は、radikoの仕様が少し変わったことのようだ。変更部分が反映されるように、Radiko録音用shell scriptを修正しておいた。

修正したshell script: 以前のポスト(RTMPDUMPによるradikoの録音)に示しておいたshell scriptを以下に置き換えることで問題なく動作。

動作を確認。

radiko.sh:


#!/bin/sh

date=`date '+%Y-%m-%d-%H:%M'`
playerurl=http://radiko.jp/player/swf/player_3.0.0.01.swf
playerfile=./player.swf
keyfile=./authkey.png

if [ $# -eq 2 ]; then
  station=$1
  DURATION=`expr $2 \* 60`
else
  echo "usage : $0 station_name duration(minuites)"
  exit 1
fi

#
# get player
#
if [ ! -f $playerfile ]; then
  wget -q -O $playerfile $playerurl

  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 ]; then
  rm -f auth1_fms
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 \
     https://radiko.jp/v2/api/auth1_fms

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`
offset=`perl -ne 'print $1 if(/x-radiko-keyoffset: (\d+)/i)' auth1_fms`
length=`perl -ne 'print $1 if(/x-radiko-keylength: (\d+)/i)' auth1_fms`

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

if [ -f auth2_fms ]; then
  rm -f auth2_fms
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 \
     https://radiko.jp/v2/api/auth2_fms

if [ $? -ne 0 -o ! -f auth2_fms ]; then
  echo "failed auth2 process"
  exit 1
fi

echo "authentication success"
areaid=`perl -ne 'print $1 if(/^([^,]+),/i)' auth2_fms`
echo "areaid: $areaid"

rm -f auth2_fms

#
# rtmpdump
#
/opt/rtmpdump-2.4/rtmpdump -v \
         -r "rtmpe://w-radiko.smartstream.ne.jp" \
         --playpath "simul-stream.stream" \
         --app "${station}/_definst_" \
         -W $playerurl \
         -C S:"" -C S:"" -C S:"" -C S:$authtoken \
         --live \
         --stop $DURATION \
         -o "/tmp/${1}_${date}"

ffmpeg -y -i "/tmp/${1}_${date}" -acodec libmp3lame "/var/www/test/audio/${1}_${date}.mp3"

rm "/tmp/${1}_${date}"

修正情報については、http://fukubaya.blogspot.jp/2012/10/radiko.htmlを参考にさせていただいた。


  1. 4 Responses to “RTMPDUMPによるradikoの録音(2012/10/28修正)”

  2. player_3.0.1.01.swf は player_3.0.0.01.swf じゃないとダメかも

    By otsune on Nov 6, 2012

  3. ご指摘ありがとうございました。

    playerurl を type miss していました。

    みなさん修正お願いします。

    とはいうものの、player_3.0.1.01.swf のままでも動作していました???
    何なんでしょうね?

    By yama on Nov 7, 2012

  1. 2 Trackback(s)

  2. Oct 28, 2012: RTMPDUMPによるradikoの録音 | Yama's Memorandum
  3. Sep 18, 2014: Yama's Memorandum » Blog Archive » RTMPDUMPによるradikoの録音(2014/09/18修正)

Post a Comment