emericg / OpenSubtitlesDownload

Automatically find and download the right subtitles for your favorite videos!
https://emeric.io/OpenSubtitlesDownload
GNU General Public License v3.0
579 stars 63 forks source link

LookupError on line 855 if subEncoding is "Unknown" #99

Closed data-flux closed 6 months ago

data-flux commented 10 months ago

If the SubEncoding is given as "Unknown" (I suppose this happens if OpenSubtitles does not have the correct metadata? Happened for me with Flight of the Conchords S01E02) then a LookupError will be thrown by:
decodedStr = str(decompressed, subEncoding, 'replace')

I fixed it with the chardet library:

if subEncoding=="Unknown":
    import chardet
    subEncoding = chardet.detect(decompressed)['encoding']

But this adds another dependency and might not be ideal.

I do have opt_force_utf8 set, but this does not seem to make a difference.

emericg commented 6 months ago

The v6 version with the new opensubtitles.com always download subtitles in UTF8 encoded format, and the code you mention is not in the script anymore.

Feel free to reopen an issue if similar problems (related to subtitles encoding) are found with the new provider.