Fix filename sanitation (Closes #555)
authorPhilipp Hagemeister <phihag@phihag.de>
Tue, 27 Nov 2012 17:27:46 +0000 (18:27 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Tue, 27 Nov 2012 17:27:46 +0000 (18:27 +0100)
youtube_dl/FileDownloader.py

index bd0f7577369bb9afbbb5bec497e765f63dc5a2d8..d7d5b1521ec72ea46782064f3c6fadd3d5032cb7 100644 (file)
@@ -327,8 +327,10 @@ class FileDownloader(object):
                """Generate the output filename."""
                try:
                        template_dict = dict(info_dict)
-                       template_dict['epoch'] = unicode(int(time.time()))
-                       template_dict['autonumber'] = unicode('%05d' % self._num_downloads)
+                       template_dict['epoch'] = int(time.time())
+                       template_dict['autonumber'] = u'%05d' % self._num_downloads
+
+                       template_dict = dict((k, sanitize_filename(compat_str(v), self.params.get('restrictfilenames'))) for k,v in template_dict.items())
                        filename = self.params['outtmpl'] % template_dict
                        return filename
                except (ValueError, KeyError), err:
@@ -368,7 +370,6 @@ class FileDownloader(object):
                                raise MaxDownloadsReached()
 
                filename = self.prepare_filename(info_dict)
-               filename = sanitize_filename(filename, self.params.get('restrictfilenames'))
 
                # Forced printings
                if self.params.get('forcetitle', False):