Skip to content

Instantly share code, notes, and snippets.

@laiso
Forked from saiten/rec_radiko.sh
Last active October 5, 2015 08:38

Revisions

  1. laiso revised this gist Nov 18, 2014. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions rec_radiko.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,4 @@
    #!/bin/sh
    # Original: https://gist.github.com/875864
    # Edited by: http://backslash.ddo.jp

    playerurl=http://radiko.jp/player/swf/player_3.0.0.01.swf
    playerfile=./player.swf
  2. laiso revised this gist Nov 18, 2014. 1 changed file with 23 additions and 18 deletions.
    41 changes: 23 additions & 18 deletions rec_radiko.sh
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,25 @@
    #!/bin/sh

    cd `dirname $0`
    # Original: https://gist.github.com/875864
    # Edited by: http://backslash.ddo.jp

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

    if [ $# -eq 1 ]; then
    channel=$1
    output=./$1.flv
    rectime=''
    elif [ $# -eq 2 ]; then
    channel=$1
    output=$2
    rectime=''
    elif [ $# -eq 3 ]; then
    channel=$1
    output=$2
    stop=$3
    rectime=$3
    else
    echo "[DEBUG] usage : $0 channel_name [outputfile]"
    echo "usage : $0 channel_name [outputfile] [rectime]"
    exit 1
    fi

    @@ -38,10 +39,10 @@ fi
    # get keydata (need swftool)
    #
    if [ ! -f $keyfile ]; then
    swfextract -b 5 $playerfile -o $keyfile
    swfextract -b 14 $playerfile -o $keyfile

    if [ ! -f $keyfile ]; then
    echo "[ERROR] failed get keydata"
    echo "failed get keydata"
    exit 1
    fi
    fi
    @@ -65,7 +66,7 @@ wget -q \
    https://radiko.jp/v2/api/auth1_fms

    if [ $? -ne 0 ]; then
    echo "[ERROR] failed auth1 process"
    echo "failed auth1 process"
    exit 1
    fi

    @@ -78,7 +79,7 @@ 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 "[DEBUG] authtoken: ${authtoken} \noffset: ${offset} length: ${length} \npartialkey: $partialkey"
    echo "authtoken: ${authtoken} \noffset: ${offset} length: ${length} \npartialkey: $partialkey"

    rm -f auth1_fms

    @@ -102,31 +103,35 @@ wget -q \
    https://radiko.jp/v2/api/auth2_fms

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

    echo "[DEBUG] authentication success"
    echo "authentication success"

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

    rm -f auth2_fms

    flv="${output}.flv"

    #
    # rtmpdump
    #
    flv="${output}.flv"
    rtmpdump -v \
    -B $stop \
    -r "rtmpe://f-radiko.smartstream.ne.jp" \
    --playpath "simul-stream.stream" \
    --app "${channel}/_definst_" \
    -W $playerurl \
    -C S:"" -C S:"" -C S:"" -C S:$authtoken \
    --live \
    --stop "${rectime}" \
    --flv $flv

    mp3="~/Dropbox/Music/${output}-${suffix}.mp3"
    ffmpeg -i $flv $mp3
    ./upload/env/bin/python ./upload/upload_gmusic.py $mp3
    echo "=== Covert FLV -> mp3 ===="

    suffix=`date '+%Y%m%d'`
    out="${output}-${suffix}.m4a"
    ffmpeg -i $flv -acodec copy $out
    aws s3 cp $out s3://so.lai.radio/
  3. laiso revised this gist Sep 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rec_radiko.sh
    Original file line number Diff line number Diff line change
    @@ -119,7 +119,7 @@ rm -f auth2_fms
    flv="${output}.flv"
    rtmpdump -v \
    -B $stop \
    -r "rtmpe://w-radiko.smartstream.ne.jp" \
    -r "rtmpe://f-radiko.smartstream.ne.jp" \
    --playpath "simul-stream.stream" \
    --app "${channel}/_definst_" \
    -W $playerurl \
  4. laiso revised this gist Oct 27, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rec_radiko.sh
    Original file line number Diff line number Diff line change
    @@ -127,6 +127,6 @@ rtmpdump -v \
    --live \
    --flv $flv

    mp3="/home/kstg/Dropbox/Music/${output}-${suffix}.mp3"
    mp3="~/Dropbox/Music/${output}-${suffix}.mp3"
    ffmpeg -i $flv $mp3
    ./upload/env/bin/python ./upload/upload_gmusic.py $mp3
  5. laiso revised this gist Oct 26, 2012. No changes.
  6. laiso revised this gist Oct 26, 2012. 1 changed file with 14 additions and 13 deletions.
    27 changes: 14 additions & 13 deletions rec_radiko.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    cd `dirname $0`

    playerurl=http://radiko.jp/player/swf/player_2.0.1.00.swf
    playerurl=http://radiko.jp/player/swf/player_3.0.0.01.swf
    playerfile=./player.swf
    keyfile=./authkey.png
    suffix=`date '+%Y%m%d'`
    @@ -18,7 +18,7 @@ elif [ $# -eq 3 ]; then
    output=$2
    stop=$3
    else
    echo "usage : $0 channel_name [outputfile]"
    echo "[DEBUG] usage : $0 channel_name [outputfile]"
    exit 1
    fi

    @@ -41,7 +41,7 @@ if [ ! -f $keyfile ]; then
    swfextract -b 5 $playerfile -o $keyfile

    if [ ! -f $keyfile ]; then
    echo "failed get keydata"
    echo "[ERROR] failed get keydata"
    exit 1
    fi
    fi
    @@ -65,7 +65,7 @@ wget -q \
    https://radiko.jp/v2/api/auth1_fms

    if [ $? -ne 0 ]; then
    echo "failed auth1 process"
    echo "[ERROR] failed auth1 process"
    exit 1
    fi

    @@ -78,7 +78,7 @@ 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"
    echo "[DEBUG] authtoken: ${authtoken} \noffset: ${offset} length: ${length} \npartialkey: $partialkey"

    rm -f auth1_fms

    @@ -102,30 +102,31 @@ wget -q \
    https://radiko.jp/v2/api/auth2_fms

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

    echo "authentication success"
    echo "[DEBUG] authentication success"

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

    rm -f auth2_fms

    #
    # rtmpdump
    #
    flv="${output}.flv"
    mp3="/var/www/Music/${output}-${suffix}.mp3"
    rtmpdump -v \
    -B $stop \
    -r "rtmpe://radiko.smartstream.ne.jp" \
    --playpath "simul-stream" \
    --app "${channel}/_defInst_" \
    -r "rtmpe://w-radiko.smartstream.ne.jp" \
    --playpath "simul-stream.stream" \
    --app "${channel}/_definst_" \
    -W $playerurl \
    -C S:"" -C S:"" -C S:"" -C S:$authtoken \
    --live \
    --flv $flv

    ffmpeg -i $flv $mp3
    mp3="/home/kstg/Dropbox/Music/${output}-${suffix}.mp3"
    ffmpeg -i $flv $mp3
    ./upload/env/bin/python ./upload/upload_gmusic.py $mp3
  7. laiso revised this gist May 24, 2012. No changes.
  8. laiso revised this gist May 24, 2012. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion rec_radiko.sh
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,22 @@
    #!/bin/sh

    cd `dirname $0`

    playerurl=http://radiko.jp/player/swf/player_2.0.1.00.swf
    playerfile=./player.swf
    keyfile=./authkey.png
    suffix=`date '+%Y%m%d'`

    if [ $# -eq 1 ]; then
    channel=$1
    output=./$1.flv
    elif [ $# -eq 2 ]; then
    channel=$1
    output=$2
    elif [ $# -eq 3 ]; then
    channel=$1
    output=$2
    stop=$3
    else
    echo "usage : $0 channel_name [outputfile]"
    exit 1
    @@ -109,11 +116,16 @@ rm -f auth2_fms
    #
    # rtmpdump
    #
    flv="${output}.flv"
    mp3="/var/www/Music/${output}-${suffix}.mp3"
    rtmpdump -v \
    -B $stop \
    -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
    --flv $flv

    ffmpeg -i $flv $mp3
  9. @saiten saiten revised this gist Apr 4, 2011. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions rec_radiko.sh
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ if [ ! -f $playerfile ]; then
    fi

    #
    # get keydata (need swftools)
    # get keydata (need swftool)
    #
    if [ ! -f $keyfile ]; then
    swfextract -b 5 $playerfile -o $keyfile
    @@ -65,9 +65,9 @@ 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)'`
    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`

    @@ -101,7 +101,7 @@ fi

    echo "authentication success"

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

    rm -f auth2_fms
  10. @saiten saiten created this gist Mar 18, 2011.
    119 changes: 119 additions & 0 deletions rec_radiko.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,119 @@
    #!/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