# radiko.jp タイムフリー番組をPowerShellスクリプトで録音するツール。 # とりあえず、VBで製作した RadikoPad_cmd のロジックをPowerShellに移植したバージョン。 # 無料会員用のみ。エリアフリーには未対応 # ver.0.1 #copyright 2025 lifewithunix.jp #録音ラジオ番組 #ラジオ局IDをダブルクォーテーションの中に指定。 $station_id="TBS" #録音開始時刻を、ダブルクォーテーション内に、YYYYMMDDhhmm 形式で指定する。秒情報は不要。 $rec_from="202502111500" #録音終了時刻を、ダブルクォーテーション内に、YYYYMMDDhhmm 形式で指定する。秒情報は不要。 $rec_to="202502111510" #$prog_name="${station_id}${rec_from}" $prog_name="${station_id}番組タイトル${rec_from}" # ffmpeg.exe が格納されているフォルダーを指定 $env:Path+=";C:\App" ###################### #以下は編集しない事 ###################### # CURL.exe オプション定義 #$curl="C:\Windows\System32\curl.exe" $cookie="-c cookie.txt" $method="POST" $url1="https://radiko.jp/v4/api/member/login" # radiko.jp AUTH Key $authkey="bcd151073c03b352e1ef2fd66c32209da9ca0afa" $resp1_status="" $radiko_session="null" $areafree="0" # Auth1 $auth1_resp = curl.exe -s -c cookie.txt ` -H "X-Radiko-App: pc_html5" ` -H "X-Radiko-App-Version: 0.0.1" ` -H "X-Radiko-User: dummy_user" ` -H "X-Radiko-Device: pc" ` -I -L https://radiko.jp/v2/api/auth1 #$auth1_resp $authtoken="" $keylength="" $keyoffset="" foreach ($auth1_var in $auth1_resp){ $auth_var_a = ($auth1_var.Split(" ")[0]).tolower().replace(":","") $auth_var_b = $auth1_var.Split(" ")[1] if ($auth_var_a -eq "x-radiko-authtoken"){ $authtoken = $auth_var_b} if ($auth_var_a -eq "x-radiko-keylength"){ $keylength = $auth_var_b} if ($auth_var_a -eq "x-radiko-keyoffset"){ $keyoffset = $auth_var_b} } $authkey_cut=($authkey.Substring($keyoffset,$keylength)) $part_key=[Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($authkey_cut)) # Auth2 $auth2_resp = curl.exe -s -c cookie.txt ` -H "X-Radiko-AuthToken: $authtoken" ` -H "X-Radiko-PartialKey: $part_key" ` -H "X-Radiko-User: dummy_user" ` -H "X-Radiko-Device: pc" ` -L https://radiko.jp/v2/api/auth2 # ffmpeg download # for none areafree users if ($areafree -eq "1"){ }else{ # ffmpeg.exe コマンドの存在PATHを直接指定すること。 ffmpeg.exe ` -fflags +discardcorrupt ` -headers "X-Radiko-AuthToken: $authtoken" ` -i "https://radiko.jp/v2/api/ts/playlist.m3u8?station_id=${station_id}&l=15&ft=${rec_from}00&to=${rec_to}00" ` -acodec copy ` -vn ` -bsf:a aac_adtstoasc ` -y ` "${prog_name}.m4a" } # logout # Debug echo "resp1_status: ${resp1_status}" echo "radiko_session: ${radiko_session}" echo "areafree: ${areafree}" echo "--" echo "authkey: ${authtoken}" echo "keyoffset: ${keyoffset}" echo "keylength: ${keylength}" echo "--" $authkey $authkey_cut $part_key #$resp1_1