Subliminal is a python library / command line tool to search and download subtitles.
Various video players like Totem or VLC (with the VLSub extension) already support downloading subtitles from OpenSubtitles based on the video name or hash, but Subliminal supports multiple subtitle websites: Addic7ed, BierDopje, OpenSubtitles, SubsWiki, Subtitulos, TheSubDB and TvSubtitles, so there are better chances for downloading working subtitles that match your video.
Subliminal uses video hashes and the "guessit" library to extract information from the filename / path to make sure the correct subtitles are downloaded. Further more, the tool uses a library called "enzyme" to detect embedded subtitles and avoid duplicates.
Installation
To install Subliminal in Ubuntu, use the following commands:
sudo apt-get install python-pip
sudo pip install subliminal
Now, to download subtitles, you can either use a file path, filename or folder path. Here's an example:
subliminal -l en The.Big.Bang.Theory.S05E18.HDTV.x264-LOL.mp4
This will download the subtitle in the current folder, if you want to download them into the video folder "cd" to that directory firstly.
"-l" sets the subtitle language, "en" (English) in the example above.
For more on how to use subliminal, run this command in a terminal:
subliminal --help
Thanks to Tamps for the tip!