Subtitles with Subliminal for Sickbeard on QNAP

* UPDATED to subliminal 0.8.0-dev (22-06-2014) *
* UPDATED to subliminal 2.0.5 (28-09-2018) *

A short write-up on how to automate the download of subtitles for every new episode that Sickbeard is queueing with SABNZBD.

First of all, for this to work, I assume you already have:

  • Obviously a QNAP
  • qpkg installed for Sickbeard and SABNZBD

As Subliminal is not part of the qpkg tree we need to first get, compile and install it. This is done by using the ipkg tree and installing additional tools.

1. Install the OPTWARE qpkg. In the QNAP adminstration interface -> Applications -> QPKG Center

2. Connect to the QNAP via SSH and update and upgrade the ipkg tree by using the following commands:

ipkg update
ipkg upgrade
 

3. Make sure you have the most recent versions of git, python tools and textutils installed, if not, run the following commands:

ipkg install python27
ipkg install py27-setuptools
ipkg install git
ipkg install textutils
 

4. Fetch and install the Subliminal package:

git clone -b master https://github.com/Diaoul/subliminal.git /tmp/subliminal
cd /tmp/subliminal
/opt/bin/python2.7 setup.py install
 

5.  Now, using your favo editor (I use vim), you have to create the following file “subtitles.sh”. This will fetch the Dutch subtitle and if this is not available the secondary language is English.

UPDATE: When you update from version 0.6 to 0.8 like I just did the original script doesn’t work anymore due to a syntax change, make sure you remove/add the bits in red below.

vim subtitles.sh
 
#!/bin/sh
echo Filename to process. $1
echo Original filename... $2
echo Show TVDB id........ $3
echo Season number....... $4
echo Episode number...... $5
echo Episode air date.... $6
echo ... pass the episode info to Subliminal and fetch the subtitle
/opt/local/bin/subliminal --cache-dir /share/MD1_DATA/subliminal -l nl -l en -- "$1"

As you can see my cache dir is placed on the MD1_DATA volume. If you only have one set of disks in a volume this will probably be MD0_DATA.

Subliminal uses a cache file out-of-the-box, instead of a defined cache directory, which is located at /root/.cache/subliminal/cli.dbm

6. Integration with Sickbeard is done by editing the config.ini and adding this script to the post processing part.

First copy the script to the Sickbeard scripts location (again, in my case this is on MD1_DATA)

cp subtitles.sh /share/MD1_DATA/.qpkg/SickBeard/AutoProcessTV/
 

Now SHUTDOWN Sickbeard otherwise the changes to the running config will NOT be applied!

vim /share/MD1_DATA/.qpkg/SickBeard/config.ini
 

Find the line that says:

extra_scripts = ""

and change it into:

extra_scripts = "/share/MD1_DATA/.qpkg/SickBeard/AutoProcessTV/subtitles.sh"

Save the file and start Sickbeard. Well that’s it, if you queue an episode Sickbeard will automagically find and download the correct subtitle, rename it according to the episode and move it to the correct folder as well.

The following bit shows the entire process in the logging for an episode of Modern Family, down the bottom you see subtitles.sh script in action:

Loading config from /share/MD1_DATA/.qpkg/SickBeard/autoProcessTV/autoProcessTV.cfg
Opening URL: http://localhost:7071/home/postprocess/processEpisode?nzbName=Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD.nzb&quiet=1&dir=%2Fshare%2FMD1_DATA%2FDownload%2Fsabnzbd%2Fcomplete%2FTV%2FModern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD
Processing folder /share/MD1_DATA/Download/sabnzbd/complete/TV/Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD

Processing /share/MD1_DATA/Download/sabnzbd/complete/TV/Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD/Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD.mkv (Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD.nzb)

Found result in history: (95011, 4, [])

Parsed Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD.nzb into Modern Family - S4E9 - 720p.WEB-DL.DD5.1.H.264 (HWD) [ABD: False]

Checking scene exceptions for a match on Modern Family

Looking up Modern Family in the DB

Lookup successful, using tvdb id 95011

Loading show object for tvdb_id 95011

