some py3 fixes, both needed and recommended; we should pass 2to3 as cleanly as possib...
[youtube-dl] / youtube_dl / FileDownloader.py
index a861086c3c8a70fa072100d9b83fe8a4ceec397d..d9a4ecd3a99c2127105d5ce3f87a4fe038fa1040 100644 (file)
@@ -433,11 +433,8 @@ class FileDownloader(object):
             try:
                 srtfn = filename.rsplit('.', 1)[0] + u'.srt'
                 self.report_writesubtitles(srtfn)
-                srtfile = open(encodeFilename(srtfn), 'wb')
-                try:
-                    srtfile.write(info_dict['subtitles'].encode('utf-8'))
-                finally:
-                    srtfile.close()
+                with io.open(encodeFilename(srtfn), 'w', encoding='utf-8') as srtfile:
+                    srtfile.write(info_dict['subtitles'])
             except (OSError, IOError):
                 self.trouble(u'ERROR: Cannot write subtitles file ' + descfn)
                 return