diff options
author | Philipp Hagemeister <[email protected]> | 2012-12-17 19:48:10 +0100 |
---|---|---|
committer | Philipp Hagemeister <[email protected]> | 2012-12-17 19:48:10 +0100 |
commit | ce4be3a91d5fe8f2970d00be5663a7aad12d2a6d (patch) | |
tree | acb41bb50ce211019361302a11072a8c2f2c73ff | |
parent | 80d3177e5c07c4970e7cebcf2b38dcdf1e289786 (diff) | |
download | youtube-dl-ce4be3a91d5fe8f2970d00be5663a7aad12d2a6d.tar.gz youtube-dl-ce4be3a91d5fe8f2970d00be5663a7aad12d2a6d.zip |
Remove some antipatterns and ensure that we always write the JSON file with UTF-8
-rw-r--r-- | youtube_dl/FileDownloader.py | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/youtube_dl/FileDownloader.py b/youtube_dl/FileDownloader.py index 61d3654e2..e8c62ce07 100644 --- a/youtube_dl/FileDownloader.py +++ b/youtube_dl/FileDownloader.py @@ -4,6 +4,7 @@ from __future__ import absolute_import import math +import io import os import re import socket @@ -453,12 +454,9 @@ class FileDownloader(object): self.trouble(u'ERROR: No JSON encoder found. Update to Python 2.6+, setup a json module, or leave out --write-info-json.') return try: - infof = open(encodeFilename(infofn), 'w') - try: - json_info_dict = dict((k, info_dict[k]) for k in info_dict if not k in ['urlhandle']) + with io.open(encodeFilename(infofn), 'w', 'utf-8') as infof: + json_info_dict = dict((k, v) for k,v in info_dict.items() if not k in ['urlhandle']) json.dump(json_info_dict, infof) - finally: - infof.close() except (OSError, IOError): self.trouble(u'ERROR: Cannot write metadata to JSON file ' + infofn) return |