ANNi録音

田所あずさと天津向のどうせワレワレなんて・・・を録音しようと思って
batファイルを書いたので備忘録として。

実行日の日付から第何回かを計算し
サイトから説明をtxtとして、サムネイルをjpgにして保存
録音はyoutube-dlを使っています。

Invoke-WebRequestが余りにも遅いので代替案を探しています。

2017.10.19 descriptionに改行があったとき<br />を誤判定するので無理矢理無視するように。改行2個までを想定。汎用的なの思いつかなかった。。。


@REM UTF-8
@chcp 65001
@echo off
rem 第一回放送の日付を設定
set first=2017/09/07
rem 第何回放送かを計算
echo WScript.Echo DateDiff("y","%first%","%date%",5) > tmp.vbs
for /f "usebackq tokens=*" %%i IN (`call cscript //nologo tmp.vbs`) DO @set num=%%i
set /a result=%num%/7+1
rem 三桁に0埋め
set result=000%result%
set result=e_anni_douse_%result:~-3%
rem 後処理
del tmp.vbs

rem 録画済みかのチェック
if exist %result%.m4a (
	echo 録画済み
	exit
) else (
	echo %result%を取得します。

	rem HTTPをダウンロード
	powershell -NoProfile -ExecutionPolicy Unrestricted -Command "& { wget -Uri https://i.allnightnippon.com/p/%result% -OutFile tmp.html }"

	rem 該当行を抽出し合成
	type nul>%result%.txt
	find "ttl_movie_line" <tmp.html>tmp1.txt
	find "txt_movie"      <tmp.html>tmp2.txt
	
	rem htmlタグを削除
	for /f "tokens=3     delims=<>" %%a in (tmp1.txt) do @echo%%a>>%result%.txt
	for /f "tokens=3,5,7 delims=<>" %%b in (tmp2.txt) do (
		@echo/%%b>>%result%.txt
		@echo/%%c>>%result%.txt
		@echo/%%d>>%result%.txt
	)

	rem 画像を取得
	find "mp3Image.src" <tmp.html>tmp3.txt
	for /f "tokens=2 delims='" %%c in (tmp3.txt) do (
		powershell -NoProfile -ExecutionPolicy Unrestricted -Command "& { wget -Uri https://i.allnightnippon.com%%c -OutFile %result%.jpg }"
	)

	rem 後処理
	del tmp*.txt
	del tmp.html
	echo txtとjpgを取得しました。

	rem 音声ダウンロード
	..\youtube-dl -o "%%(id)s.%%(ext)s" --hls-prefer-native -x https://i.allnightnippon.com/p/%result%
)

rem pause