VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors.
Please consider supporting us by disabling your ad blocker or buy PlayOn and record Netflix! :)
+ Reply to Thread
Results 1 to 2 of 2
  1. Hello,

    Can someone please help me with building the batch script?

    I'm trying to create a batch process for my video files, i have mkv files with embedded subtitle and i want to extract a specific language subtitle to srt file and remove all subtitles within that mkv file, i also want to preserve the creation/modified date of the file.

    Here are the steps for my need:
    - Search within a folder with sub-folders all the mkv files
    - Check every mkv file for subtitles
    - If subtitles exists, search for Hebrew Subtitles
    - If Hebrew subtitles exists, than extract it to .srt file
    - When the subtitle been extract, mux the mkv file to remove all embedded subtitles from that mkv file
    - Remove old file
    - Rename new file with the original name
    - Preserve creation/modified date of the file

    i've searched the forum and found a script that i can use, so i tried to modify it for my purpose but unfortunately i'm getting a lot of errors and i don't have the knowledge to fix it.

    this is my modified script:
    REM // =======================
    REM || Batch Subtitle Muxing
    REM ||       for MKVmerge
    REM || v0.4-20150511 by drudge
    REM \\ =======================
    REM @@ This batch script will scan the provided directory (or current folder)
    REM @@ for video files, attempt to match them with subtitle files,
    REM @@ and mux them using the MKVmerge command line.
    REM     // ---- ---- ---- ----
    REM // full path to mkvmerge.exe
    REM     SET muxpath=C:\Program Files\MKVToolNix\mkvmerge.exe
    REM // full path to mkvmerge.exe
    REM     SET extractpath=C:\Program Files\MKVToolNix\mkvextract.exe
    REM \\ -- -- -- -- --
    REM // full path to unrar program, make sure to include switches
    REM     SET rarpath=C:\Program Files\7-Zip\7z.exe
    REM     SET rarcmd=e
    REM \\ -- -- -- -- --
    REM // output path (with trailing slash)
    REM ++ leave blank for working directory
            SET outputdir=
    REM @@ default: SET "outputdir="
    REM \\ -- -- -- -- --
    REM // prepend text to output filename
    REM ++ REQUIRED if outputdir is left blank
            SET filesuffix=-new
    REM @@ blank: SET "filesuffix="
    REM \\ -- -- -- -- --
    REM \\ ---- ---- ---- ----
    REM -- editing below this line should be done precisely. (here thar be dragons)
    REM ===========================================================================
    REM @@ simple counters
    SET /A "mc=0"
    SET /A "me=0"
    REM @@ default working path
    SET wp=
    REM @@ optional working path via argument
    IF EXIST "%~1" SET wp=%~1
    REM @@ ready steady go!
    ECHO ===========================================================================
    REM @@ attempt to use custom setting for output path
    IF EXIST "%outputdir%" (
            REM @@ user has provided output path
            ECHO == User Setting -- Output to: [%outputdir%]
    ) ELSE (
            REM @@ no custom setting, check for suffix
            IF [%filesuffix%]==[] (
                    ECHO @@ ERROR: empty [filesuffix] setting requires [outputdir] to be set
                    SET /A me+=1
            REM @@ use working path for output
            SET outputdir=%wp%
    FOR /r %%H IN ("%wp%") DO (
            REM @@ because "." doesn't tell us where we are
            ECHO == Scanning [%%~dpfH\] for video files...
    FOR /r %%I IN ("%wp%*.mkv") DO (
            REM @@ found a video file, now check for subtitles
            CALL:SUBSEARCH "%%~I"
    FOR /f %%A in (' mkvmerge -i "%~dpnx1" ^| FIND /c /i "subtitles" ') DO (
        IF %%A==0 (
                ECHO @@ ERROR: "%~nx1" has no subtitles
        ELSE (
            ECHO "%~nx1" has subtitles, searching for Hebrew subtitles.
            FOR %%B in (' mkvmerge -F verbose-text -i "%~dpnx1" ^| FINDSTR /i /r /c:"subtitles.*heb" ') DO (
                IF %ERRORLEVEL% EQU 0 (
                        SET substring=mkvmerge -F verbose-text -i "%~dpnx1" ^| FINDSTR /i /r /c:"subtitles.*heb"
                        CALL SET track=%substring:~9,1%
                        ECHO HEBREW Track ID: %track%
                        CALL SET line= %track%:""
                        CALL :SUBEXTRACT
                 ) ELSE (
                        ECHO %~nx1 do not have Hebrew subtitles.
                        CALL :MUXIT
    setlocal enabledelayedexpansion
    mkvextract --ui-language en tracks "%~dpn1.mkv" !line! ||(ECHO Demuxing error!&GOTO:eof)
    REM @@ we've made it!
    SET /A mc+=1
    REM @@ now we let mkvmerge work its magic
    ECHO | SET /p muxdone="++ Muxing: (%mc%) [%~n1%~x1]"
    mkvmerge -o "%outputdir%%~n1%filesuffix%%~x1" --no-subtitles --language 0:eng --default-track 0:yes --language 1:eng --default-track 1:yes "%~1" --track-order 0:0,0:1
    ECHO  ..complete
    REM @@ success!
    REM @@ remove old file
    ECHO removing old file...
    IF EXIST "%outputdir%%~n1%filesuffix%%~x1" if NOT ERRORLEVEL 1 (
              DEL "%~f1"
              REN "%outputdir%%~n1%filesuffix%%~x1" "%%~nx"
    ECHO == Finished Processing: %mc% completed / %me% errors
    ECHO ===========================================================================
    REM @@ game over, man
    This is my folders structure:

    ├─Movie_abc [...]
    │ ├─Movie_abc.mkv

    ├─Movie_def [...]
    │ ├─Movie_def.mkv

    ├─Movie_ghi [...]
    │ ├─Movie_ghi.mkv

    TV Shows
    ├─Series _abc [...]
    │ ├─Season 1
    │ ├─ Episode_abc.mkv
    │ ├─ Episode_def.mkv

    ├─Series _def [...]
    │ ├─Season 1
    │ ├─ Episode_abc.mkv
    │ ├─ Episode_def.mkv

    ├─Series _ghi [...]
    │ ├─Season 1
    │ ├─ Episode_abc.mkv
    │ ├─ Episode_def.mkv

    Thank in advanced for anyone that can help me.
    Last edited by BuSHari; 12th Oct 2017 at 12:19.
    Quote Quote  
  2. I always get the error:
    'ELSE' is not recognized as an internal or external command,
    operable program or batch file.
    i can't figure what is the problem with the ELSE
    Quote Quote  

Similar Threads