OK, give this version a try. I added logic so you can specific what part of the pattern to use for the subtitles track name. For example, the pattern for your forced tracks is now, "{LNG}.<forced>". So, it will look for a file called "NAME.en.forced.srt" and set it's track name to "forced". I did the same for "cc".
The track language is now set based on the language being processed.
Code:
@:: batch file to convert mp4 files to mkv
@echo off
setlocal EnableExtensions EnableDelayedExpansion
:: languages
set "langs=en eng"
:: subtitles file patterns
:: use "{LNG}" for the language code
:: use '<' and '>' to bracket the section to use for the track name
set "subpats={LNG}.<forced> {LNG} {LNG}-us {LNG}.<cc> {LNG}-us.<cc>"
:: separator (characters between title and subtitles pattern
set "subsep=."
:: location of mvkmerge
set "mkvmerge=C:\Program Files\MKVToolNix\mkvmerge.exe"
:: output subdirectory
set "outdir=Anystream\mkv"
:: escapes brackets in subpats for proper processing
set "subpats=%subpats:<=^<%"
set "subpats=%subpats:>=^>%"
:: if there are no arguments, process the directory containing the script
if "%~1" == "" (
call :DIR "%~dp0"
goto :DONE
)
:: iterator through command line arguments
:CMDS
set "curr=%~1"
if "%curr%" == "" goto :DONE
:: ensure current arg exists
if not exist "%curr%" goto :EOF
:: determine if current arg is a dir or a file
pushd "%curr%" >NUL 2>&1
if ERRORLEVEL 1 (
call :FILE "%curr%"
) else (
call :DIR "%curr%"
)
shift
goto :CMDS
:DIR
echo recursing %1...
for /r %%i in ("*.mp4") do call :FILE "%%~i"
popd
goto :EOF
:FILE
:: ignore non-mp4 files
if /i "%~x1" NEQ ".mp4" goto :EOF
echo processing %1
pushd "%~dp1"
mkdir "%outdir%" >NUL 2>&1
:: process subtitles
set subs=
for %%L in (%langs%) do (
for %%P in (%subpats%) do (
set opts=
:: substitute current language into pattern
set pat=%%P
set "pat=!pat:{LNG}=%%L!"
:: remove brackets for file name
set "file=!pat:<=!"
set "file=!file:>=!"
set "file=%~n1%subsep%!file!.srt"
:: remove text around brackets (inclusive) for track name
set "track="
echo "!pat!" | find "<" > NUL 2>&1
if not ERRORLEVEL 1 (
set "track=!pat:*<=!"
set "track2=!track:*>=!"
call set "track=%%track:>!track2!=%%"
)
:: if file exist, process it
if exist "!file!" (
echo found subtitles file: "!file!"
:: check for "forced" in subtitle file name
echo !file! | find /i "forced" > NUL 2>&1
if ERRORLEVEL 1 (
set "opts=!opt! --language 0:%%L --default-track 0:0 --forced-track 0:0 --track-name ^"0:!track!^""
) else (
set "opts=!opt! --language 0:%%L --default-track 0:1 --forced-track 0:1 --track-name ^"0:!track!^""
)
:: add new subtitles file to list
set "subs=!subs! !opts! ^"!file!^""
)
)
)
echo calling "%mkvmerge%" --default-language en -o "%outdir%\%~n1.mkv" "%~nx1" %subs%
"%mkvmerge%" --default-language en -o "%outdir%\%~n1.mkv" "%~nx1" %subs%
popd
goto :EOF
:DONE
echo Done.
pause