Saturday, December 11, 2010

How to use Subdowloader on a Mac

SubDownloader is a very convenient tool to download subtitles files for movies or TV shows. However, it does not work well on Macs. The latest official build for Mac  (2.0.9.3) uses some obsolete  APIs to interact with www.opensubtitles.org and it no longer works. Building directly from the latest source tarball (2.0.13) will hit the infamous dependency hell because of its reliance on the QtPy.

Recently I found another way to use SubDownloader on Macs.  Instead of resolving the dependency issues on Macs, I just gave upon using the graphical interface of SubDowloader and made it work for the command line only; then I used Automator to build a service so that it could download subtitles by right clicking a file or folder from Finder and choose Download Subtitles in the popup menu. It turned out to work very well.

Procedures to install SubDownloader on a Mac:
  1. Download SubDownloader source tarball and decompress it.
  2. Open terminal and patch a bug in subdownloader-2.0.14
    • $ sed -i.bak 's/subtitle = video\.getOneSubtitle()/subtitles = video.getOnlineSubtitles()[0]/' ~/Downloads/subdownloader-2.0.14/modules/filter.py
  3. Download kaa-base and kaa-metadata from http://sourceforge.net/projects/freevo/files/ and decompress them.
  4. Install Xcode if you haven't done that.
  5. Open terminal and type the following commands.
    • $ sudo python setup.py install
    • $ cd Downloads/
    • $ sudo python setup.py install
    • $ cd ../kaa-medata-0.7.7/src/disc/
    • $ curl -O http://cddb-py.sourceforge.net/CDDB/unix/cdrommodule.c
    • $ cd ../..
    • $ sudo python setup.py install
  6. Create a service using Automator
    • Open Automator.
    • Click the "Service" icon and then click "Choose" button on the bottom.
    • Choose "files and Folders" and "Finder" on the list boxes right of the text "Service receives selected".
    • Drag "Run Shell Script" from the list of actions into the workflow window.
    • Select "/usr/bin/python" and paste the following script into script window; change the text "/Users/myname/Downloads/subdownloader-2.0.14" in the script to the folder which you place the subdownloader files.
    import os,sys
    if __name__ == '__main__':
      paths = []
      for i in range(1,len(sys.argv)):
        paths.append(os.path.realpath(sys.argv[i]))
    
      os.chdir("%s/Downloads/subdownloader-2.0.14" %(os.environ["HOME"]))
      for x in paths:
        os.system("./run.py -c -D -l en --rename-subs -V  \"%s\"" % x)
    
  7. Save the workflow with the name "Download Subtitles"