python-opensubtitles icon indicating copy to clipboard operation
python-opensubtitles copied to clipboard

IndexError: list index out of range

Open mooseyoose opened this issue 4 years ago • 6 comments

Hi,

When I use the example provided, I get this error:

Traceback (most recent call last): File "subtitles.py", line 10, in <module> id_subtitle_file = data[0].get('IDSubtitleFile') IndexError: list index out of range

Any idea?

Thanks

mooseyoose avatar Nov 07 '20 20:11 mooseyoose

From what I can tell it looks like the search didn't return any items for your query, but didn't raise an error (which might be for a number of reasons. I don't remember how the api handles malformed queries).

If you try the query with a hash of "18379ac9af039390", and a size of 366876694 then you should get responses for fringe season 4 episode 3 if that helps you debug. This library provides a very thin wrapper in most cases so its easy to mistype the queries.

It's possible whatever you are trying to query for just returned no results as well.

CosmicHorrorDev avatar Nov 07 '20 20:11 CosmicHorrorDev

Thanks! I managed to get it working. I wasn't using the size variable properly.

I'm trying to get subtitles for the movie Joker 2019. But it's only returning 1 subtitle. Any idea why it can only find 1?

mooseyoose avatar Nov 07 '20 21:11 mooseyoose

If you're doing a search by an exact match then it's very possible that there is only one set of subtitles associated with that exact file (the api does limit to 5 results per query if you're using the default user agent, although I can't find the docs on that now). You could also try doing a full-text search with something like:

ost.search_subtitles([{"query": "Joker 2019"}])

Although this won't be as accurate as the exact match since the subtitles might not be aligned, or it may get some wrong results.

Like I mentioned before this library is a very thin wrapper, so the only reason I know these things is from opensubtitles' documentation, since I've been working on my own wrapper.

CosmicHorrorDev avatar Nov 07 '20 22:11 CosmicHorrorDev

If you're doing a search by an exact match then it's very possible that there is only one set of subtitles associated with that exact file (the api does limit to 5 results per query if you're using the default user agent, although I can't find the docs on that now). You could also try doing a full-text search with something like:

ost.search_subtitles([{"query": "Joker 2019"}])

Although this won't be as accurate as the exact match since the subtitles might not be aligned, or it may get some wrong results.

Like I mentioned before this library is a very thin wrapper, so the only reason I know these things is from opensubtitles' documentation, since I've been working on my own wrapper.

Sorry for the late reply. Your answer has been helpful and I've got it working. Do you know how to increase the limit from 5 in the API?

mooseyoose avatar Nov 27 '20 00:11 mooseyoose

It's listed here. Searches are limited to 5 results on the testing user agent which is the one that this library sets unless you provide a different value. I think 5 results are good enough for most people though, particularly when you are doing an exact file match. If you want more than 5 results you would have to register for your own user agent.

CosmicHorrorDev avatar Nov 27 '20 05:11 CosmicHorrorDev

If you want to keep asking questions then feel free to email me (It's listed under my profile). I'd rather not keep this thread going since the original issue was resolved since it can create noise for other people to sift through.

CosmicHorrorDev avatar Nov 27 '20 05:11 CosmicHorrorDev