From: Sergey M. Date: Sun, 30 Aug 2015 20:18:15 +0000 (+0600) Subject: Merge pull request #5588 from aajanki/encode_frag_filenames X-Git-Url: http://git.oshgnacknak.de/?a=commitdiff_plain;h=55801fc76e2813de9a84eaa830d70ed73cb44463;p=youtube-dl Merge pull request #5588 from aajanki/encode_frag_filenames [f4m] Fix encode error by sanitizing fragment filenames --- 55801fc76e2813de9a84eaa830d70ed73cb44463 diff --cc youtube_dl/downloader/f4m.py index 275564b59,3cb07e15f..f478fc03c --- a/youtube_dl/downloader/f4m.py +++ b/youtube_dl/downloader/f4m.py @@@ -338,23 -391,24 +338,24 @@@ class F4mFD(FragmentFD) url += '?' + akamai_pv.strip(';') if info_dict.get('extra_param_to_segment_url'): url += info_dict.get('extra_param_to_segment_url') - frag_filename = '%s-%s' % (tmpfilename, name) + frag_filename = '%s-%s' % (ctx['tmpfilename'], name) try: - success = http_dl.download(frag_filename, {'url': url}) + success = ctx['dl'].download(frag_filename, {'url': url}) if not success: return False - with open(frag_filename, 'rb') as down: - down_data = down.read() - reader = FlvReader(down_data) - while True: - _, box_type, box_data = reader.read_box_info() - if box_type == b'mdat': - dest_stream.write(box_data) - break + (down, frag_sanitized) = sanitize_open(frag_filename, 'rb') + down_data = down.read() + down.close() + reader = FlvReader(down_data) + while True: + _, box_type, box_data = reader.read_box_info() + if box_type == b'mdat': + dest_stream.write(box_data) + break if live: - os.remove(frag_filename) + os.remove(encodeFilename(frag_sanitized)) else: - frags_filenames.append(frag_filename) + frags_filenames.append(frag_sanitized) except (compat_urllib_error.HTTPError, ) as err: if live and (err.code == 404 or err.code == 410): # We didn't keep up with the live window. Continue @@@ -372,9 -426,20 +373,9 @@@ msg = 'Missed %d fragments' % (fragments_list[0][1] - (frag_i + 1)) self.report_warning(msg) - dest_stream.close() + self._finish_frag_download(ctx) - elapsed = time.time() - start - self.try_rename(tmpfilename, filename) for frag_file in frags_filenames: - os.remove(frag_file) + os.remove(encodeFilename(frag_file)) - fsize = os.path.getsize(encodeFilename(filename)) - self._hook_progress({ - 'downloaded_bytes': fsize, - 'total_bytes': fsize, - 'filename': filename, - 'status': 'finished', - 'elapsed': elapsed, - }) - return True