Subliminal on QNAP

Installing Subliminal

So installing Subliminal on QNAP (in my case, a QNAP 412 Turbo Nas) isn’t out of the box with qpkg’s like for example SickBeard, CouchPotato or SABnzbd. For all who’s wondering, these tools are the ultimate combination for managing and updating your media library.

Subliminal is the successor of Periscope, also written in Python. It allows your to download subtitles for movies/tv shows fairly easy. Here’s a quick install guide.

First, connect to your NAS via SSH with the ‘admin’ user.
Next, make sure you update your IPKG’s + add some new ones:

ipkg update                             
ipkg upgrade                            
ipkg install git                         
ipkg install textutils	                
ipkg install python27	                
ipkg install py27-setuptools	    
ipkg install mlocate

So now you’ve got all the utlities you need so let’s download the latest version of Subliminal:

git clone -b master https://github.com/Diaoul/subliminal.git /tmp/subliminal

Now let’s install Subliminal.

cd /tmp/subliminal
/opt/bin/python2.7 setup.py install

You now should have a working copy of Subliminal on your NAS. Now how do you use this wonderful piece of software?

You can manually retrieve subs using this command:

# subliminal -l LANG DIR
subliminal -l en /Qmultimedia/Movies/

But here’s a better way. We’re lazy right?

Automating Subliminal with Sickbeard and Couchpotato

1) using cronjobs
Cronjobs is a command/script which runs regularly. Normally you’d use crontab for this, but QNAP automatically cleans this each reboot..
So according to their docs, we’ll have to do some other way. We’ll pick method 1.

echo "1 22,0 * * * /share/MD0_DATA/.qpkg/Optware/local/bin/subliminal -l en /Qmultimedia/Movies/" >> /etc/config/crontab
echo "#1 22,0 * * * /share/MD0_DATA/.qpkg/Optware/local/bin/subliminal -l en /Qmultimedia/Series/" >> /etc/config/crontab
crontab /etc/config/crontab

You now have a cronjob which checks for new subtitles for new movies at 22 and 24 hour each day. Don’t overdo do this, since you’re basicly scraping all the subtitle sites. Once or twice a day should do.

2) using extrascripts
Currently only sickbeard has this well documented.
Using the ‘locate’ command I found out where my SickBeard install is located.

cd /share/MD0_DATA/.qpkg/SickBeard/
vim config.ini

And find the extrascript and replace it with:

extra_scripts = "findSubs.sh"

Now create this script:

vim findSubs.sh

Insert script

# http://code.google.com/p/sickbeard/wiki/AdvancedSettings
subliminal -l en $1

Now quit vim and chmod this bash script.

chmod +x findSubs.sh

Congrats! Sickbeard will now automaticlly call this script as soon as an episode is downloaded meaning you will have subtitles almost directly after downloading them.

EDIT:
I noticed these cronjobs aren’t always running.. after quite some debugging I found a workaround. The reason the cronjobs aren’t working is because Subliminal is having problems scanning directories with lots of media. Here’s how I fixed it:

1 22,0 * * * /share/MD0_DATA/Multimedia/_crons/subs_series.sh
10 22,0 * * * /share/MD0_DATA/Multimedia/_crons/subs_movies.sh

subs_series.sh

#!/bin/bash
 
find /Qmultimedia/Series/ -type d | while read dir;
do
        /share/MD0_DATA/.qpkg/Optware/local/bin/subliminal -l en "$dir" --cache-dir /Qmultimedia/_crons/cache/
        echo "$dir"
done
 
touch /Qmultimedia/_crons/logs/series_`date +\%Y-\%m-\%d-\%H-\%M-\%S`-cron.log
~

subs_movies.sh

#!/bin/bash
 
find /Qmultimedia/Movies/ -type d | while read dir;
do
        /share/MD0_DATA/.qpkg/Optware/local/bin/subliminal -l en "$dir" --cache-dir /Qmultimedia/_crons/cache/
        echo "$dir"
done
 
touch /Qmultimedia/_crons/logs/movies_`date +\%Y-\%m-\%d-\%H-\%M-\%S`-cron.log

Freelance webdeveloper & Entreprenerd Specialized in developing, scaling and optimizing of succesful web applications, community websites and small/corporate business websites using technologies such as PHP 5, Laravel, HTML5, jQuery, .. Trying to find optimal Google love for every website. I'm always interested and open for new business opportunities.

