Zone38 Presents...
Letters to the World

28-Jul-2010

Subtitles for Netflix, à la Python

Filed under: Programming — codeman38 @ 10:29 pm

So I just read this post by Josh Erickson in which he discovered a super-secret feature of Netflix’s web player: the ability to load an external subtitle file for any streaming video. This is huge— basically, after converting them to the proper format, you’re able to overlay subtitles from a site like OpenSubtitles over any of the many uncaptioned videos from Netflix.

Here’s the trick: Press Ctrl+Shift+Alt+M to display a secret diagnostic menu. One of the options shown there is “Load Custom DFXP File”, from which you can load a custom subtitle script in W3C Timed Text format.

But how do we get subtitles into this DFXP format? Well, in the link above, Josh Erickson took the time to write a Windows PowerShell script to convert SubRip files to that format, with all of the necessary quirks to make Netflix’s player recognize it (a harder task than one would think, as the parser is about as finicky as I sometimes can be).

That’s great… if you’re using Windows. But there’s a certain other platform that Netflix fully supports which isn’t able to run that script— at least not without installing Windows in a dual-boot partition or VM, anyway.

Thankfully, I’m also somewhat experienced in Python, which is natively supported in Mac OS X. And so, I decided to port the script to Python.

Here’s the Python version of srt2dfxp.

It’s a command-line-only script for now, much like Erickson’s original; run it without any parameters and it will let you know the syntax. For creating files for use with the Netflix player, the -n option is most important; this is the one that forces the output to use Netflix-specific formatting quirks. The -t option is also useful; it will add a delay of whatever number of seconds comes after -t, to allow for differences in starting time due to things like the Starz logo.

Here’s an example of how to use the program:

./srt2dfxp.py -n -t15 holygrail.srt holygrail.dfxp

will convert holygrail.srt to holygrail.dfxp in Netflix-compatible format, with a delay of 15 seconds added to all time stamps.

(And yes, I used that filename in the example for a reason. This is a Python script, after all! ^_~)

I’ve tested it, and it seems to work with streaming on my MacBook. Let me know if you experience any issues with it!

Edited to add: Two minor bug fixes that I’ve already worked in: convert & to & so Netflix doesn’t choke on ampersands in the output, and don’t crash on the UTF-8 byte order marker if it’s present.

Edited 2010/08/26: Updated to version 1.3. Fixed another stupid mistake– time offsets are no longer rounded to the nearest integer.

Edited 2010/09/30 to add: As David points out in comment #14 below, the XML output from Jubler works perfectly well with Netflix! I’ve just tested this, and confirmed it. This is extremely helpful for having to deal with subtitles with incorrect frame rates or non-SubRip subtitle formats, though you can use it as to convert correctly timed SRT files just as easily.

© 2001-2017 codeman38. Powered by WordPress.