X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2FFileDownloader.py;h=ebc2552dfc0933306a2e50b1e4a9b0bc8e501270;hb=0214ce7c7584bd27c6e175065e3991d97af05855;hp=e8c62ce07adbff3b10942c0d21700b06592bdad1;hpb=993693aa796fa2d50e0ce3cc7b0d551ffcc4a786;p=youtube-dl diff --git a/youtube_dl/FileDownloader.py b/youtube_dl/FileDownloader.py index e8c62ce07..ebc2552df 100644 --- a/youtube_dl/FileDownloader.py +++ b/youtube_dl/FileDownloader.py @@ -421,11 +421,8 @@ class FileDownloader(object): try: descfn = filename + u'.description' self.report_writedescription(descfn) - descfile = open(encodeFilename(descfn), 'wb') - try: - descfile.write(info_dict['description'].encode('utf-8')) - finally: - descfile.close() + with io.open(encodeFilename(descfn), 'w', encoding='utf-8') as descfile: + descfile.write(info_dict['description']) except (OSError, IOError): self.trouble(u'ERROR: Cannot write description file ' + descfn) return @@ -436,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 @@ -449,14 +443,8 @@ class FileDownloader(object): infofn = filename + u'.info.json' self.report_writeinfojson(infofn) try: - json.dump - except (NameError,AttributeError): - 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) + json_info_dict = dict((k, v) for k,v in info_dict.items() if not k in ['urlhandle']) + write_json_file(json_info_dict, encodeFilename(infofn)) except (OSError, IOError): self.trouble(u'ERROR: Cannot write metadata to JSON file ' + infofn) return @@ -505,6 +493,10 @@ class FileDownloader(object): # Extract information from URL and process it videos = ie.extract(url) + + if len(videos or []) > 1 and self.fixed_template(): + raise SameFileError(self.params['outtmpl']) + for video in videos or []: video['extractor'] = ie.IE_NAME try: