Python: How to get data from chunks of file over xml-rpc

974 views Asked by At

I am creating a software for downloading movie subtitles using OpenSubtitle API in Python.

The API implements XML-RPC protocol. According to API documentation, to download a subtitle from site database, the following method is used:

array DownloadSubtitles( $token, array($IDSubtitleFile, $IDSubtitleFile,...) )

Its output is:

[data] => Array
    (
        [0] => Array
            (
                [idsubtitlefile] => 10
                [data] => MQ0KMDA6MDA6MzgsMzAwIC0tPiAwMDowMDo0MSwwMDA...
            )
        [1] => Array
            (
                [idsubtitlefile] => 20
                [data] => MQ0KMDA6MDA6MjYsMjgzIC0tPiAwMD...
            )

Where [idsubtitlefile] is subtitle_id and [data] is subtitle byte in base64 and gzip form.

The problems I am facing is, whenever I download a subtitle:

idsubtitlefile='513de0ea27d63b9d631d769a492d72dc'
token='a1t49trievitmjda4ija7dif44'
xmlrpclib.DownloadSubtitles(token,[(idsubtitlefile)] )

I get a result like this:

[{'data': 'H4sIAAAAAAAAAwMAAAAAAAAAAAA=',\      
   'idsubtitlefile':'513de0ea27d63b9d631d769a492d72dc'}] 

Here, the data value is supposed to be base64 encoded binary subtitle data, but how can so little data be the subtitle.

I think somehow the data has to be download from server in chunks, or perhaps I am missing something.

1

There are 1 answers

0
Glenn On BEST ANSWER

Just to amplify @Martijn's comment a little - the response is indeed an empty file, which you can verify using code like this:

>>> raw = 'H4sIAAAAAAAAAwMAAAAAAAAAAAA='
>>> import base64
>>> decoded = base64.b64decode(raw)
>>> import zlib
>>> decompressed_data=zlib.decompress(decoded, 16+zlib.MAX_WBITS)
>>> print decompressed_data

>>> len(decompressed_data)
0

There is nothing to suggest anything more is required of you based on the API doc. Can you retry with an example that is known to have a subtitle? Are you checking for errors? http://trac.opensubtitles.org/projects/opensubtitles/wiki/XmlRpcStatusCode

EDIT: There are some open source Python API users listed here in case they are helpful: http://trac.opensubtitles.org/projects/opensubtitles/wiki/ProgramsUsingAPI