]> gitweb @ CieloNegro.org - youtube-dl.git/commitdiff
Merge pull request #5588 from aajanki/encode_frag_filenames
authorSergey M. <dstftw@gmail.com>
Sun, 30 Aug 2015 20:18:15 +0000 (02:18 +0600)
committerSergey M. <dstftw@gmail.com>
Sun, 30 Aug 2015 20:18:15 +0000 (02:18 +0600)
[f4m] Fix encode error by sanitizing fragment filenames

1  2 
youtube_dl/downloader/f4m.py

index 275564b5976b9d28a7d67f839c81467029aa5c18,3cb07e15f2896e99f958576905a39401c7547056..f478fc03cda121698611f1474d37c7448465597f
@@@ -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
                      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