Adobe flashのサポート終了に伴う、ザリガニが見ていたさんのrec_radiko.shの変更

主題
Adobe flashのサポート終了に伴う、ザリガニが見ていたさんのrec_radiko.shの変更点について述べる。

背景
遅きに失した感はあるが、Adobe flashのサポート終了に伴い、ファンであるザリガニが見ていたさんのrec_radiko.shが動かなくなってしまっていた。使っていないのがバレた気もするし、ほとんどあるスクリプトのコピペなのだが、一応公開しておく。
なお、このスクリプトはエリアフリー対応ではない。エリア外のラジオ局を録音しようとすると、403 Forbiddenで終了する。

手順

  1. ベーススクリプト
    ザリガニが見ていたさんのスクリプト

  2. 筆者によるベーススクリプトの仕様変更
    diffファイルはこちらからダウンロードできる。

  3. Big Sur導入によって必要となったスクリプトの仕様変更

    diffファイルは、こちらからダウンロードできる。

  4. Adobe flash廃止によって必要となったスクリプトの仕様変更

    --- a/rec_radiko.sh	2020-11-16 09:04:23.000000000 +0900
    +++ b/rec_radiko.sh	2021-07-17 16:25:11.000000000 +0900
    @@ -2,7 +2,7 @@
    # Original1: https://gist.github.com/875864 saiten / rec_radiko.sh
    # Original2: http://backslash.ddo.jp/wordpress/archives/1020 http://backslash.ddo.jp/tools/rec_radiko2.txt
    
    -# Install: wget swftools rtmpdump ffmpeg http://d.hatena.ne.jp/zariganitosh/20130120/radiko_recoding_again
    +# Install: wget ffmpeg http://d.hatena.ne.jp/zariganitosh/20130120/radiko_recoding_again
    
    PATH=$PATH:/usr/local/bin
    VERSION=4.0.0
    @@ -25,39 +25,13 @@
    # 認証
    radiko_authorize() {
    echo "==== authorize ===="
    -  #
    -  # get player
    -  #
    -  if [ ! -f $playerfile ]; then
    -    echo $playerfile downloading...
    -    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
    -    echo $keyfile extracting...
    -    # swfextract -b 5 $playerfile -o $keyfile <---radiko仕様変更点
    -    swfextract -b 12 $playerfile -o $keyfile
    -
    -    if [ ! -f $keyfile ]; then
    -      echo "failed get keydata"
    -      exit 1
    -    fi
    -  fi
    -
    +authkey_value="bcd151073c03b352e1ef2fd66c32209da9ca0afa"
    #
    # access auth1_fms
    #
    wget -q \
            --header="pragma: no-cache" \
    -       --header="X-Radiko-App: pc_ts" \
    +       --header="X-Radiko-App: pc_html5" \
            --header="X-Radiko-App-Version: $VERSION" \
            --header="X-Radiko-User: test-stream" \
            --header="X-Radiko-Device: pc" \
    @@ -77,16 +51,20 @@
    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`
    +  partialkey=`echo $authkey_value | dd bs=1 skip=${offset} count=${length} 2> /dev/null | base64`
    +
    +  echo "authtoken: ${authtoken}
    +  offset: ${offset}
    +  length: ${length}
    +  partialkey:
    +  $partialkey"
    
    -  echo "authtoken: ${authtoken}\n offset: ${offset}\n length: ${length}\n partialkey: $partialkey"
    -
    #
    # access auth2_fms
    #
    wget -q \
            --header="pragma: no-cache" \
    -       --header="X-Radiko-App: pc_ts" \
    +       --header="X-Radiko-App: pc_html5" \
            --header="X-Radiko-App-Version: $VERSION" \
            --header="X-Radiko-User: test-stream" \
            --header="X-Radiko-Device: pc" \
    @@ -113,27 +91,24 @@
    #
    # get stream-url
    #
    -  channel_xml=`wget -q "http://radiko.jp/v2/station/stream/${channel}.xml" -O -`
    -  stream_url=`echo $channel_xml | sed 's/^\(\)/\1UTF-8\2/' | xpath -e  "//url/item[1]/text()" 2>/dev/null`
    -  stream_url_parts=(`echo ${stream_url} | perl -pe 's!^(.*)://(.*?)/(.*)/(.*?)$/!$1://$2 $3 $4!'`)
    +  channel_xml=`wget -q "http://radiko.jp/v2/station/stream_smh_multi/${channel}.xml" -O -`
    +  stream_url=`echo $channel_xml | xpath -e "/urls/url[@areafree='0'][1]/playlist_create_url/text()" 2>/dev/null`
    
    #
    -  # get authtoken
    -  #
    -  authtoken=`perl -ne 'print $1 if(/x-radiko-authtoken: ([\w-]+)/i)' auth1_fms_$$`
    -
    -  #
    -  # rtmpdump
    +  # Record HLS with ffmpeg
    #
    echo "save as '$output'"
    -  rtmpdump -r ${stream_url_parts[0]} \
    -           --app ${stream_url_parts[1]} \
    -           --playpath ${stream_url_parts[2]} \
    -           -W $playerurl \
    -           -C S:"" -C S:"" -C S:"" -C S:$authtoken \
    -           --live \
    -           --stop "${rectime:=30}" \
    -           --flv "${output}"
    +  ffmpeg \
    +    -loglevel error \
    +    -fflags +discardcorrupt \
    +    -headers "X-Radiko-Authtoken: ${authtoken}" \
    +    -i "${stream_url}" \
    +    -acodec copy \
    +    -vn \
    +    -bsf:a aac_adtstoasc \
    +    -y \
    +    -t ${rectime:=30} \
    +    "${output}"
    }
    
    # 引数解析
    @@ -173,13 +148,8 @@
    
    mkdir -p ${wdir:=$HOME/Downloads} ; cd $wdir ; wdir=`pwd`
    
    -station_name=`curl -s http://radiko.jp/v2/api/program/station/today?station_id=$channel|xpath "//station/name/text()" 2>/dev/null`
    -output="${wdir}/${fname:=${station_name}_`date +%Y%m%d-%H%M`}${fext:=.flv}"
    -
    -# playerurl=http://radiko.jp/player/swf/player_2.0.1.00.swf <---radiko仕様変更点
    -playerurl=http://radiko.jp/apps/js/flash/myplayer-release.swf
    -playerfile=./player.swf
    -keyfile=./authkey.jpg
    +station_name=`curl -s http://radiko.jp/v2/api/program/station/today?station_id=$channel|xpath -e "//station/name/text()" 2>/dev/null`
    +output="${wdir}/${fname:=${station_name}_`date +%Y%m%d-%H%M`}${fext:=.m4a}"
    
    if [ "$OPTION_a" = "TRUE" ]; then
    radiko_authorize && cat auth2_fms_$$|grep -e '^\w\+'
    @@ -187,9 +157,5 @@
    radiko_authorize && radiko_record
    fi
    
    -ffmpeg -v quiet -y -i "${output}" -c: copy "${output%.*}.aac"
    -MP4Box -add "${output%.*}.aac" "${output%.*}.m4a" -sbr
    -rm -f "${output}"
    -rm -f "${output%.*}.aac"
    rm -f auth1_fms_$$
    rm -f auth2_fms_$$

    diffファイルは、こちらからダウンロードできる。

  5. パッチの適用

    patch -p1 < rec_radiko.patch
    patch -p1 < rec_radiko_big_sur.patch
    patch -p1 < rec_radiko_remove_flash_releted.patch

参考サイト

以上。

この投稿へのコメント

コメントはありません。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

この投稿へのトラックバック

トラックバックはありません。

トラックバック URL