Retrieving episode object for 4x9

The old status had a quality in it, using that: 720p WEB-DL

SB snatched this episode so I'm marking it as priority

Is ep a priority download: True

File /share/MD1_DATA/Multimedia/Seriezz/Modern Family/Season 04/Modern Family - 4x09 - When a Tree Falls.mkv doesn't exist so there's no worries about replacing it

This download is marked a priority download so I'm going to replace an existing file if I find one

Deleting file /share/MD1_DATA/Multimedia/Seriezz/Modern Family/Season 04/Modern Family - 4x09 - When a Tree Falls.mkv

Found release name Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD

Destination folder for this episode: /share/MD1_DATA/Multimedia/Seriezz/Modern Family/Season 04

Moving file from /share/MD1_DATA/Download/sabnzbd/complete/TV/Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD/Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD.mkv to /share/MD1_DATA/Multimedia/Seriezz/Modern Family/Season 04/Modern Family - 4x09 - When a Tree Falls.mkv

Executing command ['/share/MD1_DATA/.qpkg/SickBeard/autoProcessTV/findsubs.sh', u'/share/MD1_DATA/Multimedia/Seriezz/Modern Family/Season 04/Modern Family - 4x09 - When a Tree Falls.mkv', u'/share/MD1_DATA/Download/sabnzbd/complete/TV/Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD/Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD.mkv', '95011', '4', '9', '2012-11-28']

Absolute path to script: /share/MD1_DATA/.qpkg/SickBeard/autoProcessTV/subtitles.sh

Script result: Filename to process. /share/MD1_DATA/Multimedia/Seriezz/Modern Family/Season 04/Modern Family - 4x09 - When a Tree Falls.mkv

Original filename... /share/MD1_DATA/Download/sabnzbd/complete/TV/Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD/Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD.mkv

Show TVDB id........ 95011

Season number....... 4

Episode number...... 9

Episode air date.... 2012-11-28

... pass the episode info to Subliminal and fetch the subtitle

WARNING: root Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.

WARNING: root Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER.

**************************************************

Downloaded 1 subtitle(s) for 1 video(s)

/share/MD1_DATA/Multimedia/Seriezz/Modern Family/Season 04/Modern Family - 4x09 - When a Tree Falls.srt from bierdopje

**************************************************

Deleting folder /share/MD1_DATA/Download/sabnzbd/complete/TV/Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD

Processing succeeded for /share/MD1_DATA/Download/sabnzbd/complete/TV/Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD/Modern.Family.S04E09.720p.WEB-DL.DD5.1.H.264-HWD.mkv

Of course, just like me, you already downloaded series. Well you can manually run the subtitles.sh script as well. I recommend doing this for each series separately and not all at once!

UPDATE: check the syntax change in red (double minus!).

subliminal -l nl /share/MD1_DATA/Multimedia/Seriezz/Modern Family/

Go into the directory where you keep your episodes:

subliminal –opensubtitles <your_opensubtitles_user>  <your_opensubtitles_password> download * -l nl -l en

One more thing to make this work! Appearently the subtitles need to be set executable for players as VLC to work otherwise you get all sorts of errors. So in the directory that contains the series run the following command:

chmod +rx *.srt
 

Enjoy!

 

This entry was posted in Technotes and tagged , , , , . Bookmark the permalink.

