You are not logged in.

#1 2011-08-09 09:31:32

billy
Member
From: Slovenia
Registered: 2006-09-13
Posts: 164

submarine - Search and download subtitles

I've tried different software to download appropriate subtitles for movies but didn't like any of them. I wanted something simple and fast. So I decided to write my own subtitle fetcher smile.

Submarine is a subtitle search and download command-line application for fetching subtitles based on movie file hashes. The subtitles are properly renamed depending on movie filename and subtitle format so they are automatically used by movie players. The application is written entirely in vala and has little runtime dependencies. The source code is hosted on GitHub (http://github.com/blazt/submarine) and there is a package in AUR (http://aur.archlinux.org/packages.php?ID=51338).

Currently the program supports:

  • downloading subtitles for multiple movies at once

  • downloading subtitles from multiple online services (only one is available for now: http://www.opensubtitles.org)

  • filtering subtitles by any number of languages

  • automatically renaming subtitles to movie filenames

  • automatically retrieving subtitles that are best rated

Planned:

  • support more subtitle services (primary goal)

  • get movie filenames from stdin. Example: find . -iname "*.avi" | submarine -l eng

  • put subtitle filenames to stdout. Example: submarine -l eng Season01/*.avi | xargs tar -czf Season01.gz

  • let user select criterion to select subtitles: best subtitle rating, preferred subtitle format, preferred language (if multiple filters are used), preffered server (if multiple servers are used),...

  • create a shared library for subtitle searching and downloading (long term)

  • convert subtitle formats (long term)

  • ...

 
Comments and suggestions are very appreciated.

Last edited by billy (2011-08-09 09:32:15)

Offline

#2 2011-08-09 22:22:05

quigybo
Member
Registered: 2009-01-15
Posts: 223

Re: submarine - Search and download subtitles

Absolutely amazing, I have wanted something like this for a long time. Thank you.

After having a quick play with it, I have noticed that it doesn't always work when using the two letter language code. It seems to happen with languages with more than one entry in the output of `-l help`. As a few examples of one file I tested, "nl" didn't work but "dut" did, "fr" didn't but "fre" did and "ro" didn't work but "rum" did. Maybe if the two letter code is the same for more than one three letter entry, they should all be checked?

Also, I can imagine that most of the time users will want to grab the same language, do you plan on adding a config file, or should I just use an alias?

And finally (pretty minor), an exit status > 0 when no files are found would be nice.

Offline

#3 2011-08-10 11:14:41

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: submarine - Search and download subtitles

Great app! Made this little Thunar custom action;

terminal --geometry=80x24 --hold -e 'submarine -l eng %n'

--hold is for debugging and can be deleted when all is ok.

EDIT: really neat actually! Thanks for the good work!

Last edited by swanson (2011-08-10 11:19:36)

Offline

#4 2011-08-10 13:00:08

z0id
Member
From: Romania
Registered: 2010-02-02
Posts: 122

Re: submarine - Search and download subtitles

It doesn't build here

open_subtitles.vala:92.92-92.92: error: Argument 3: Cannot pass value to reference or output parameter
                    Soup.XMLRPC.parse_method_response ((string) message.response_body.flatten().data, -1, v);
                                                                                                          ^
open_subtitles.vala:136.92-136.92: error: Argument 3: Cannot pass value to reference or output parameter
                    Soup.XMLRPC.parse_method_response ((string) message.response_body.flatten().data, -1, v);
                                                                                                          ^
open_subtitles.vala:168.92-168.92: error: Argument 3: Cannot pass value to reference or output parameter
                    Soup.XMLRPC.parse_method_response ((string) message.response_body.flatten().data, -1, v);
                                                                                                          ^
open_subtitles.vala:218.92-218.92: error: Argument 3: Cannot pass value to reference or output parameter
                    Soup.XMLRPC.parse_method_response ((string) message.response_body.flatten().data, -1, v);
                                                                                                          ^
open_subtitles.vala:261.92-261.92: error: Argument 3: Cannot pass value to reference or output parameter
                    Soup.XMLRPC.parse_method_response ((string) message.response_body.flatten().data, -1, v);
                                                                                                          ^
Compilation failed: 5 error(s), 0 warning(s)
make[2]: *** [libsubmarine_la_vala.stamp] Error 1

/usr/bin/drinking

Offline

#5 2011-08-10 13:32:33

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: submarine - Search and download subtitles

I have these;

Vala 0.12.1-1
libsoup: 2.34.3-1
libgee : 0.6.1-1

Compiled fine here.

Offline

#6 2011-08-10 13:45:39

billy
Member
From: Slovenia
Registered: 2006-09-13
Posts: 164

Re: submarine - Search and download subtitles

@quigybo:
Thanks fot testing smile. The fixes should now be available on github.
Exit status is now 0 if all went OK, 1 if no files were saved or overwritten (program had no effect) and 2 if there was invalid input.
Language codes are now properly resolved. If you use 'de' for example, it adds 'deu' and 'ger' codes too.

I plan to add a config, but first I'll add one or two more subtitle servers. Until then you can use an alias.

@swanson:
Great custom action, I didn't know you can do that so easily. I'll add it to github wiki.

@z0id:
I am using the same packages as swanson and it builds fine. Which version of vala and libsoup are you using?

Last edited by billy (2011-08-10 13:47:31)

Offline

#7 2011-08-11 17:02:40

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: submarine - Search and download subtitles

billy wrote:

Exit status is now 0 if all went OK, 1 if no files were saved or overwritten (program had no effect) and 2 if there was invalid input.


I'm trying to build a script to call from Thunar but how do you define 'Invalid input'.
Or to be more exact; what can an invalid avi-file be to generate exit code 2?

Last edited by swanson (2011-08-11 17:19:34)

Offline

#8 2011-08-11 17:53:36

billy
Member
From: Slovenia
Registered: 2006-09-13
Posts: 164

Re: submarine - Search and download subtitles

swanson wrote:
billy wrote:

Exit status is now 0 if all went OK, 1 if no files were saved or overwritten (program had no effect) and 2 if there was invalid input.


I'm trying to build a script to call from Thunar but how do you define 'Invalid input'.

I defined invalid input as when program is called with wrong flags, wrong parameters, filenames that do not exist, with no arguments (calling just 'submarine'),... In all of this cases program exits with ERROR message (except for 'submarine' which shows help). Basically 2 is for user error and 1 it's for program "error" (no subtitles saved).

But I think that I should change how 0 and 1 are returned, because now 0 is returned when _at_least_one_ subtitle was saved.
Maybe it would be better to return 0 only if _all_ were found and saved and the ones that weren't saved already existed (or in the case with '--force' if all were saved)?

Offline

#9 2011-08-19 11:24:19

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: submarine - Search and download subtitles

I can't praise submarine enough! Before you had to browse ugly sites with very messy filehandling, then rename the sub file.  Now it's all done in a blink of an eye!

I'm working further on my script and the exit codes could be very useful for showing osd messages. But I'd like some more explanation of them. Are they; 0  = success, 1 = not found, 2 = error, wrong format etc?

Offline

#10 2011-08-30 00:56:50

billy
Member
From: Slovenia
Registered: 2006-09-13
Posts: 164

Re: submarine - Search and download subtitles

Sorry I didn't have time to respond in decent time.
I really like that you like my program smile.

Yes, the exit codes are as you described them, but they are dependant on the '-f' switch. For example if we pass arbitrary number of movies to program:
without -f:
  0: all movies have subtitles after program end
  1: not all movies have subtitles after program end (although some may have been downloaded)
  2: error, wrong input,...
with -f:
  0: all subtitles were found and saved/replaced
  1: not all subtitles were found and saved/replaced
  2: error, wrong input,...
If I happen to change exit codes I'll report it in this thread.

Also I released new version (0.1.1), because Podnapisi.net support was added!

Offline

#11 2011-08-30 08:11:53

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: submarine - Search and download subtitles

Great work! Here's my present separate script called from Thunar;

#!/bin/bash
submarine -l swe $1
message1="$?"
if [[ "$message1" == "0" ]]; then
message2="Downloaded sub $1"
icon="icon.png"
elif [[ "$message1" == "1" ]]; then
message2="No sub downloaded - maybe non existent"
icon="other_icon.png"
elif [[ "$message1" == "2" ]]; then
message2="Other error"
icon="icon_3.png"
else
message2="weird error !!! " 
icon="yet_another_icon.png"


fi

notify-send -i $icon "Subtitle" "$message2"
exit 0

Yes, I'm no programmer. Who would have 'weird error' in their script? Any hints of translating submarine's exit codes to human readable strings are welcome!
PS Adjust the script to your needs, It's called from Thunar with: 'scriptname %n'. I guess it's easy to convert to a nautilus script.

PPS The new version compiles and work fine here!!

Last edited by swanson (2011-08-30 08:17:10)

Offline

#12 2012-01-13 09:52:23

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: submarine - Search and download subtitles

Just an update from a user; I'm still using this app almost daily and it still is one of the smallest and smartest apps I ever came across! I'd recommend it to any and all users of separate subtitle files!

@Billy; keep up the good work!

Offline

#13 2012-01-24 14:09:16

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: submarine - Search and download subtitles

New error;

error while loading shared libraries: libarchive.so.2:

when  trying to use submarine. I guess it has to do with recent system updates (pacman/libarchive).

Present file structure;

locate libarchive.so.
/usr/lib/libarchive.so.12
/usr/lib/libarchive.so.12.0.3
[mrmedia@mediadatorn ~]$ ls /usr/lib/libarchive.so.12
lrwxrwxrwx 1 root root 20 13 jan 17.53 /usr/lib/libarchive.so.12 -> libarchive.so.12.0.3

A symlink could fix it, but then I'll be banned from the forums.

EDIT: Ahh, reinstall fixed it!

Last edited by swanson (2012-01-24 14:12:34)

Offline

#14 2012-02-19 06:22:20

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: submarine - Search and download subtitles

Recently some problem has come up when trying to search for subs; the process hangs and the only log reference I can find is this;

Feb 19 06:43:51 localhost kernel: [79818.147646] Pid: 23880, comm: submarine Tainted: P           O 3.2.6-2-ck #1 System manufacturer System Product Name/M4N68T-M-V2
Feb 19 06:43:51 localhost kernel: [79818.147657] Process submarine (pid: 23880, ti=c6e08000 task=ef0f4100 task.ti=c6e08000)

It actually hangs everything and a reboot is the only way out.
Really don't like it!

Well, Google has it; "the taint state is set when a machine check exception (MCE) has been raised, indicating a hardware related problem has occurred."

And P means; "* P: A module with a Proprietary license has been loaded, i.e. a module that is not licensed under the GNU General Public License (GPL) or a compatible license. ..."

And M4N68T-M-V2 is my motherboard. Very strange that submarine should initiate this, although the video file is on a NFS file server?

Last edited by swanson (2012-02-19 06:32:03)

Offline

#15 2012-02-19 10:23:28

billy
Member
From: Slovenia
Registered: 2006-09-13
Posts: 164

Re: submarine - Search and download subtitles

Wow, this is really bad.
I'm not sure if this is a bug in my program, because i'm not running in kernel-space, but it sure looks like it triggers it. I will try to reproduce it here, but I'm afraid it's hardware dependant.

What is the last output written by submarine before the crash?
Try updating the whole system and recompiling submarine, then try triggering the bug again (I guess you already tried this, but I'm writing it in case you didn't).
Does a crash happen on any parameters passed to submarine? Could you please try running the following commands (locally and then over NFS):

  $ submarine -v -h
  $ submarine -v -s os file.avi
  $ submarine -v -s pn file.avi

I will try to add some debug messages to program (as soon as I can), so pinpointing the bugs will be easier.

Offline

#16 2012-02-19 13:15:22

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: submarine - Search and download subtitles

Will do. Back shortly.

Offline

#17 2012-02-19 14:02:04

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: submarine - Search and download subtitles

After reinstall no changes. Same error message in logs and no ouput from submarine, even with -v option. Works ok locally. So it might be something on the server side, but NFS is untouched there since a long time. Everything else is ok server side, like ssh, nfs file transfers and so on.

Offline

#18 2012-02-19 14:56:09

billy
Member
From: Slovenia
Registered: 2006-09-13
Posts: 164

Re: submarine - Search and download subtitles

I've successfully recreated the bug on my machine. I've created a NFSv4 share and after running submarine on some file on it, it crashed the program. Luckily in my case it didn't crash the kernel (and submarine outputed some text), so it will be easier to debug.

swanson, thank you for reporting this problem. I'll report back here when I fix this.

Offline

#19 2012-02-19 15:19:52

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: submarine - Search and download subtitles

I just booted another kernel (3.0.0.16) on the (ubuntu) server and submarine worked! So it seems to be some problem with the 3.0.0.16 server/nfs. Thats the only major change I've made lately. Before this submarine has been working nice a long time with the video files on the nfs server (kernel 2.6.38).

(The server WILL get Arch some day)

Offline

#20 2012-02-19 15:49:15

billy
Member
From: Slovenia
Registered: 2006-09-13
Posts: 164

Re: submarine - Search and download subtitles

Glad to hear that it's working smile.
So then this could be a bug in nfs or recent kernel. I'll try to locate what code from submarine triggers it and report it upstream.

Offline

#21 2012-02-19 16:16:08

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: submarine - Search and download subtitles

Thanks for the effort! Great work!

Offline

#22 2012-02-26 20:27:54

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: submarine - Search and download subtitles

Very nice piece of code! I love it, thanks! big_smile


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#23 2012-03-08 16:30:20

Revelation60
Member
From: The Netherlands
Registered: 2009-03-19
Posts: 158
Website

Re: submarine - Search and download subtitles

Great package! smile

Offline

#24 2012-03-08 22:59:24

kevin89
Arch Linux f@h Team Member
From: Netherlands
Registered: 2007-03-14
Posts: 218

Re: submarine - Search and download subtitles

I've been looking for something like this for ages! CouchPotato is fetching my movies for Sabnzbd to download already, which is good. But then the subtitle hunt begins.... Have run your app and it worked for ~30 movies, which is great! Unfortonately, I still have ~130 movies for which no (english or dutch) subtitle could be found.

I see more services are on the top of your to do list, so I'll look forward to that! smile

Once more, great contribution!

Last edited by kevin89 (2012-03-08 22:59:46)

Offline

#25 2012-03-20 20:07:39

theGunslinger
Member
Registered: 2011-05-20
Posts: 300

Re: submarine - Search and download subtitles

Another thumbs up for this great contribution. Rock on!

Offline

Board footer

Powered by FluxBB