]> gitweb @ CieloNegro.org - youtube-dl.git/commitdiff
[downloader/http] Use write_xattr function for --xattr-set-filesize
authorYen Chi Hsuan <yan12125@gmail.com>
Thu, 29 Sep 2016 16:49:14 +0000 (00:49 +0800)
committerYen Chi Hsuan <yan12125@gmail.com>
Sat, 1 Oct 2016 06:47:20 +0000 (14:47 +0800)
youtube_dl/__init__.py
youtube_dl/downloader/http.py

index 1cf3140a038cdcc27737c6ae018cb0db3eb9014b..72141b983d6ec1c62f58eff3920d80e77a9eee39 100644 (file)
@@ -283,12 +283,6 @@ def _real_main(argv=None):
             'key': 'ExecAfterDownload',
             'exec_cmd': opts.exec_cmd,
         })
-    if opts.xattr_set_filesize:
-        try:
-            import xattr
-            xattr  # Confuse flake8
-        except ImportError:
-            parser.error('setting filesize xattr requested but python-xattr is not available')
     external_downloader_args = None
     if opts.external_downloader_args:
         external_downloader_args = compat_shlex_split(opts.external_downloader_args)
index f8b69d186ac5ee93c8402f85bc66e7ed59570118..11294d106064414e2fe538b3c53327fb617b08f5 100644 (file)
@@ -13,6 +13,9 @@ from ..utils import (
     encodeFilename,
     sanitize_open,
     sanitized_Request,
+    write_xattr,
+    XAttrMetadataError,
+    XAttrUnavailableError,
 )
 
 
@@ -179,9 +182,8 @@ class HttpFD(FileDownloader):
 
                 if self.params.get('xattr_set_filesize', False) and data_len is not None:
                     try:
-                        import xattr
-                        xattr.setxattr(tmpfilename, 'user.ytdl.filesize', str(data_len))
-                    except(OSError, IOError, ImportError) as err:
+                        write_xattr(tmpfilename, 'user.ytdl.filesize', str(data_len))
+                    except (XAttrUnavailableError, XAttrMetadataError) as err:
                         self.report_error('unable to set filesize xattr: %s' % str(err))
 
             try: