Using the @OpenSubtitles API in C#
Open Subtitles is a great online resource for finding subtitles for movies online, and you can also interact with it programmatically using their XML-RPC API – but it’s quite complex, so it’s best to start with a pre-built library.
I went for this library on SourceForge – https://sourceforge.net/projects/opensubdotnet/
it had a demo console app that works out of the box, but you should register your own user agent with OpenSubtitles, so they know who you are.
I needed a two step process for my app – which you can download on iTunes here:
https://itunes.apple.com/gb/app/open-subtitles/id522825951?mt=8
The first was to make a search for movies by name; which you can do using the opensubdotnet library below;
OSDotNetSession session = OSDotNetSession.LogIn(“”, “”, “en”, “**YOUR USER AGENT HERE**”);
List<SearchSubtitleResult> List = session.SearchByQuery(Request.QueryString[“film”]);
Then, once you get that list of films, with language variations, you can ask the user to select one, you can get the download link at this stage, however, if you need to do any server processing of the subtitles, then you can’t just download this and unzip it, since OpenSubtitles will block your server for not being a human (a captcha)
But, I get the IMDB ID and Subtitle File at this stage, and pass it through to the next step
OSDotNetSession session = OSDotNetSession.LogIn(“”, “”, “en”, “**YOUR USER AGENT HERE**”);
List<SearchSubtitleResult> List = session.SearchByImdbId(strImdb);
SearchSubtitleResult selected = List.First(f => f.IDSubtitleFile == strSubtitleID);
MemoryStream mem = session.DownloadSubtitle(selected);
string strLang = selected.ISO639.ToLower();
Encoding enc = Encoding.GetEncoding(“iso-8859-1″);
if (strLang==”he”) enc = Encoding.GetEncoding(“iso-8859-8″);
if (strLang==”el”) enc = Encoding.GetEncoding(“iso-8859-7″);
if (strLang==”ar”) enc = Encoding.GetEncoding(“iso-8859-6”);
StreamReader sr = new StreamReader(mem,enc);
string strText = sr.ReadToEnd();
Note that you need to be careful with text encodings here. The text is not necessarily going to be in the latin (i.e. english) alphabet. So I have made exceptions here for Hebrew (he), Greek (el) and Arabic (ar). This should be extended for Chinese, Korean, Japanese, Russian, Thai, Hindu, Georgian etc., but if anyone wants to complete that list, please comment below.
I just discovered this site.I. I’ve always used SubScene, but your site wonderful and I’ll use your site first.
LikeLike