@echo off
rem BDAVtH_ԑgIčĐB 2025/3/24쐬

rem ȉ̃R}hɃpXʂĂB
rem bdavinfo.exe
rem busybox64.exe
rem nkf.exe

for /f "usebackq delims=" %%I in (`powershell -Command "(new-object -COM 'Shell.Application').BrowseForFolder(0,'Blu-raytH_[Iĉ', 0, 0).Self.Path"`) do set folder=%%I

if "%folder%" == "" goto fin

for /f "usebackq delims=" %%I in (`where /r "%folder%" info.bdav ^| busybox64 head -n 1`) do (
  bdavinfo "%%I" "%TEMP%\_temp_1.txt" -T -jdpb
  set stream_path=%%~dpISTREAM\
)

nkf -s < "%TEMP%\_temp_1.txt" | busybox sed -r -e "s/^0+/echo /" -e "s/\.m2ts\t/\t/" | busybox unix2dos > "%TEMP%\_temp_2.txt"
del "%TEMP%\_temp_1.txt"

echo @echo off> "%TEMP%\_temp_.bat"
echo cls>> "%TEMP%\_temp_.bat"
echo echo ԍ	^N	^撷		ԑg>> "%TEMP%\_temp_.bat"
type "%TEMP%\_temp_2.txt" >> "%TEMP%\_temp_.bat"
del "%TEMP%\_temp_2.txt"
echo echo.>> "%TEMP%\_temp_.bat"
echo set /p n=ԂĐ܂H >> "%TEMP%\_temp_.bat"
echo if exist "%stream_path%0000%%n%%.m2ts" (>> "%TEMP%\_temp_.bat"
echo   start "" "%stream_path%0000%%n%%.m2ts">> "%TEMP%\_temp_.bat"
echo ) else if exist "%stream_path%000%%n%%.m2ts" (>> "%TEMP%\_temp_.bat"
echo   start "" "%stream_path%000%%n%%.m2ts">> "%TEMP%\_temp_.bat"
echo ) else (>> "%TEMP%\_temp_.bat"
echo   start "" "%stream_path%00%%n%%.m2ts">> "%TEMP%\_temp_.bat"
echo )>> "%TEMP%\_temp_.bat"
echo del "%TEMP%\_temp_.bat">> "%TEMP%\_temp_.bat"

"%TEMP%\_temp_.bat"