9 Responses to Subtitles with Subliminal for Sickbeard on QNAP

  1. RayF says:

    Hi Ron,
    sorry your comment got lost in the provider transfer of the Technotes blog. anyways you wrote:
    “can you help me on step 5, i use terminal on mac, and when i create the file, i am not able to safe it.. I am pretty new to this, so maybe you can help me!”

    I need a little bit more information to answer your question: it could be a permissions issue (maybe you’re not allowed to write the file on that location), or an editor usage issue or something else.

    You can however also use the standard textedit software in your Applications folder, copy paste the text in the box under step 5 and save it as “subtitles.sh”
    Just make sure it’s in plain text before you save the file (Textedit, menu “Format”, “Make Plain Text”)

  2. Christian says:

    Hi,

    I’m using your sickbeard extra_script bash script on my qnap but I have a problem. Subtitles gets downloaded but always have chmod 600 and can’t be viewed in my media player. Ofcourse I can chmod it manually everytime but I prefer an automatic way. Maybe there is something wrong in the script since I adjusted the script to my needs. Got the following now:

    #! /bin/sh
    echo Filename to process. $1
    echo Original filename… $2
    echo Show TVDB id…….. $3
    echo Season number……. $4
    echo Episode number…… $5
    echo Episode air date…. $6
    echo … pass the episode info to Subliminal and fetch the subtitle
    /share/MD0_DATA/.qpkg/Optware/local/bin/subliminal -l nld eng -c /share/MD0_DATA/.qpkg/Subliminal/subliminal.cache.dbm –addic7ed-username username –addic7ed-password password “$1”

    Can you help me? The subtitles should be chmod 666 or atleast readabily for everyone.

    Thanks in advance

    • RayF says:

      It should inherit the permissions from its parent, at least in my case it does. However a friend of mine had some irregular permission issues on a few folders. He scheduled an hourly script to chmod it correctly throughout his media folder. BTW I’m still on 3.8.1 and he’s on 4.x

  3. Pingback: Thecus NAS Subliminal | Mijn locatie op het .NET

  4. Felipe says:

    Hi there, this script is awesome, its possible add it in cronjob ? for example, after process tv show, if not found available subtitles (because epsode was aired minutes ago and dont have yet subtitle), it will search for subtitles in 6 hours, 9 hours, 12 hours, until find subtitles.. It also can put limit: 7 days

    Would be really great !!

    Thank you for great job

    • RayF says:

      Absolutely, you can add “/opt/local/bin/subliminal -l nl -l en /share/MD1_DATA/Multimedia/Seriezz/*” to a cronjob and run it on whatever timeschedule you’d like. It will go through all the directories.

      I recommend splitting the script across multiple cronjobs depending on the size of your media library. You could run these in-parallel. Also make sure you time each run so the next run of the same directories doesn’t start too early.

  5. M says:

    Hi,

    I installed everything according to your tutorial but I get this error msg in the SabNZB log:

    Executing command [u’/share/MD0_DATA/.qpkg/SickBeard/autoProcessTV/subtitles.sh’, u’/share/MD0_DATA/Multimedia/Series/How I Met Your Mother/Season 9/How I Met Your Mother – 9×16 – How Your Mother Met Me.mp4′, u’/share/MD0_DATA/Download/sabnzbd/complete/TV/How.I.Met.Your.Mother.S09E16.HDTV.x264-KILLERS/how.i.met.your.mother.s09e16.hdtv.x264-killers.mp4′, ‘75760’, ‘9’, ’16’, ‘2014-01-27’]

    Unable to run extra_script: 8

  6. M says:

    Absolute path to script: /share/MD0_DATA/.qpkg/SickBeard/autoProcessTV/subtitles.sh

    Executing command [u’/share/MD0_DATA/.qpkg/SickBeard/autoProcessTV/subtitles.sh’, u’/share/MD0_DATA/Multimedia/Series/How I Met Your Mother/Season 9/How I Met Your Mother – 9×16 – How Your Mother Met Me.mp4′, u’/share/MD0_DATA/Download/sabnzbd/complete/TV/How.I.Met.Your.Mother.S09E16.HDTV.x264-KILLERS/how.i.met.your.mother.s09e16.hdtv.x264-killers.mp4′, ‘75760’, ‘9’, ’16’, ‘2014-01-27’]

    Unable to run extra_script: 8

    • RayF says:

      Does the script run manually?
      So go to the directory where you put the script : /share/MD0_DATA/.qpkg/SickBeard/autoProcessTV/ and start subtitles.sh -l nl -l en /share/MD0_DATA/Multimedia/Series/How I Met Your Mother/Season 9/How I Met Your Mother – 9×16 – How Your Mother Met Me.mp4

      if that works then it’s probably the way you call the script from “extra_scripts =” in config.ini , maybe quotes or forgotten backslashes

Leave a Reply to Christian Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.