Search code examples
python-3.xrestsubtitle

Open Subtitle's REST API POST /api/v1/download


I read the documentation from Opensubtitle's new API here and am receiving a 500 error when trying to reach the Download endpoint. I have success with other endpoints including /api/v1/login and also /api/v1/subtitles.

Here's the data in JSON format I'm trying to request

{'id': '5164746',
 'type': 'subtitle',
 'attributes': {'subtitle_id': '5164746',
  'language': 'en',
  'download_count': 9608,
  'new_download_count': 46,
  'hearing_impaired': False,
  'hd': True,
  'format': None,
  'fps': 23.976,
  'votes': 0,
  'points': 0,
  'ratings': 0.0,
  'from_trusted': False,
  'foreign_parts_only': False,
  'auto_translation': False,
  'ai_translated': False,
  'machine_translated': None,
  'upload_date': '2020-02-09T13:59:42Z',
  'release': '2160p.4K.BluRay.x265.10bit.AAC5.1-[YTS.MX]',
  'comments': "Slightly resynced the 1080p.WEBRip.x264-[YTS.LT] version by explosiveskull to this 4K release. HI removed. I didn't do 4K sync for Infinity War, as they're already on site here:\r\nHi: https://www.opensubtitles.org/en/subtitles/7436082/avengers-infinity-war-en\r\nNo HI: https://www.opensubtitles.org/en/subtitles/7436058/avengers-infinity-war-en",
  'legacy_subtitle_id': 8092829,
  'uploader': {'uploader_id': 66694,
   'name': 'pooond',
   'rank': 'bronze member'},
  'feature_details': {'feature_id': 626618,
   'feature_type': 'Movie',
   'year': 2019,
   'title': 'Avengers: Endgame',
   'movie_name': '2019 - Avengers: Endgame',
   'imdb_id': 4154796,
   'tmdb_id': 299534},
  'url': 'https://www.opensubtitles.com/en/subtitles/legacy/8092829',
  'related_links': {'label': 'All subtitles for Avengers: Endgame',
   'url': 'https://www.opensubtitles.com/en/movies/2019-untitled-avengers-movie',
   'img_url': 'https://s9.osdb.link/features/8/1/6/626618.jpg'},
  'files': [{'file_id': 5274788,
    'cd_number': 1,
    'file_name': 'Avengers.Endgame.2019.2160p.4K.BluRay.x265.10bit.AAC5.1-[YTS.MX].srt'}]}}

Here's the request that I'm sending:

headers = {
    'Api-Key': api_one,
    'Authorization': auth,
    'Content-Type': 'application/json',
}

data = '{"file_id":5274788,"sub_format":"srt","file_name":"Avengers.Endgame.2019.2160p.4K.BluRay.x265.10bit.AAC5.1-[YTS.MX]","strip_html":true,"cleanup_links":true,"remove_adds":true,"in_fps":0,"out_fps":0,"timeshift":0}'


response = requests.post('https://www.opensubtitles.com/api/v1/download', headers=headers, data=data)

Has anyone else had success using the download endpoint from this API?


Solution

  • Looks like there was an error with some of the parameters above. Here's a link to the documentation. Updated the data parameter of the post request to just include the file_id.

    data = '{"file_id":5274788}'
    response = requests.post('https://www.opensubtitles.com/api/v1/download', headers=headers, data=data)