Page 1 of 1

CORS ERROR: I can't download subtitle files.

Posted: Fri Nov 03, 2023 6:01 pm
by natsunasubi
Hello.
I'm using an API from JavaScript on the web.
Although I can use the API (api.opensubtitles.com) without any problems, I am no longer able to download subtitle files from www.opensubtitles.com using Javascript, which was previously possible.
It seems that the cause is that access-control-allow-origin, access-control-allow-methods and access-control-allow-headers are missing from the response header of the OPTIONS request.
I would be happy if you could fix it.

Thank you,

Re: CORS ERROR: I can't download subtitle files.

Posted: Fri Nov 03, 2023 11:32 pm
by oss
Hi

can not reproduce, can you send CURL example?
curl --request OPTIONS \
--url 'https://api.opensubtitles.com/api/v1/su ... 2ec4c341a2' \
--header 'Api-Key: <APIKEY>' \
--header 'User-Agent: <APP_NAME> v1.1'
response
< access-control-allow-methods: GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS
< access-control-allow-origin: *
< access-control-allow-headers: *
same for /download endpoint (and all other endpoints)

Re: CORS ERROR: I can't download subtitle files.

Posted: Sat Nov 04, 2023 8:19 am
by natsunasubi
Thank you for your reply.
I am sorry. There was a lack of explanation, and I was able to find out the cause.
The issue isn't with the API(api.opensubtitles.com) itself, but with downloading files from the URL it provides.
However, when I removed the Api-Key, Authorization, and X-User-Agent headers from the request, I was able to download it. This is because by using only commonly used headers, the browser (Chrome) sends the GET request directly instead of checking with an OPTIONS request.
The reason I couldn't download the file was because I added X-User-Agent etc. when downloading the file.

When an OPTIONS request occurs, it seems that an error occurs because the response from www.opensubtitles.com is missing necessary headers. (I was able to see it when I opened it directly in the browser, but for some reason a 404 was returned when I sent the OPTIONS request.)

curl -v -X OPTIONS \
--url 'https://www.opensubtitles.com/download/E1848123179276226103BD9C1E9E2FE7B0B9AD65AAF2D8637FE61085EDCA0ACC5FCCD22E3D9C9EAF242D2BE8CD72A1F1AA6FCF47B7C51C8B42B646CD071F9CF6AD96496296625538DF1332AA18500E36429D5C880DF0661970A43E129545BF25CA123EAF6EF064907A518DE2F13457D4264022761DF799D7E71AAFDF18B470F1DEBF929395EFEE27438DD0C7040FF068CAA94CD40159D30011E511DB39963B11CC0A880E8BB2B27CADE00C917E722304DB2C613362DEE419C6F48C2DEDFA8EDFCE1B7CD7CCDE3BEFD9CB808970991089F14A21A868824B42A40AB85488693409988F1B7E249B171142BBAE900315A1E2F2A9D41CD2B8C86B9804FF3DA863ECC18F838D74286D41F600C1A4A02F0ACE6F7BDE4A844C29A220BB66BA7031F3B18436E528159932E690E4AC99E5140669F9/subfile/%5BCrunchyroll%5D%20SPY%20x%20FAMILY%20S01E02%20SECURE%20A%20WIFE.eng.srt' \
-H 'Access-Control-Request-Method: GET' \
-H 'Access-Control-Request-Headers: x-user-agent' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'

Re: CORS ERROR: I can't download subtitle files.

Posted: Sat Nov 04, 2023 1:49 pm
by oss
now it is clear and it is fixed. Thank you for report!

Re: CORS ERROR: I can't download subtitle files.

Posted: Sat Nov 04, 2023 2:23 pm
by natsunasubi
Thank you for fixing it!
I confirmed that files can be downloaded even if I send the headers.