1

(A same question is available in Stackoverflow. But that didn't help me because it used other function)

API Documentation

Hello, I am trying to implement Opensubtitle API with Python. I prefer trying to search subtitle file with hash, because it's accurate.

As I have never used xmlrpc before and quite new to using APIs, I had to study to make it work. But I am stuck at the final point. My program is returning Status 200 (OK), but the 'data' array is blank. I think, I am doing something wrong with the paramater passing thing. The code is here:

from xmlrpclib import ServerProxy
import hashCheck, os

server = 'http://api.opensubtitles.org/xml-rpc'

class MainEngine(object):

    def __init__(self, language="None"): 
        self.rpc = ServerProxy(server, allow_none=True)

        user_agent = 'OSTestUserAgentTemp'
        self.Start()

    def getToken(self):
        self.logindata = self.rpc.LogIn(None, None, "en", "OSTestUserAgentTemp")
        self.Token = self.logindata["token"]
        return self.Token

    def subSearch(self, path):
        self.hash = hashCheck.hash(self.path)
        token = self.getToken()
        self.param = [
            token, # token
            [
                'eng', # sublanguageid
                self.hash, #hash
                os.path.getsize(path), # byte size 
            ]
        ]
        Obj = self.rpc.SearchSubtitles(token, self.param)
        print Obj

    def Start(self):
        # print server
        self.path = "E:\Movies\English\Captain Phillips\Captain Phillips.mp4"
        self.subSearch(self.path)

def main():
    MainEngine()

if __name__ == '__main__':
    main()
2
  • first: add link to documetation. second: you can use print() to see what you have in variable and what exactly you send, and then you can compare with documentation.
    – furas
    Nov 18, 2016 at 5:19
  • I know what I am sending in variables, but I am not sure if the array structure is correct. Documentation added @furas Nov 18, 2016 at 5:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.