emericg / OpenSubtitlesDownload

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

UnicodeDecodeError: fix #22

Closed pauloup closed 6 years ago

pauloup commented 7 years ago

Hi, I tried the last version 3.5 on Ubuntu Gnome 16.04 and it gave me this fatal error:

paulo@paulo-Aspire-5742 ~/.l/s/n/scripts> 
./OpenSubtitlesDownload.py "/mnt/Backup/Movies/The Great Gatsby (2013)/The.Great.Gatsby.2013.720p.BluRay.x264.YIFY.mp4"
Traceback (most recent call last):
  File "./OpenSubtitlesDownload.py", line 604, in <module>
    subtitlesSelected = selectionGnome(subtitlesList)
  File "./OpenSubtitlesDownload.py", line 225, in selectionGnome
    subtitlesItems += '"' + item['SubFileName'] + '" '
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 57: ordinal not in range(128)

So I found out that including these two lines on the beginning of the code just fix the problem:

reload(sys)  
sys.setdefaultencoding('utf8') 

Here's my modified version: http://pasteall.org/153473/python

GRMajestic commented 7 years ago

Hello all, Just a request, can you add a function which will check if the subtitles are already in place? This will a nice functionality for automated scripts.

Looking forward to your feedback.

emericg commented 7 years ago

Hi. @pauloup I'm not familiar with your issue and I never really had an encoding problem. Can it be related to your system encoding not being UTF8 or your file title / path having non ASCII char in them? I found this link (http://stackoverflow.com/questions/28657010/dangers-of-sys-setdefaultencodingutf-8) talking about it so I'll think about forcing a local inside the script.

@GRMajestic sure, but can you open a new issue and talk a bit more about the specific of your use case so we can define a proper feature?