mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-31 14:45:14 +00:00 
			
		
		
		
	Correct JSON writing (Closes #596)
This commit is contained in:
		| @@ -454,9 +454,8 @@ 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: | ||||
|                 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) | ||||
|                 write_json_file(json_info_dict, encodeFilename(infofn)) | ||||
|             except (OSError, IOError): | ||||
|                 self.trouble(u'ERROR: Cannot write metadata to JSON file ' + infofn) | ||||
|                 return | ||||
|   | ||||
| @@ -3,6 +3,7 @@ | ||||
|  | ||||
| import gzip | ||||
| import io | ||||
| import json | ||||
| import locale | ||||
| import os | ||||
| import re | ||||
| @@ -175,6 +176,18 @@ else: | ||||
|         assert type(s) == type(u'') | ||||
|         print(s) | ||||
|  | ||||
| # In Python 2.x, json.dump expects a bytestream. | ||||
| # In Python 3.x, it writes to a character stream | ||||
| if sys.version_info < (3,0): | ||||
|     def write_json_file(obj, fn): | ||||
|         with open(fn, 'wb') as f: | ||||
|             json.dump(obj, f) | ||||
| else: | ||||
|     def write_json_file(obj, fn): | ||||
|         with open(fn, 'w', encoding='utf-8') as f: | ||||
|             json.dump(obj, f) | ||||
|  | ||||
|  | ||||
| def htmlentity_transform(matchobj): | ||||
|     """Transforms an HTML entity to a character. | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Philipp Hagemeister
					Philipp Hagemeister