Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to take the first download 'str' zip link. I don't need more than one file of information. When I tried a not famous movie such as Shame 2011 My code worked but when I tried Avatar doesn't work. I think the code trying to take a lot of 'str' files information, API after that blocks this request.

**How I can reach the first English str file download link? **

from xmlrpc.client import ServerProxy
from pprint import pprint

imdb='tt0499549'#-->Avatar
#'tt1723811'-->Shame 2011

server = ServerProxy("http://api.opensubtitles.org/xml-rpc")
token = server.LogIn('yourusername', 'yourpassword', 'eng', 'TemporaryUserAgent')['token']
response = server.SearchSubtitles(token, [{'sublanguageid': 'eng', 'query':imdb }])#'moviehash':"0"
pprint(response) 

You only have five attempts with TemporaryUserAgent.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
162 views
Welcome To Ask or Share your Answers For Others

1 Answer

Check out opensubtitle's new API - here's the documentation. It's way easier to use than the older API.

Grabbing subtitles is as easy as

    headers = {
        'Api-Key': api_key,
    }

    params = (
        ('imdb_id', movie_id),
    )

    response = requests.get('https://www.opensubtitles.com/api/v1/subtitles', headers=headers, params=params)

Where api_key is your api_key from their website, and movie_id is the movie's IMDB id (e.g., Titanic's ID is 0120338, and can be found within the URL of its movie page on IMDb - https://www.imdb.com/title/tt0120338/)

An example of the response returned looks like this:

{'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:
Hi: https://www.opensubtitles.org/en/subtitles/7436082/avengers-infinity-war-en
No 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'}]}}

To download a file you would take the 'file_id' and input it into a download request to the Open Subtitle API like this:

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

data = '{"file_id":5274788}'

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

Where auth is the authorization key you get from their API (/api/v1/login endpoint):

headers = {
   'Api-Key': api_key,
   'Content-Type': 'application/json',
}
    
data = '{"username":"__USERNAME","password":"__PASSWORD"}'

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

and __USERNAME and __PASSWORD is your account's username and password.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...