Forum rules
Under no circumstances is spamming or advertising of any kind allowed. Do not post any abusive, obscene, vulgar, slanderous, hateful, threatening, sexually-orientated or any other material that may violate others security. Profanity or any kind of insolent behavior to other members (regardless of rank) will not be tolerated. Remember, what you don’t find offensive can be offensive to other members. Please treat each other with the kind of reverence you’d expect from other members.
Failure to comply with any of the above will result in users being banned without notice. If any further details are needed, contact: “The team” using the link at the bottom of the forum page. Thank you.
watdafox
Posts: 27
Joined: Fri Aug 07, 2015 3:13 am

Questions about the API flow

Fri Aug 07, 2015 3:56 am

Hello,

I'm developping a node.js module for the XML API, to make easier downloading and uploading subtitles.

Code: Select all

var OS = require('mymodule'); var OpenSubtitles = new OS('UserAgent', 'Username', 'Password'); OpenSubtitles.search({ imdbid: 'tt000000', path: '/home/user/breakdance.avi' }).then(function (subtitles) { console.log('%s subtitles found', subtitles.length); }).catch(function (error) { console.error(error); });

The goal is to have a fully-featured wrapper, entirely asynchronous and easy-to-use.

But I have some question:

1) if a user is registered on OpenSubtitles.org as VIP, or some other account without ads, and that the API queries "SearchSubtitles" using a token linked to that premium account, will the response contain links to subtitles without ads? Or is it only by passing by "DownloadSubtitles" ? (the token is sent with SearchSubtitles, so it would make sense that the returned links are ad-free)

2) Why does login in as user: 'wzqkejqkzj' & password: 'iiiiiiii' with a fake UserAgent (say 'QJZHEJHJZ') work?

EDIT: I'm sorry to edit this so much, but when I find the answer by myself, I prefer to take the related questions out rather than making someone take time to answer something non-needed.

User avatar
oss
Site Admin
Posts: 5890
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: Questions about the API flow

Tue Aug 11, 2015 5:24 am

1. For now SearchSubtitles() returns "clean" links without ads for VIP, but further checks are done, when downloading subtitles, so even you pass clean link, you might get ad-supported subtitles. You can use standard HTTP download and not use XML-RPC download

2. for me it doesnt, I get: "[status] => 414 Unknown User Agent"

watdafox
Posts: 27
Joined: Fri Aug 07, 2015 3:13 am

Re: Questions about the API flow

Tue Aug 11, 2015 3:19 pm

I see, then my auth flow must be broken somehow. Because I get a token back when I use:

Code: Select all

var OS = require('opensubtitles-api'); var Os = new OS('HJJJJEZQK', 'eqizjekj', 'qjzkje'); Os.login() .then(function(token) { console.log(token) });
(that moment when you have to debug why you can bypass authentication without even trying to, lol)

watdafox
Posts: 27
Joined: Fri Aug 07, 2015 3:13 am

Re: Questions about the API flow

Tue Aug 11, 2015 6:39 pm

Regarding the auth, I figured it out. I was only checking for "response.token" and OpenSubtitles sends back a token even if the status is 414. I added a check for the status as well.

Thanks

watdafox
Posts: 27
Joined: Fri Aug 07, 2015 3:13 am

Re: Questions about the API flow

Wed Aug 12, 2015 12:52 am

Ok, I block on uploading subtitles. Somehow it always responds 403+402 (hash & content don't match + invalid srt format).

It must be the gzip+b64 encode. For unknown reason though, it seems to work perfectly on my end.

Could someone double-check these please:

- subtitle content (plain text): http://pastebin.com/raw.php?i=h8G6fmKa
- subtitle hash (md5): 0f12fd8aadb9496885b25a505cd5d9be
- gzip+b64 subcontent: http://pastebin.com/raw.php?i=ci59ZuGA

This is the code I'm using:

Code: Select all

fs.readFile(subpath, function (err, data) { if (err) reject(err); zlib.deflateRaw(data, function (err, buffer) { if (err) reject(err); resolve(buffer.toString('base64')); }); });
EDIT: finally I managed to upload something... it's zlib.deflate, not deflateRaw. For some reason, if I trust the docs on both node.js and OpenSubtitles, and compare with the results, I can manage to send gzipped+base64 encoded data only if gzipped with header.

User avatar
oss
Site Admin
Posts: 5890
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: Questions about the API flow

Wed Aug 12, 2015 9:22 am

good you solved it.

Well, we are using

http://php.net/manual/en/function.gzuncompress.php

for decompress...

it is opposite of

http://php.net/manual/en/function.gzcompress.php

from docs
Note:
This is not the same as gzip compression, which includes some header data. See gzencode() for gzip compression.


User avatar
oss
Site Admin
Posts: 5890
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: Questions about the API flow

Thu Aug 13, 2015 8:58 am

looks really great. I would add to docs that one have to register UserAgent with OpenSubtitles.org to use that module and link here:
http://trac.opensubtitles.org/projects/ ... vReadFirst

Also it would be great to have somewhere link directly to our website www.opensubtitles.org

thanks for great work.

watdafox
Posts: 27
Joined: Fri Aug 07, 2015 3:13 am

Re: Questions about the API flow

Thu Aug 13, 2015 4:17 pm

added to the todo list, thanks.

I have another question regarding UA though, doc says to avoid wierd versionning because it's matched by regex. So, is one of these UA better than the other:

- MyApp v0.3.8 => more easy to match, lacks hotfix and prerelease state
- MyApp v0.3.8-2 => more accurate atm
- MyApp v0.3.8-beta2 => our application will use that versionning in the future

User avatar
oss
Site Admin
Posts: 5890
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: Questions about the API flow

Thu Aug 13, 2015 5:05 pm

currently we are using this:

Code: Select all

if (preg_match('/(.*?)[\s_]+[vV]?(\d+(?:\.\d+)*)/', $useragent, $matches)) {
- user agent can be any string
- i can change regexp to match your versions, I think this can do:

Code: Select all

/(.*?)[\s_]+[v]?(\d+(?:[\.\d\-]|alpha|beta|pre|rc|ga|rtm)*)/i

watdafox
Posts: 27
Joined: Fri Aug 07, 2015 3:13 am

Re: Questions about the API flow

Thu Aug 13, 2015 8:24 pm

I based myself on http://semver.org/

------

I don't know the first think about php (it's what you're using, right?), but on nodejs you have "semver" module.

Example:

Code: Select all

semver = require('semver'); semver('0.3.8-rc1+20150813');
will output:

Code: Select all

Object { build: { 0: '20150813' } major: 0 minor: 3 patch: 8 prerelease: { 0: 'rc1' } raw: '0.3.8-rc1+20150813' version: '0.3.8-rc1' }
------

The regex you posted seem to work fine too, except for 1 part: it leaves a trailing '-' with 'UserAgent v0.3.8-LOL' for example.

User avatar
oss
Site Admin
Posts: 5890
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: Questions about the API flow

Fri Aug 14, 2015 8:57 am

ok my regexp match all of that, so I will update code.

"UserAgent v0.3.8-LOL" - is not according semver, right ?

Return to “Developing”

Who is online

Users browsing this forum: No registered users and 25 guests