Advertisement
Zignature

Sonarr AutoSubber v3

May 28th, 2016
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 2.88 KB | None | 0 0
  1. /*******************************************************************************************************
  2. [Sonarr AutoSubber v3] by Zignature & rednoah
  3.  
  4. Scripting by rednoah
  5. The creator of Filebot - The ultimate tv renamer / subtitle downloader / sfv validator
  6. https://github.com/rednoah
  7. http://www.filebot.net/
  8.  
  9. Concept & idea and tiny modifications by Zignature
  10.  
  11. DESCRIPTION:
  12. Custom script for Sonarr for automated multilingual subtitle downloading.
  13. This script uses Filebot to search for missing subtitles by hash in the given language(s) and
  14. saves the file with ISO 639-2/B language code(s).
  15. This is handy for Plex users for instance, since Plex doesn't support ISO 639-3 codes.
  16.  
  17. If multiple languages are required add them as a comma-separated list (without spaces!) eg. nl,en,fr,de
  18.  
  19. PREREQUISITES:
  20. - Filebot
  21. - Filebot added to your system's PATH (Environment Variable) setting
  22. - If you run Sonarr as a Windows service, DO NOT run it under the Local System Account. Sonarr as a Windows service under the Local System Account doesn't execute custom scripts. Run it as a user. Or you can run Sonarr as an application!
  23. - An Opensubtitles.org account to login to Opensubtitles in Filebot
  24.  
  25. INSTALLATION/SETUP:
  26. - Install Filebot. You can get it for free at https://www.filebot.net/. Donations are appreciated :)
  27. - Copy sonarr-subber.groovy to your preferred location on your harddrive
  28. - In Sonarr navigate to Sonarr -> Settings -> Connect -> [+] -> Custom Script
  29. - In the Pop-up enter the following:
  30.     Name: Enter a descriptive name to your liking eg. Sonarr Subtitle Downloader
  31.     On Grab: No
  32.     On Download: Yes
  33.     On Upgrade: Yes
  34.     On Rename: No
  35.     Filter Series Tags: Use at your own discretion
  36.     Path: Full path to Filebot. (On Windows systems: C:\Program Files\FileBot\filebot.exe)
  37.     Arguments: -script "FULL-PATH-TO\sonarr-subber.groovy" --lang [2-letter ISO 639-1 language code(s)]
  38. - Click on the Test button.
  39. - If the test succeeded click on the Save button.
  40.  
  41. This script also runs after manual imports.
  42.  
  43. ARGUMENTS EXAMPLES:
  44. In these examples it's assumed you copied sonarr-subber.groovy to C:\MyScripts\ on a Windows system.
  45.  
  46. Search for Dutch subtitles:
  47. -script "C:\MyScripts\sonarr-subber.groovy" --lang nl
  48.  
  49. Search for Dutch, English and French subtitles:
  50. -script "C:\MyScripts\sonarr-subber.groovy" --lang nl,en,fr
  51. *******************************************************************************************************/
  52.  
  53. // select input language(s)
  54. def languages = _args.lang.split(/\W/) as List
  55.  
  56. // select input video
  57. def env = System.getenv()
  58. def episodeFile = env['sonarr_episodefile_path'] as String
  59.  
  60. // fetch subtitles
  61. def subtitleFiles = languages.findResults{
  62.     getSubtitles(lang: it, file: episodeFile, output: 'srt', encoding: 'UTF-8')
  63. }.flatten()
  64.  
  65. // rename subtitles
  66. rename(map: subtitleFiles.collectEntries{
  67.     [it, getMediaInfo(it, '{fn[0..-5]}.{lang.ISO3B}.{ext}')]
  68. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement