Keep video IDs verbatim if possible (Closes #571)
[youtube-dl] / youtube_dl / FileDownloader.py
index 9dc3523e0e492c774fbaf277d560ab3a7a8993a2..c471cc16081d5ff40cd0898ba0149f346d6c574e 100644 (file)
@@ -1,6 +1,8 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 
+from __future__ import absolute_import
+
 import math
 import os
 import re
@@ -12,7 +14,7 @@ import time
 if os.name == 'nt':
     import ctypes
 
-from utils import *
+from .utils import *
 
 
 class FileDownloader(object):
@@ -332,8 +334,11 @@ class FileDownloader(object):
             template_dict['epoch'] = int(time.time())
             template_dict['autonumber'] = u'%05d' % self._num_downloads
 
-            template_dict = dict((key, u'NA' if val is None else val) for key, val in template_dict.items())
-            template_dict = dict((k, sanitize_filename(compat_str(v), self.params.get('restrictfilenames'))) for k,v in template_dict.items())
+            sanitize = lambda k,v: sanitize_filename(
+                u'NA' if v is None else compat_str(v),
+                restricted=self.params.get('restrictfilenames'),
+                is_id=(k==u'id'))
+            template_dict = dict((k, sanitize(k, v)) for k,v in template_dict.items())
 
             filename = self.params['outtmpl'] % template_dict
             return filename
@@ -461,7 +466,7 @@ class FileDownloader(object):
                 try:
                     success = self._do_download(filename, info_dict)
                 except (OSError, IOError) as err:
-                    raise UnavailableVideoError
+                    raise UnavailableVideoError()
                 except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
                     self.trouble(u'ERROR: unable to download video data: %s' % str(err))
                     return