mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-21 17:51:51 +00:00
[utils] Support xattr as well as pyxattr
Closes #9054 There are two xattr packages in Python, pyxattr [1] and xattr [2]. They have different APIs. In old days pyxattr supports Linux only and xattr supports Linux, Mac, FreeBSD and Solaris, and pyxattr supports Linux only. Recently pyxattr adds support for Mac OS X. [3] An old version of [2] is shipped with Mac OS X. However, some Linux distributions have pyxattr only, for example PLD-Linux [4] and old Arch Linux. [5] As a result, supporting both is the way to go. [1] https://github.com/iustin/pyxattr [2] https://github.com/xattr/xattr [3] https://github.com/iustin/pyxattr/pull/9 [4] https://github.com/rg3/youtube-dl/issues/5498 [5] https://git.archlinux.org/svntogit/community.git/commit/?id=427c4c76401e386d865ccddea4fbfdc74df80492 https://git.archlinux.org/svntogit/community.git/commit/?id=59b40da7b69622a6761d364a8b07909e9cccaa56 python-xattr is added on 2016/06/29 while pyxattr is there for more than 6 years
This commit is contained in:
parent
d54739a2e6
commit
53a7e3d287
2 changed files with 21 additions and 12 deletions
|
@ -1,5 +1,9 @@
|
||||||
version <unreleased>
|
version <unreleased>
|
||||||
|
|
||||||
|
Core
|
||||||
|
+ Support pyxattr as well as python-xattr for --xattrs and
|
||||||
|
--xattr-set-filesize (#9054)
|
||||||
|
|
||||||
Extractors
|
Extractors
|
||||||
* [dctp] Fix extraction (#10734)
|
* [dctp] Fix extraction (#10734)
|
||||||
+ [leeco] Recognize more Le Sports URLs (#10794)
|
+ [leeco] Recognize more Le Sports URLs (#10794)
|
||||||
|
|
|
@ -3161,20 +3161,25 @@ def write_xattr(path, key, value):
|
||||||
# try the pyxattr module...
|
# try the pyxattr module...
|
||||||
import xattr
|
import xattr
|
||||||
|
|
||||||
# Unicode arguments are not supported in python-pyxattr until
|
if hasattr(xattr, 'set'): # pyxattr
|
||||||
# version 0.5.0
|
# Unicode arguments are not supported in python-pyxattr until
|
||||||
# See https://github.com/rg3/youtube-dl/issues/5498
|
# version 0.5.0
|
||||||
pyxattr_required_version = '0.5.0'
|
# See https://github.com/rg3/youtube-dl/issues/5498
|
||||||
if version_tuple(xattr.__version__) < version_tuple(pyxattr_required_version):
|
pyxattr_required_version = '0.5.0'
|
||||||
# TODO: fallback to CLI tools
|
if version_tuple(xattr.__version__) < version_tuple(pyxattr_required_version):
|
||||||
raise XAttrUnavailableError(
|
# TODO: fallback to CLI tools
|
||||||
'python-pyxattr is detected but is too old. '
|
raise XAttrUnavailableError(
|
||||||
'youtube-dl requires %s or above while your version is %s. '
|
'python-pyxattr is detected but is too old. '
|
||||||
'Falling back to other xattr implementations' % (
|
'youtube-dl requires %s or above while your version is %s. '
|
||||||
pyxattr_required_version, xattr.__version__))
|
'Falling back to other xattr implementations' % (
|
||||||
|
pyxattr_required_version, xattr.__version__))
|
||||||
|
|
||||||
|
setxattr = xattr.set
|
||||||
|
else: # xattr
|
||||||
|
setxattr = xattr.setxattr
|
||||||
|
|
||||||
try:
|
try:
|
||||||
xattr.set(path, key, value)
|
setxattr(path, key, value)
|
||||||
except EnvironmentError as e:
|
except EnvironmentError as e:
|
||||||
raise XAttrMetadataError(e.errno, e.strerror)
|
raise XAttrMetadataError(e.errno, e.strerror)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue