[GUIDE] Automatically download subtitles

Support for Synology NAS, QNAP NAS and other Embedded Linux systems
Post Reply
maxoudela
Power User
Posts: 17
Joined: 31 Mar 2016, 12:16

[GUIDE] Automatically download subtitles

Post by maxoudela » 07 Apr 2016, 12:33

This tutorial is intended for people who wants to automatically download subtitles for their movies/series. Basically, everything is already written in the forum, but this tutorial aims at regrouping everything in one thread.

I'm using Download Station of Synology combined to an RSS feed in order to automatically download some series (if you want to do that, it's there https://www.crisi.ch/automatically-down ... adstation/. What I wanted was to also download subtitles automatically.

Prerequisites
  • You must have DSM 6.0 minimum on your Synology.
  • You must have (and know how) to have access to your NAS via SSH.
Installation
First of all, we will need to install Java 8 on the NAS. If this is not done yet, you must open the package center, then find the package "Java8" and install it. If you had Java7 installed, you can remove it (at least it's what I did).

Once done, you can install FileBot :P. For that, simply follow the procedure but do not install FileBotNode, we don't need it : http://www.filebot.net/forums/viewtopic.php?f=3&t=1802

At that point, you should have FileBot correctly installed and running.

Configuration
Let's get into business. We first need to set up our OpenSubtitles account. The subtitles are going to be downloaded from the website http://www.opensubtitles.org/ so you need to create an account on it. Then you need to inform Filebot by following this procedure : viewtopic.php?f=3&t=228

Then you will need to set the Java path correctly.

But why? I've already installed Java 8 on the nas!

Because :
Running commands from the login shell is not the same as using Synology DSM Task Scheduler or cron because they'll not initialise with ~/.profile so PATH may be different.
Got it? No? Allright, it's not a problem, neither did I :lol: . The point is that we will execute an automated task (download subtitles) with Synology Task Manager. This task will be executed by a user (usually the same you connect with SSH). But a command will fail when ran in a Task as it will succeed when ran in SSH. So we need to fix that.

The procedure is somehow explained here (https://www.youtube.com/watch?v=8N6hYNj ... tml5=False), but it's simple in our case so I've detailed it :
  • Connect in SSH with the same user you will use for the task.
  • Verify that Java is correctly installed by typing :

    Code: Select all

    java -version
    Image
  • Then identify where it's installed by typing :

    Code: Select all

    echo ${JAVA_HOME}
    Image

    You should have something similar to me. Now we just need to include Java for our user so that the Task can be ran!
  • You need to take the path you got from the previous command, remove jre at the end, and add bin/java, in my case it will be :

    Code: Select all

    sudo ln -s /var/packages/Java8/target/j2sdk-image/bin/java /usr/local/bin/java
  • Enter your password and it's good.
  • Verify it went well by typing :

    Code: Select all

    which java
    and verify it points to the /usr/local/bin/java .
You can exit SSH and get back to DSM.

Adding the task
Before adding the Task, you need to identify where your movies and series are. In my case I have a folder named video which contains a folder named Series. In that folder, I have all my series. So for the Task, the path I will use will be /volume1/video/Series . That means that I want FileBot to download subtitles that are not present in any sub-folders of Series every time the task will be launched.
  • Go to Synology Control Panel, and to Task Scheduler, then click on create -> Scheduled task -> User defined script.
  • Give it a fancy name and select the same user you used in SSH.
  • On the schedule tab, program it daily for example.
  • On Task settings, write a command (examples are here : http://www.filebot.net/cli.html ), in order to download the missing subtitles for your series :

    Code: Select all

    cd /var/services/homes/master
    filebot -script fn:suball /volume1/video/Series/ --def maxAgeDays=7
    Do not forget to use maxAgeDays as specified here : viewtopic.php?f=4&t=5#p8871

    I put a cd command just before calling FileBot because my user is different from admin and somehow, the taskManager is not at the right place when starting. If your user is admin, you should not need that command.
  • Click OK
I suggest that before testing on your root Series folder, test it on a sub-folder first. Because if something goes wrong, it won't take much time before ending.
You can redirect the output log as specified here : http://www.filebot.net/forums/viewtopic ... 802#p12015

But since you are noob like me :? , here is a simpler way to do that :
  • In the Control Panel, select the task you just created, then hit the Settings button.
  • You can now enable the output and select a folder where the results of the Task will be printed.
    Image
    In my case I put it in video folder which is rather dumb but I like to spice things a little :roll:
When everything is ready, you can click on Run in order to test your Task. Hopefully, you can check in the logs the output.

FAQ
But the task will be executed each day, I want it to be executed when my downloads are finished!
First of all, settle down cowboy. You are lucky someone like rednoah developed a tool allowing you to automatically do things. Then, the download station of Synology doesn't allow (yet) to run scripts when a download is done. So the solution right now is to run periodically a Task that will download missing subtitles.

This is very cool for the future as everything will be automatically done but I have downloaded a Serie a long time ago, and I want to download the subtitles!
You are totally right. The script is working for future downloads as we indicated maxAgeDays to 7 and we do not download subtitles for files that are older that 7 days. In your case, you should connect in SSH, go to the folder where all your episodes are, and run the command manually :

Code: Select all

filebot -script fn:suball /path/to/media 
BUT be aware that you removed the maxAgeDays so the location where you execute the command must be small because otherwise you will try to download too much subtitles and you will get banned from OpenSubtitles and then you will be sad.

Allright this is cool but I'm french, and as you know, french do not speak very good english
Hello there french fellow. I understand your pain since I'm also French. What you need is to add a little option that you can find here (http://www.filebot.net/cli.html) in order to specify that you want French subtitles!

Code: Select all

filebot -script fn:suball /volume1/video/Séries/ --lang fr --def maxAgeDays=7
Last edited by maxoudela on 11 Apr 2016, 11:56, edited 1 time in total.

User avatar
rednoah
The Source
Posts: 16578
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Synology] Download subtitles automatically

Post by rednoah » 07 Apr 2016, 13:23

Thanks for the rather excellent tutorial! Much appreciated! :ugeek:

Here's some additional tips:
  • My Java Installer can help you install Oracle Java 8 and avoid all the $PATH issues (may not work for older ARM devices though)
  • The OpenJDK runtime works, but it's known to be very slow on ARM devices
  • I recommend setting --def minAgeDays=1 as well so that it'll wait for a day before it'll search for subtitles because good subtitles may not be available until a few days after the release
:idea: Please read the FAQ and How to Request Help.

kunato
Posts: 3
Joined: 22 Jun 2018, 04:07

Re: [GUIDE] Automatically download subtitles

Post by kunato » 22 Jun 2018, 04:09

This guide does NOT WORK.
It was 45 mins waste of time.
You must have custom-specificed something that works only for you but noone else.

Also, your SSH command is incorrect.
Input: /var/packages/Java7/target/j2sdk-image/bin/java /usr/local/bin/java
Output: Error: Could not find or load main class .usr.local.bin.java

:oops: :cry: :oops:

User avatar
rednoah
The Source
Posts: 16578
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [GUIDE] Automatically download subtitles

Post by rednoah » 22 Jun 2018, 07:07

kunato wrote:
22 Jun 2018, 04:09

Code: Select all

$ /var/packages/Java7/target/j2sdk-image/bin/java /usr/local/bin/java
Error: Could not find or load main class .usr.local.bin.java
How did you come up with this? Java 7 does not work. FileBot requires Java 8 and FileBot will not work with Java 7.


Here's what the guide says: symlink the java executable to /usr/local/bin

Code: Select all

sudo ln -s /var/packages/Java8/target/j2sdk-image/bin/java /usr/local/bin/java

Here's what you're doing: execute the java executable and pass in /usr/local/bin/java as first argument

Code: Select all

/var/packages/Java7/target/j2sdk-image/bin/java /usr/local/bin/java

I guess you forgot to write sudo ln -s before the <target> <link> arguments and thus ended up doing something completely different. Though it wouldn't have worked anyway because Java 7 can't run FileBot in the first place, even if linked correctly. :roll:
:idea: Please read the FAQ and How to Request Help.

kunato
Posts: 3
Joined: 22 Jun 2018, 04:07

Re: [GUIDE] Automatically download subtitles

Post by kunato » 23 Jun 2018, 23:16

Your guide works for you because you likely have ONLY one versions of java installed: Java8 - commonly multiple versions of Java are installed since packets can be picky in which Java version they required.

The guide should state: "You MUST/HAVE TO delete Java 7, otherwise, the guide below WILL NOT work without some editing". "CAN" means, possibility, not a requirement. "MUST" means a requirement.

The user MUST deinstall Java7 AND reboot NAS to proceed.

It is quite possible that JAVA_HOME still points to Java 7, even AFTER Java7 is de-installed! Users need to REBOOT NAS to refresh JAVA_HOME (otherwise manual pointing is required).

If user has Java7, Java8 -> then running echo ${JAVA_HOME} will produce the first instance, which is Java7, and the output will be
/var/packages/Java7/target/j2sdk-image/jre
NOT
/var/packages/Java8/target/j2sdk-image/jre

The user will have to manually change number 7 to 8 to proceed with guide, which makes it "messy" to follow.
Last edited by kunato on 24 Jun 2018, 00:16, edited 2 times in total.

kunato
Posts: 3
Joined: 22 Jun 2018, 04:07

Re: [Synology] Download subtitles automatically

Post by kunato » 23 Jun 2018, 23:57

Please note that when "Unofficial Java Installer" is used to install Java, it is not resolving the issue from this guide.
Even when Java 7 is de-installed, echo ${JAVA_HOME} still returns
/var/packages/Java7/target/j2sdk-image/jre

JAVA_HOME needs to be manually set to point to Java 8 vs Java 7.
OR
Java 7 needs to be de-installed AND NAS rebooted for changes to take effect.
rednoah wrote:
07 Apr 2016, 13:23
Thanks for the rather excellent tutorial! Much appreciated! :ugeek:

Here's some additional tips:
  • My Java Installer can help you install Oracle Java 8 and avoid all the $PATH issues (may not work for older ARM devices though)
  • The OpenJDK runtime works, but it's known to be very slow on ARM devices
  • I recommend setting --def minAgeDays=1 as well so that it'll wait for a day before it'll search for subtitles because good subtitles may not be available until a few days after the release

Nellybauer
Posts: 2
Joined: 20 Jul 2018, 13:40

Re: [GUIDE] Automatically download subtitles

Post by Nellybauer » 20 Jul 2018, 14:33

I'm trying to manually grab some subtitles for an older season, approx 2 years old. When I run

Code: Select all

filebot -script fn:suball /mypath/season2
i.e. without specifying --def maxAgeDays & each episode comes back with "Ignore old:"

Is the --def maxAgeDays=30 flag set by default & can't be overwritten? I tried forcing it to be very high & it says 30 is the max value.

Update:
I'm getting around it as this is only a 1 off activity by using the Windows client instead on of my Synology direct, which works great but would still be interested to know if the command line version is limited to 30d max age even if you dont specify the flag

User avatar
rednoah
The Source
Posts: 16578
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [GUIDE] Automatically download subtitles

Post by rednoah » 20 Jul 2018, 20:10

What you're asking for is possible, but due to abuse, it's only for those who spend a bit of time reading the code:
https://github.com/filebot/scripts/blob ... all.groovy
:idea: Please read the FAQ and How to Request Help.

Nellybauer
Posts: 2
Joined: 20 Jul 2018, 13:40

Re: [GUIDE] Automatically download subtitles

Post by Nellybauer » 20 Jul 2018, 23:32

rednoah wrote:
20 Jul 2018, 20:10
What you're asking for is possible, but due to abuse, it's only for those who spend a bit of time reading the code:
https://github.com/filebot/scripts/blob ... all.groovy
Thanks, I stumbled on to that myself earlier as well. So I take it I'm looking at the maxagedayslimit field.

As I updated in my earlier post, I just used the windows version instead for this 1 off task but thanks for confirming how it can be done.

Bought a licence today after being a user on Synology for a long time. It through me a bit after just installing the latest update in the package center that no files were getting processed, checked the AMC log and saw the messages of needing a licence, happy to pay the 6 dollars. Will teach me to just blindly update without reading the changes first!

gac550
Posts: 1
Joined: 16 Oct 2018, 21:40

Re: [GUIDE] Automatically download subtitles

Post by gac550 » 16 Oct 2018, 21:53

Hi gents,
I need your help, I installed properly FileBot Nodes & Java so that I can use the Filebot interface rather the SSH terminal. I would like to SEARCH only subtitles (OpenSource) in English and Spanish as well, and I have working licenses for both. My Synology is installed abroad, for that, I have only remote access via the web interface (I do not have access to SSH/Terminal).

So, how I can download ONLY subtitles (Spanish and English) using FileBot Node? Or which is the CODE that I need to add in Synology Scheduled Task? The videos are located in:
\volume1\videos\movies

Many thanks in advance!

User avatar
rednoah
The Source
Posts: 16578
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [GUIDE] Automatically download subtitles

Post by rednoah » 17 Oct 2018, 14:04

Unfortunately, FileBot Node only supports amc script calls, and thus cannot be used to only fetch subtitles.

You can however create your own script, and call filebot from there, and once you've got it working you can have Scheduler call the script regularly:
viewtopic.php?f=4&t=5#p8871
:idea: Please read the FAQ and How to Request Help.

Tdoc
Posts: 22
Joined: 20 Feb 2018, 08:19

Re: [GUIDE] Automatically download subtitles

Post by Tdoc » 17 Feb 2019, 16:27

Can I run subtitles search at the same time the scheduler is renaming and moving the series ?

I am using SHOWRSS to automatically get what we are watching, it would be truely wonderful to have subtitles being fetched as the series moves to the storage drives

I have now inform filebot via SSh my opensubtitle credential, and check all is fine, quota 200 a day

in advance thanks

User avatar
rednoah
The Source
Posts: 16578
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [GUIDE] Automatically download subtitles

Post by rednoah » 18 Feb 2019, 05:22

It stands to reason that the script that is called by your scheduler, can be more than one line, and do the subtitles command before or after the renaming files command. I'd do it before so newly downloaded subtitles are moved accordingly in the following rename step as well.
:idea: Please read the FAQ and How to Request Help.

balian
Posts: 5
Joined: 22 Feb 2019, 16:22

Re: [GUIDE] Automatically download subtitles

Post by balian » 22 Feb 2019, 16:41

Have followed this guide all the way to this step, but I'm stuck now:

Code: Select all

ln: failed to create symbolic link ‘/usr/local/bin/java/java’: File exists
Image

Can you help me?

User avatar
rednoah
The Source
Posts: 16578
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [GUIDE] Automatically download subtitles

Post by rednoah » 22 Feb 2019, 16:58

So you're having trouble getting the java command working?


Have you tried my java installer package already?
viewtopic.php?f=13&t=1802


You can also manually run the installer script if you prefer:
https://github.com/rednoah/java-install ... n-on-linux
:idea: Please read the FAQ and How to Request Help.

balian
Posts: 5
Joined: 22 Feb 2019, 16:22

Re: [GUIDE] Automatically download subtitles

Post by balian » 22 Feb 2019, 17:22

rednoah wrote:
22 Feb 2019, 16:58
Have you tried my java installer package already?
viewtopic.php?f=13&t=1802
That was exactly my problem! I had installed this one:
Image

Installed your package and the link command worked perfectly! Thank you very much!

john1deer
Posts: 3
Joined: 31 Mar 2019, 15:46

Re: [GUIDE] Automatically download subtitles

Post by john1deer » 31 Mar 2019, 15:56

Getting an error:

Code: Select all

Get [English] subtitles for 1 files
CmdlineException: OpenSubtitles: Please enter your login details by calling `filebot -script fn:configure`
when running as Task, but no issues when running from command-line.

Command:

Code: Select all

filebot -script fn:suball '/volume1/video/'
When running from command line (same user as in Task) I get:

Code: Select all

...
Fetch subtitles for [/volume1/video/]
Get [English] subtitles for 1 files


Java seems to be configured correctly:

Code: Select all

[email protected]:~$ which java
/usr/local/bin/java
[email protected]:~$ ls -l /usr/local/bin/java
lrwxrwxrwx 1 root root 47 May  3  2018 /usr/local/bin/java -> /var/packages/Java8/target/j2sdk-image/bin/java
Where is the opensubtitles configuration is stored? Why does Task behaves differently?

User avatar
rednoah
The Source
Posts: 16578
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [GUIDE] Automatically download subtitles

Post by rednoah » 31 Mar 2019, 16:06

How did you confirm that you indeed run your scheduled tasks as the same user? What does filebot -script fn:sysinfo say?

It's stored per-user, so you might have to run filebot -script fn:configure as the user that will be running your scheduled tasks.

:idea: filebot -script fn:sysinfo will tell you where the application data folder is for your current user.
:idea: Please read the FAQ and How to Request Help.

john1deer
Posts: 3
Joined: 31 Mar 2019, 15:46

Re: [GUIDE] Automatically download subtitles

Post by john1deer » 03 Apr 2019, 21:20

rednoah wrote:
31 Mar 2019, 16:06
How did you confirm that you indeed run your scheduled tasks as the same user?
In Edit task/General the user is the same as the user accessed via shell (verified with whoami just to be sure)
rednoah wrote:
31 Mar 2019, 16:06
What does filebot -script fn:sysinfo say?
$ filebot -script fn:sysinfo
x86_64
FileBot 4.8.2 (r5789)
JNA Native: 5.2.2
MediaInfo: 17.12
7-Zip-JBinding: 9.20
Chromaprint: java.io.IOException: Cannot run program "fpcalc": error=2, No such file or directory
Extended Attributes: OK
Unicode Filesystem: OK
Script Bundle: 2019-02-26 (r552)
Groovy: 2.5.1
JRE: Java(TM) SE Runtime Environment 1.8.0_171
JVM: 64-bit Java HotSpot(TM) 64-Bit Server VM
CPU/MEM: 2 Core / 1 GB Max Memory / 17 MB Used Memory
OS: Linux (amd64)
HW: Linux media 4.4.59+ #23824 SMP PREEMPT Tue Feb 12 16:52:55 CST 2019 x86_64 GNU/Linux synology_apollolake_218+
DATA: /volume1/@appstore/filebot/data/user
Package: SPK
rednoah wrote:
31 Mar 2019, 16:06
:idea: filebot -script fn:sysinfo will tell you where the application data folder is for your current user.
Running this as a task I get:

x86_64
Locking /volume1/homes/tv/filebot.log
FileBot 4.8.2 (r5789)
JNA Native: 5.2.2
MediaInfo: 17.12
7-Zip-JBinding: 9.20
Chromaprint: java.io.IOException: Cannot run program "fpcalc": error=2, No such file or directory
Extended Attributes: OK
Unicode Filesystem: OK
Script Bundle: 2019-02-26 (r552)
Groovy: 2.5.1
JRE: Java(TM) SE Runtime Environment 1.8.0_171
JVM: 64-bit Java HotSpot(TM) 64-Bit Server VM
CPU/MEM: 2 Core / 1 GB Max Memory / 17 MB Used Memory
OS: Linux (amd64)
HW: Linux media 4.4.59+ #23824 SMP PREEMPT Tue Feb 12 16:52:55 CST 2019 x86_64 GNU/Linux synology_apollolake_218+
DATA: /volume1/@appstore/filebot/data/user
Package: SPK


(same data path)

User avatar
rednoah
The Source
Posts: 16578
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [GUIDE] Automatically download subtitles

Post by rednoah » 04 Apr 2019, 04:49

Strange. Well, I guess you can call configure just before the amc script, and that should ensure that things are running in the exact same context:

Code: Select all

filebot -script fn:configure --def osdbUser=<username> --def osdbPwd=<password>
filebot -script fn:amc ...
:idea: Please read the FAQ and How to Request Help.

john1deer
Posts: 3
Joined: 31 Mar 2019, 15:46

Re: [GUIDE] Automatically download subtitles

Post by john1deer » 06 Apr 2019, 15:07

Running this under task:

Code: Select all

filebot -script fn:sysinfo
filebot -script fn:configure --def osdbUser=<user> osdbPwd=<pass>
I get:

Code: Select all

x86_64
FileBot 4.8.2 (r5789)
JNA Native: 5.2.2
MediaInfo: 17.12
7-Zip-JBinding: 9.20
Chromaprint: java.io.IOException: Cannot run program "fpcalc": error=2, No such file or directory
Extended Attributes: OK
Unicode Filesystem: OK
Script Bundle: 2019-02-26 (r552)
Groovy: 2.5.1
JRE: Java(TM) SE Runtime Environment 1.8.0_171
JVM: 64-bit Java HotSpot(TM) 64-Bit Server VM
CPU/MEM: 2 Core / 1 GB Max Memory / 18 MB Used Memory
OS: Linux (amd64)
HW: Linux media 4.4.59+ #23824 SMP PREEMPT Tue Feb 12 16:52:55 CST 2019 x86_64 GNU/Linux synology_apollolake_218+
DATA: /volume1/@appstore/filebot/data/user
Package: SPK
License: FileBot License P******* (Valid-Until: 2019-07-**)
Done ヾ(@⌒ー⌒@)ノ
x86_64
Testing OpenSubtitles... OK
Done ヾ(@⌒ー⌒@)ノ
After this, subtitles are downloaded correctly.

Thanks!

chiarac
Posts: 7
Joined: 20 May 2015, 18:13

Re: [GUIDE] Automatically download subtitles

Post by chiarac » 25 Apr 2019, 17:05

Hi John1deer,
I have the same issue.

Did I understand correctly that you ran

Code: Select all

filebot -script fn:sysinfo
filebot -script fn:configure --def osdbUser=<user> osdbPwd=<pass>
once as task and then you are running the "standard" script to download subtitles?
or did you add the fn:configure part to the regularly running script?

thank you!

User avatar
ramonfarron
Posts: 1
Joined: 05 Sep 2019, 10:17

Re: [GUIDE] Automatically download subtitles

Post by ramonfarron » 05 Sep 2019, 10:26

Hello,

I've just installed 4.8.2 on MacOS and the subtitle function is missing. It looks like it's an unregistered version and I'm not sure what to do, because the Apple support didn't answer my questions yet.

User avatar
rednoah
The Source
Posts: 16578
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [GUIDE] Automatically download subtitles

Post by rednoah » 05 Sep 2019, 10:51

Please include screenshots and sysinfo.


Please read How to Request Help for details on that.


:!: If you have purchased FileBot from the Mac App Store (though we're at FileBot 4.8.5 now and you can't install older versions) then you will indeed find the Subtitles feature removed due to Apple restrictions: viewtopic.php?f=12&t=5983
:idea: Please read the FAQ and How to Request Help.

Post Reply