This script uses Filebot to search for missing subtitles by hash in the given language(s) and
saves the file with ISO 639-2/B language code(s).
This is handy for Plex users for instance, since Plex doesn't support ISO 639-3 codes.
If multiple languages are required add them as a comma-separated list (without spaces!) eg. nl,en,fr,de
Prerequisites:
- Sonarr - TV Series Manager (https://sonarr.tv/)
- Filebot (Of course
)
- Filebot added to your system's PATH (Environment Variable) setting
- On Windows systems run Sonarr as an application! NOT as a Windows Service! Sonarr as a Windows service doesn't execute custom scripts.
- An Opensubtitles.org account to login to Opensubtitles in Filebot
Installation/Setup:
- Install Sonarr
- Install Filebot.
- Copy sonarr-subber.groovy to your preferred location on your harddrive
- In Sonarr navigate to Sonarr -> Settings -> Connect -> [+] -> Custom Script
- In the Pop-up enter the following:
- Name: Enter a descriptive name to your liking eg. Sonarr Subtitle Downloader
- On Grab: No
- On Download: Yes
- On Upgrade: Yes
- On Rename: No
- Filter Series Tags: Use at your own discretion
- Path: Full path to Filebot. (On Windows systems: C:\Program Files\FileBot\filebot.exe)
- Arguments: -script "FULL-PATH-TO\sonarr-subber.groovy" --lang [2-letter ISO 639-1 language code(s)]
- Click on the Test button.
- If the test succeeded click on the Save button.
Sonarr Custom Script Arguments Examples:
In these examples it's assumed you copied sonarr-subber.groovy to C:\MyScripts\ on a Windows system.
Search for Dutch subtitles:
Code: Select all
-script "C:\MyScripts\sonarr-subber.groovy" --lang nl
Code: Select all
-script "C:\MyScripts\sonarr-subber.groovy" --lang nl,en,fr
The Script:
Code: Select all
// select input language(s)
def languages = _args.lang.split(/\W/) as List
// select input video
def env = System.getenv()
def episodeFile = env['sonarr_episodefile_path'] as String
// fetch subtitles
def subtitleFiles = languages.findResults{
getSubtitles(lang: it, file: episodeFile, output: 'srt', encoding: 'UTF-8')
}.flatten()
// rename subtitles
rename(map: subtitleFiles.collectEntries{
[it, getMediaInfo(it, '{fn[0..-5]}.{lang.ISO3B}.{ext}')]
})