Post by AlleyCatHello all. I think this will be simple for you batch and script gurus, but
it's driving me crazy.
Videofile: House.S08E18.Body And Soul.mkv
Subtitle: House.S08E18.HDTV.XviD-LOL.srt
If you please... copy text after third period (or whatever will be before
the extension in other cases) of videofile and copy it to the srt file, so
both files are identical other than the extension.
Sample: House.S08E18.Body And Soul.mkv
House.S08E18.Body And Soul.srt
Not all vid files are in this "format", but I'll work on it from there.
Thank you so very much.
It's pretty complicated considering the format can be anything. Try below
code. Use code from the pastebin link if your news client always split long
lines.
<http://pastebin.com/4Ajrgiak>
The code relies heavily on the well known episode numbering format "SxxEyy".
It must be in the proper numbers. e.g. no season/episode zero. It assumes
that the text before that is the video title. It'll use both as a prefix
with period or a space separator based file naming. Text after the episode
are ignored. If two or more video files matched, only the first one is used.
e.g. for these files:
House S08E18 Body And Soul.mkv
House.S08E18.HDTV.XviD-LOL.srt
House.S08E18.Body And Soul.H264-LMAO.mkv
House.S08E18.HDTV.XviD-LOL.srt
The srt will be renamed as:
House S08E18 Body And Soul.srt
The actual REN command in the batch file is disabled. It simply show the REN
command line that should be executed.
@echo off
setlocal enabledelayedexpansion
pushd
if "%~1" == "" (
echo Usage: SyncSrtFileNames {folder}
goto :eof
)
cd /d "%~1"
if not errorlevel 0 (
echo Path is not accessible.
goto :eof
)
for %%A in (*.srt) do (
set fname=%%A
set fext=%%~xA
set processed=0
for /f "tokens=1-30 delims=." %%B in ("%%A") do (
call :getprefix "%%B" "%%C" "%%D" "%%E" "%%F" "%%G" "%%H" "%%I" "%%J"
"%%K" "%%L" "%%M" "%%N" "%%O" "%%P" "%%Q" "%%R" "%%S" "%%T" "%%U" "%%V"
"%%W" "%%X" "%%Y" "%%Z" "%%[" "%%\" "%%]" "%%^^" "%%_"
)
if !processed! == 0 (
for /f "tokens=1-30 delims= " %%B in ("%%A") do (
call :getprefix "%%B" "%%C" "%%D" "%%E" "%%F" "%%G" "%%H" "%%I" "%%J"
"%%K" "%%L" "%%M" "%%N" "%%O" "%%P" "%%Q" "%%R" "%%S" "%%T" "%%U" "%%V"
"%%W" "%%X" "%%Y" "%%Z" "%%[" "%%\" "%%]" "%%^^" "%%_"
)
)
)
goto :eof
:getprefix
set eps=
set prefix=
set separator=.
call :gploop %*
set eps=
set prefix=
set "separator= "
call :gploop %*
goto :eof
:gploop
if "%~1" == "" goto :eof
set ch=%~1
call :chkeps %ch:~0,1% %ch:~1,1% %ch:~2,1% %ch:~3,1% %ch:~4,1% %ch:~5,1%
%ch:~6,1%
if "%prefix%" == "" (
set prefix=%~1
) else (
set prefix=%prefix%%separator%%~1
)
if not "%eps%" == "" (
if not "%prefix%" == "" (
for %%B in ("%prefix%*") do (
if !processed! == 0 if not "%%~B" == "%fname%" (
echo dummy: ren "%fname%" "%%~nB%!fext!"
set processed=1
)
)
)
goto :eof
)
shift
goto :gploop
:chkeps
if not "%7" == "" goto :eof
if /i not "%1" == "s" goto :eof
set /a num=(%2*10)+%3
if !num! == 0 goto :eof
if /i not "%4" == "e" goto :eof
set /a num=(%5*10)+%6
if !num! == 0 goto :eof
set eps=%ch%