opensubtitles-api
OpenSubtitles.org API wrapper for downloading and uploading subtitles, helping to communicate with the OpenSubtitles XML-RPC API using Node.js
In addition of allowing to use all available methodCalls asynchronously, it also allows you to directly use powerfull custom calls, like:
search
: Chained function returning the best matching subtitles based on the information you can feed it.upload
: Chained function requiring only the path to the video and to the subtitle files to send new subtitles to OpenSubtitles.org (flow: LogIn > TryUploadSubtitles > UploadSubtitles)hash
: Function returning Hash and Byte size for a given videomd5
: Function returning Hash for a given subtitleidentify
: Chained function returning metadata based on video file hash
Read index.js for more info on the custom calls.
More complete docs are available.
This module requires a valid UserAgent.
Quick start
npm install opensubtitles-api
Then:
const OS = ;const OpenSubtitles = useragent:'UserAgent' username: 'Username' password: 'Password' ssl: true;
You can omit username and password to use OpenSubtitles.org anonymously (not all methods are available)
You can omit the endpoint to use HTTP default OpenSubtitles API endpoint: http://api.opensubtitles.org:80/xml-rpc
SSL: default value is 'false', set to true to use https. This parameter gets overwritten by any custom endpoint
NOTE: 'Password' can be a MD5 encrypted string, OpenSubtitles accept these. It is recommended to use it. You can get the MD5 of a PASSWORD string by doing: require('crypto').createHash('md5').update(PASSWORD).digest('hex');
Examples:
A simple login:
OpenSubtitles ;
NOTE: The login()
call is useful to verify "Username" and "Password" (if you get a token, you're authentified, as simple as that), but is never needed for the custom calls (search, upload), they're made by the module itself. If you use raw xml-rpc call (OpenSubtitles.api.methodCall), prefer to login with the raw OpenSubtitles.api.LogIn
Get in touch with OpenSubtitles.org API directly:
Example :
const OS = ;const OpenSubtitles = 'UserAgent'; OpenSubtitlesapithen...
Methods available through the extended OpenSubtitles.api.<method>
call:
- LogIn
- LogOut
- SearchSubtitles
- SearchToMail
- CheckSubHash
- CheckMovieHash
- CheckMovieHash2
- InsertMovieHash
- TryUploadSubtitles
- UploadSubtitles
- DetectLanguage
- DownloadSubtitles
- ReportWrongMovieHash
- ReportWrongImdbMovie
- GetSubLanguages
- GetAvailableTranslations
- GetTranslation
- GetUserInfo
- SearchMovieOnIMDB
- GetIMDBMovieDetails
- GuessMovieFromString
- InsertMovie
- SubtitlesVote
- GetComments
- AddComment
- AddRequest
- SetSubscribeUrl
- SubscribeToHash
- AutoUpdate
- SuggestMovie
- QuickSuggest
- NoOperation
- ServerInfo
NOTE: All methods should be supported. You can consult ./lib/opensubtitles.js
for the list of available calls and the required parameters.
Search the best subtitles in all languages for a given movie/episode:
OpenSubtitles;
NOTE: No parameter is mandatory, but at least one is required. The more possibilities you add, the best is your chance to get the best matching subtitles in a large variation of languages. I don't recommend ever using "query", as it is highly error-prone. *sublangageid is a 3 letters langcode (ISO 639-2 based)
Here's how the function prioritize:
- Hash + filesize (or Path, that will be used to calculate hash and filesize)
- Filename
- IMDBid (+ Season and Episode for TV Series)
The function internally ranks the subtitles to get the best match given the info you provided. It works like this:
matched by 'hash' and uploaded by:
+ admin|trusted 12
+ platinum|gold 11
+ user|anon 8
matched by tag and uploaded by:
+ admin|trusted 11
+ platinum|gold 10
+ user|anon 7
matched by imdb and uploaded by:
+ admin|trusted 9
+ platinum|gold 8
+ user|anon 5
matched by other and uploaded by:
+ admin|trusted 4
+ platinum|gold 3
+ user|anon 0
bonus of fps matching if:
+ nothing matches 2
+ imdb matches 0.5
Upload a subtitle:
OpenSubtitles ;
NOTE: Only subpath
is mandatory. However, it is highly recommended to also provide path
and imdbid
to make sure you can add a subtitle even if the movie isn't already in the database.
Optionnal parameters are self-explanatory:
- sublanguageid // subtitle is in which language?
- highdefinition // is for HD versions
- hearingimpaired // subtitle contains written description of sounds
- moviereleasename // title of the release, usually the filename without extension
- movieaka // alternate title, for example in another language
- moviefps // frames par second
- movieframes // total number of frames in the video
- movietimems // total duration in milliseconds
- automatictranslation // the subtitle was translated by a machine, eg. Google Translate
- subauthorcomment // commentary from the author
- subtranslator // subtitle was translated by?
- foreignpartsonly // subtitle only contains translation for non-native language, example: only the elvish and Ork in 'The Lord of the Ring', not the english.
Use gzipped subtitles:
Using gzipped subtitles can reduce load on opensubtitles and enhance everyone's experience.
Example: download the best matching subtitle in french, unzip it and display the subtitle.
const OpenSubtitles = ;const OS = 'OSTestUserAgent';OS;
Extract Hash & MovieByteSize
OpenSubtitleshash'path/to/file.mp4' ;
Get metadata from Hash
OpenSubtitles
Notes:
If you're logging in anonymously by default and want to update the module with a username/password for the future, just throw in a new new OpenSubtitle({})
with the right object. Same thing to switch endpoint or http/https.
License
The MIT License (MIT)
- Copyright (c) 2015-2017 Jean van Kasteel vankasteelj@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.