A feature-rich command-line audio/video downloader
[utils] Support xattr as well as pyxattr
Yen Chi Hsuan53a7e3d2879f
diff --git a/ChangeLog b/ChangeLogindex efc3e494e1..8ef39cd63c 100644--- a/ChangeLog+++ b/ChangeLog@@ -1,5 +1,9 @@version <unreleased>+Core++ Support pyxattr as well as python-xattr for --xattrs and+ --xattr-set-filesize (#9054)+Extractors* [dctp] Fix extraction (#10734)+ [leeco] Recognize more Le Sports URLs (#10794)diff --git a/youtube_dl/utils.py b/youtube_dl/utils.pyindex d2dfa80139..c259f8bff4 100644--- a/youtube_dl/utils.py+++ b/youtube_dl/utils.py@@ -3161,20 +3161,25 @@ def write_xattr(path, key, value):# try the pyxattr module...import xattr- # Unicode arguments are not supported in python-pyxattr until- # version 0.5.0- # See https://github.com/rg3/youtube-dl/issues/5498- pyxattr_required_version = '0.5.0'- if version_tuple(xattr.__version__) < version_tuple(pyxattr_required_version):- # TODO: fallback to CLI tools- raise XAttrUnavailableError(- 'python-pyxattr is detected but is too old. '- 'youtube-dl requires %s or above while your version is %s. '- 'Falling back to other xattr implementations' % (- pyxattr_required_version, xattr.__version__))+ if hasattr(xattr, 'set'): # pyxattr+ # Unicode arguments are not supported in python-pyxattr until+ # version 0.5.0+ # See https://github.com/rg3/youtube-dl/issues/5498+ pyxattr_required_version = '0.5.0'+ if version_tuple(xattr.__version__) < version_tuple(pyxattr_required_version):+ # TODO: fallback to CLI tools+ raise XAttrUnavailableError(+ 'python-pyxattr is detected but is too old. '+ 'youtube-dl requires %s or above while your version is %s. '+ 'Falling back to other xattr implementations' % (+ pyxattr_required_version, xattr.__version__))++ setxattr = xattr.set+ else: # xattr+ setxattr = xattr.setxattrtry:- xattr.set(path, key, value)+ setxattr(path, key, value)except EnvironmentError as e:raise XAttrMetadataError(e.errno, e.strerror)