-
-
Save zarigani/4555169 to your computer and use it in GitHub Desktop.
認証部分と録音部分に大別
-aオプションを追加(エリア情報を取得)
-oオプションを拡張(ディレクトリ名とファイル名の自由度を高める) オプションを設定する仕様に変更
コマンドをフルパスに変更
rm -fの条件判定を削除
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| playerurl=http://radiko.jp/player/swf/player_2.0.1.00.swf | |
| playerfile=./player.swf | |
| keyfile=./authkey.png | |
| if [ $# -eq 1 ]; then | |
| channel=$1 | |
| output=./$1.flv | |
| elif [ $# -eq 2 ]; then | |
| channel=$1 | |
| output=$2 | |
| else | |
| echo "usage : $0 channel_name [outputfile]" | |
| 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 swftools) | |
| # | |
| if [ ! -f $keyfile ]; then | |
| swfextract -b 5 $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=`cat auth1_fms | perl -ne 'print $1 if(/x-radiko-authtoken: ([\w-]+)/i)'` | |
| offset=`cat auth1_fms | perl -ne 'print $1 if(/x-radiko-keyoffset: (\d+)/i)'` | |
| length=`cat auth1_fms | perl -ne 'print $1 if(/x-radiko-keylength: (\d+)/i)'` | |
| 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=`cat auth2_fms | perl -ne 'print $1 if(/^([^,]+),/i)'` | |
| echo "areaid: $areaid" | |
| rm -f auth2_fms | |
| # | |
| # rtmpdump | |
| # | |
| rtmpdump -v \ | |
| -r "rtmpe://radiko.smartstream.ne.jp" \ | |
| --playpath "simul-stream" \ | |
| --app "${channel}/_defInst_" \ | |
| -W $playerurl \ | |
| -C S:"" -C S:"" -C S:"" -C S:$authtoken \ | |
| --live \ | |
| --flv $output |
xpath コマンドは libxml-xpath-perl パッケージに含まれているようです。
libxml-xpath-perl: /usr/bin/xpath
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
素晴らしいスクリプトありがとうございます。この中で使われている xpath コマンドの由来が分からなかったのですが、何由来か分かりますでしょうか。多分何らかのPerlモジュールから入ったものと思うのですが…。Debian系OSであれば dpkg -S $(which xpath) すると調べられると思います。
I thanks to this awesome script! I wonder
xpathcommand using in this script. Where is this command from? If you use Debian like OS, you can lookdpkg -S $(which xpath).