Everytime a video is downloaded the scipt is supposed to download the correct Dutch subtitle.
I already got something going, but it seems the script is checking all files in the directory instead of the specific video file.
I also can't seem to figure out how to pass a language code to the script....
The batch file called by Sonarr:
Code: Select all
@ECHO OFF
@setlocal EnableDelayedExpansion
:: [Sonarr AutoSubber] by Zignature
:: NOTES:
:: Filebot.exe needs to be in your system's PATH (Environment Variable) setting!!!
:: Sonarr needs to run as an application. NOT as a Windows service!
:: Invoke Filebot to search for subtitle by hash (strict mode).
START "Searching subtitle..." /WAIT filebot -script "E:\Scripts\sonarr-autosubber.groovy" "%sonarr_episodefile_path%"
Code: Select all
// filebot -script "sonarr-autosubber.groovy" "<path\to\file]>"
args.getFiles().findAll {
getSubtitles(file:it, lang:'nl', output:'srt', encoding:'utf8', strict:'true')
}.each {
// Define the full path
def filePath = it.toString();
// Define the starting point of the full filename
def fileNameIdx = filePath.lastIndexOf('\\') + 1
// Define the full path to the current directory
def parentPath = filePath[0..fileNameIdx-1]
// The filename without the dot and the extension
def fileName = filePath.substring(fileNameIdx,filePath.length()-4)
// Define the source subtitle file
def src_srt = new File(parentPath.toString() + fileName.toString() + ".nld.srt")
// Define the destination subtitle file
def dst_srt = new File(parentPath.toString() + fileName.toString() + ".nl.srt")
// Check whether a subtitle was downloaded and then rename.
if(src_srt.exists()) {
// Check whether the subtitle was already renamed.
if(!dst_srt.exists()) {
// Create new subtitle file with "nl" language code
dst_srt.write("")
// Copy the contents from the source subtitle file
dst_srt << src_srt.text
// Delete source subtitle file
src_srt.delete()
}
}
}
