License:
This script is free for everyone to use or edit. Just don't sell it

Requirements:
- Windows operating system (for now)
- sub-merge-mkv-groovy.bat (included in zip file)
- sub-merge-mkv.groovy (included in zip file, fully commented)
- MKVToolnix (Jean Claude Van Damme at https://www.bunkus.org/videotools/mkvtoolnix/)
- Both Filebot and MKVToolnix need to be added to the system environment PATH variable
- Download sub-merge-mkv-groovy.zip
- Unzip to a folder of your liking
- Either run sub-merge-mkv-groovy.bat
- Or run in CMD/CLI
Code: Select all
filebot -script /path/to/sub-merge-mkv.groovy /path/to/files
- When sub-merge-mkv-groovy.bat is executed it asks for the folder to be scanned
- The script then recursively scans the given folder for MKV video files
- For every MKV video file it finds:
- it scans the file for existing Dutch subtitles using MKVToolnix (MKVmerge.exe)
- if MKVToolnix detects Dutch subtitles, it moves on to the next MKV video file
- if MKVToolnix doesn't detect Dutch subtitles, Filebot searches for subtitles (filetype SubRip/SRT, encoding UTF8, strict mode)
- if Filebot doesn't find Dutch subtitles, it moves on to the next MKV video file
- if Filebot finds Dutch subtitles, MKVToolnix merges/remuxes them into the MKV video file and deletes the original SRT file
This script can easily be adapted to suit other languages.
You need to edit the following lines in the fully commented version of sub-merge-mkv.groovy:
On line 24 change:
Code: Select all
def regex = ~/subtitles.*language:dut/
Code: Select all
def regex = ~/subtitles.*language:eng/
Code: Select all
lang:'nl'
Code: Select all
lang:'en'
Code: Select all
'.nld.srt'
Code: Select all
'.eng.srt'
Code: Select all
"0:dut"
Code: Select all
"0:eng"
Disclaimer:
- This script has only been tested an run on Windows (8.1). I have no idea whether this will work on other platforms. I'm sure with a little tweaking it will.
- Use this script at your own peril. I'll take no responsibility for any loss of data or any damage. I suggest running it a couple of times on a test folder first.
Code: Select all
@ECHO OFF
SET /p mediafolder=Enter The folder path to scan:%=%
ECHO the folder path is: %mediafolder%
ECHO.
filebot -script "sub-merge-mkv.groovy" %mediafolder%
PAUSE
Code: Select all
// filebot -script "path\to\sub-mkv.groovy" <folder>
subsskipped = 0
subsfound = 0
subsmerged = 0
subsnotfound = 0
subsnotmerged = 0
args.getFiles().findAll { getMediaInfo(file:it, format:'{ext}')=='mkv' }.each {
def filepath = it.toString()
def mkvinfo = ["mkvmerge", "-I", it]
def proc = mkvinfo.execute()
proc.waitFor()
def exitcode = "${proc.exitValue()}".toInteger()
def procOutput = "${proc.in.text}"
def regex = ~/subtitles.*language:dut/
if ( exitcode == 0 ) {
if ( regex.matcher(procOutput ).getCount() == 0) {
if ( getSubtitles( file:it, lang:'nl', output:'srt', encoding:'utf8', strict:'true' ).size() > 0 ) {
subsfound++
def srtfile = new File ( filepath.replaceFirst('.mkv', '.nld.srt') )
def outputfile = new File ( filepath.replaceFirst('.mkv', '.merging.mkv') )
def mkvtitle = filepath.tokenize('\\').last().replaceFirst('.mkv', '')
def mkvmerge = ["mkvmerge", "-o", outputfile, "-S", it, "--language", "0:dut", "--title", mkvtitle, srtfile]
proc = mkvmerge.execute()
proc.waitFor()
exitcode = "${proc.exitValue()}".toInteger()
if ( exitcode == 0 ) {
subsmerged++
it.delete()
srtfile.delete()
new File ( outputfile.toString() ).renameTo ( new File ( it.toString() ) )
} else {
subsnotmerged++
}
} else {
subsnotfound++
}
} else {
subsskipped++
}
}
}
println "\nResults: skipped: " + subsskipped + ", not found: " + subsnotfound + ", found: " + subsfound + ", merged: " + subsmerged + ", not merged: " + subsnotmerged + "\n"