#setlinebreak(on) *GetRadiko.sh [#b76a8cca] 最新のスクリプトは[[GitHub:https://github.com/sarami55/script]]にあります。 2013/4/1にすこし変更。 playerのバージョンが4.0.0.00になった。 なんか2012/10/25からいままでの[[GetRadiko.sh]]では保存ができなくなったので、いろいろとネットを調べてみたら仕様がわかったみたいなので、スクリプトを変更して見ました。 変更点は以下の通り。 -バグのためかshじゃ動かないのでbashに変更。 line 1 -playerのバージョンが新しくなったらしいので変更 line 42 -playerのgwfファイル内にある認証に使うキーがオブジェクトID 5から14にかわったらしい。 line 70 -ストリーム接続先が変わった。局ごとのxmlファイルを読み込み、接続先を得るようにした。line 157-165 (ここがshではうごかなかった。freebsd7.1) -複数のサーバにftpでアップする記述を外部にだした。 line 242 #sh("bash;highlight:[1,42,70,157,158,159,160,161,162,163,164,165,242]"){{ #!/usr/local/bin/bash export PATH=$PATH:/home/user/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin export LD_LIBRARY_PATH=/home/user/lib export PERL5LIB="/home/user/lib/perl5/lib/perl5:/home/user/lib/perl5/li\b/perl5/perl5/i386-freebsd-64int" POSTURL="http://www8.puny.jp/uploader/upload/" if [ $# -eq 6 ]; then OUTFILEPREFIX=$1 RECTIMEMIN=$2 CHANNEL=$3 else echo "usage : $0 OUTFILEPREFIX RECTIMEMIN CHANNEL" exit 1 fi OUTFILEPREFIX=$1 RECTIMEMIN=$2 CHANNEL=$3 RTMPDUMP=/home/user/bin/rtmpdump FFMPEG=/home/user/ffmpeg OUTFILEBASEPATH=/home/user/REC OUTFILENAME=${OUTFILEBASEPATH}/`date '+%Y-%m-%d-%H%M'`-${CHANNEL}-${OUTFILEPREFIX} AUAUDIR=`date '+%Y-%m'` FLVFILEEXT=".flv" AACFILEEXT=".aac" PASS=`date '+%m%d'` #sleep 30 MARGINTIMEMIN=60 #RECTIME=`expr ${RECTIMEMIN} + ${MARGINTIMEMIN} \* 2 \* 15` RECTIME=`expr ${RECTIMEMIN} + ${MARGINTIMEMIN}` cd ${OUTFILEBASEPATH} playerurl=http://radiko.jp/player/swf/player_3.0.0.01.swf playerfile=/home/user/bin/player.swf keyfile=/home/user/bin/authkey.png # # get player # if [ ! -f $playerfile ]; then wget -q \ --tries=13 \ --retry-connrefused \ --waitretry=4 \ --timeout=10 \ -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 14 $playerfile -o $keyfile if [ ! -f $keyfile ]; then echo "failed get keydata" exit 1 fi fi if [ -f auth1_fms_${OUTFILEPREFIX}_${CHANNEL} ]; then rm -f auth1_fms_${OUTFILEPREFIX}_${CHANNEL} 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 \ --tries=10 \ --retry-connrefused \ --waitretry=5 \ --timeout=10 \ -O auth1_fms_${OUTFILEPREFIX}_${CHANNEL} \ 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_${OUTFILEPREFIX}_${CHANNEL} | perl -ne 'print $1 if(/x-radiko-authtoken: ([\w-]+)/i)'` offset=`cat auth1_fms_${OUTFILEPREFIX}_${CHANNEL} | perl -ne 'print $1 if(/x-radiko-keyoffset: (\d+)/i)'` length=`cat auth1_fms_${OUTFILEPREFIX}_${CHANNEL} | 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_${OUTFILEPREFIX}_${CHANNEL} if [ -f auth2_fms_${OUTFILEPREFIX}_${CHANNEL} ]; then rm -f auth2_fms_${OUTFILEPREFIX}_${CHANNEL} 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 \ --retry-connrefused \ --waitretry=5 \ --tries=10 \ --timeout=10 \ -O auth2_fms_${OUTFILEPREFIX}_${CHANNEL} \ https://radiko.jp/v2/api/auth2_fms if [ $? -ne 0 -o ! -f auth2_fms_${OUTFILEPREFIX}_${CHANNEL} ]; then echo "failed auth2 process" exit 1 fi #echo "authentication success" areaid=`cat auth2_fms_${OUTFILEPREFIX}_${CHANNEL} | perl -ne 'print $1 if(/^([^,]+),/i)'` #echo "areaid: $areaid" rm -f auth2_fms_${OUTFILEPREFIX}_${CHANNEL} 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 # RETRYCOUNT=0 while : do ${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 ${OUTFILENAME}${FLVFILEEXT} \ --stop ${RECTIME} if [ $? -ne 1 -o `wc -c ${OUTFILENAME}${FLVFILEEXT} | awk '{print $1}'` -ge 10240 ]; then break elif [ ${RETRYCOUNT} -ge 5 ]; then echo "failed rtmpdump" exit 1 else RETRYCOUNT=`expr ${RETRYCOUNT} + 1` fi done rm -f $playerfile $keyfile # # # tmpa=${OUTFILENAME}${FLVFILEEXT} com=$4; dlpass=$5; rmpass=$6; tmpfile=/tmp/rrr.$$ filename=`basename $tmpa` upfile=${OUTFILENAME}-${CHANNEL}.zip cd /home/user/REC #zip -q -P $dlpass $upfile $filename gpg --options /home/user/.gnupg/opt.txt $filename #curl -s \ # -F "file=@$upfile;type=application/x-zip-compressed" \ # -F "comment=$com-$PASS" \ # -F "download_pass=$dlpass" \ # -F "remove_pass=$rmpass" \ # -F 'code_pat=京' \ # --retry 5 \ # --retry-delay 10 \ # $POSTURL > $tmpfile # #INFO=/home/user/000/`basename $upfile`; #echo $POSTURL > $INFO #GetId.pl $tmpfile > $INFO.info # # POSTURL=`echo $POSTURL | sed 's/\/upload\//\/download\//'` # ID=`cat $INFO.info` # TW.pl "[`basename $upfile`] is uploaded. $POSTURL$ID.zip" >/dev/null #mv $upfile $filename.zip #rm -f $tmpfile DB=/home/user/.gnupg/Sessionkeys.db key=`gpg -o /dev/null --batch --show-session-key $filename.gpg 2>&1| perl -ne 'print $1 if (/gpg: session key:\s+.(\w+:\w+)/)'` outasffile=`basename $filename` sqlite3 $DB "insert into sKey values('$outasffile.gpg', '$key');" Update-crk.sh $OUTFILEBASEPATH/$outasffile.gpg FTP.sh $filename rm -f $filename.zip $filename.gpg exit 0; }}