19 Comments

  1. Pingback: Generating m3u's playlists on the fly.

  2. Zerocool64

    Is anyone has already encountered this error ?

    [/share/MD0_DATA/.qpkg/Optware/local/bin] # ./subliminal -l fr /share/Public/Ringer_S01E05.avi
    Traceback (most recent call last):
      File “./subliminal”, line 5, in
        pkg_resources.run_script(‘subliminal==0.5.1’, ‘subliminal’)
      File “/opt/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py”, line 489, in run_script
        self.require(requires)[0].run_script(script_name, ns)
      File “/opt/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py”, line 1214, in run_script
        exec script_code in namespace, namespace
      File “/opt/local/lib/python2.7/site-packages/subliminal-0.5.1-py2.7.egg/EGG-INFO/scripts/subliminal”, line 79, in

      File “/opt/local/lib/python2.7/site-packages/subliminal-0.5.1-py2.7.egg/EGG-INFO/scripts/subliminal”, line 52, in main

    OSError: [Errno 2] No such file or directory: ‘/root/.config/subliminal’

    1. ChrisSchalenborgh

       Nope.. and I just checked, I don’t have that file on my NAS . What version of subliminalare you running?

        1. Zerocool64

          I can’t explain that but with the option –cache-dir /tmp it works.

          You can clear my replies if you want, I think I’m the only one which has had that error

  3. ldw

    When I try to run subliminal manually, I get this error:
    -sh: subliminal: command not found

    What am I doing wrong?

    1. ChrisSchalenborgh

      Try using the full path.. most likely:
      /share/MD0_DATA/.qpkg/Optware/local/bin/subliminal

  4. Maarten De Bont

    having the same problems as below but with added error:

    [/share/MD0_DATA/.qpkg/Optware/local/bin] # ./subliminal –cache-dir /tmp/ -l nl /share/MD0_DATA/Releases6/TV/The Exes WARNING: subliminal.core Service bierdopje not available: none of available features could be used. One of [‘xml’] requiredNo subtitles downloaded

    1. ChrisSchalenborgh

       Try one of these commands:

      [~] # subliminal -h
      -sh: subliminal: command not found
      [~] # /share/MD0_DATA/.qpkg/Optware/local/bin/subliminal -h
      usage: subliminal [-h] [-l LG] [-p NAME] [-m] [-f] [-w N] [-q | -v]
                        [–cache-dir DIR | –no-cache-dir] [–version]
                        PATH [PATH …]

      Subtitles, faster than your thoughts

      positional arguments:
        PATH                  path to video files or folders

      optional arguments:
        -h, –help            show this help message and exit
        -l LG, –language LG  wanted language (ISO 639-1)
        -p NAME, –plugin NAME
                              plugin to use
        -m, –multi           download multiple subtitle languages
        -f, –force           replace existing subtitle file
        -w N, –workers N     use N threads (default: 4)
        -q, –quiet           disable output
        -v, –verbose         verbose output
        –cache-dir DIR       cache directory to use
        –no-cache-dir        do not use cache directory (some plugins may not work)
        –version             show program’s version number and exit

      1. Calloha

        Nope. “command not found”. I do see a subliminal* file in the /share/MD0_DATA/.qpkg/Optware/local/bin directory. But I got the feeling there should be more than that?

        1. Calloha

          Sorry, got it working using the full path, but after running the command I got the following problem:

          /share/MD0_DATA/.qpkg/Optware/local/bin/subliminal -l en /share/MD0_DATA/Multimedia/VideosTraceback (most recent call last):  File “/share/MD0_DATA/.qpkg/Optware/local/bin/subliminal”, line 5, in     pkg_resources.run_script(‘subliminal==0.6.1’, ‘subliminal’)  File “/opt/lib/python2.7/site-packages/pkg_resources.py”, line 489, in run_script    self.require(requires)[0].run_script(script_name, ns)  File “/opt/lib/python2.7/site-packages/pkg_resources.py”, line 1214, in run_script    exec script_code in namespace, namespace  File “/opt/local/lib/python2.7/site-packages/subliminal-0.6.1-py2.7.egg/EGG-INFO/scripts/subliminal”, line 99, in
            File “/opt/local/lib/python2.7/site-packages/subliminal-0.6.1-py2.7.egg/EGG-INFO/scripts/subliminal”, line 55, in main
          OSError: [Errno 2] No such file or directory: ‘/root/.config/subliminal’

  5. c0de1b75

    great script, but when i downoad a episode, there isn’t always direct a subtitle available. It scan only once when finished downoading right ?

    1. ChrisSchalenborgh

      Yeah using callbacks, that’s why you should implement this cronjob solution so it will scan on a regular basis 🙂

  6. koen

    Thanks for the guide; still a few questions: 
    1) why are these entries red: echo “1 22,0 * * * /share/MD0_DATA/.qpkg/Optware/local/bin/subliminal -l en /Qmultimedia/Movies/” >> /etc/config/crontab
    echo “#1 22,0 * * * /share/MD0_DATA/.qpkg/Optware/local/bin/subliminal -l en /Qmultimedia/Series/” >> /etc/config/crontab
    crontab /etc/config/crontab

    2) Where should I put this (from the edit section)?:
    1 22,0 * * * /share/MD0_DATA/Multimedia/_crons/subs_series.sh
    10 22,0 * * * /share/MD0_DATA/Multimedia/_crons/subs_movies.sh3) my crontab file does not have any new entries in there. Is this ok?4) how can I verify this works after an installation. I can see the subliminal -h entries.Thanks!!!

    1. ChrisSchalenborgh

      Hi Koen,

      1) code syntax used on this blog
      2) doesn’t matter..
      3) what do you mean?
      4) there should be some logs everytime the cronjob runs (see touch command)

      1. koen

        Ok, I will try to be more specific: 
        1) where do i need to put this: echo “1 22,0 * * * /share/MD0_DATA/.qpkg/Optware/local/bin/subliminal -l en /Qmultimedia/Movies/” >> /etc/config/crontab
        echo “#1 22,0 * * * /share/MD0_DATA/.qpkg/Optware/local/bin/subliminal -l en /Qmultimedia/Series/” >> /etc/config/crontab
        crontab /etc/config/crontab

        Is this in putty (ssh), in a file or where.

        2. Ok.
        3. The crontab file in /etc/config/crontab, no entry of a new cronjob in there.
        4. I don’t see any logs created.

        Most important is step 1. Also, in your edit section, where do i need to put this in: 
        1 22,0 * * * /share/MD0_DATA/Multimedia/_crons/subs_series.sh
        10 22,0 * * * /share/MD0_DATA/Multimedia/_crons/subs_movies.sh. Is this in a file or SSH or something else?
        I hope you can help me as this is the one thing i have been looking for since a long time!

Leave a Reply

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