+from __future__ import unicode_literals
+
import os
import subprocess
import sys
from .common import PostProcessor
+from ..compat import (
+ subprocess_check_output
+)
from ..utils import (
check_executable,
hyphenate_date,
- preferredencoding,
+ version_tuple,
)
# 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):
+ self._downloader.report_warning(
+ '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__))
+
+ raise ImportError
+
def write_xattr(path, key, value):
return xattr.setxattr(path, key, value)
# Write xattrs to NTFS Alternate Data Streams:
# http://en.wikipedia.org/wiki/NTFS#Alternate_data_streams_.28ADS.29
def write_xattr(path, key, value):
- assert(key.find(":") < 0)
- assert(path.find(":") < 0)
- assert(os.path.exists(path))
+ assert ':' not in key
+ assert os.path.exists(path)
ads_fn = path + ":" + key
- with open(ads_fn, "w") as f:
+ with open(ads_fn, "wb") as f:
f.write(value)
else:
user_has_setfattr = check_executable("setfattr", ['--version'])
elif user_has_xattr:
cmd = ['xattr', '-w', key, value, path]
- subprocess.check_output(cmd)
+ subprocess_check_output(cmd)
else:
# On Unix, and can't find pyxattr, setfattr, or xattr.
if infoname == "upload_date":
value = hyphenate_date(value)
- byte_value = value.encode(preferredencoding())
+ byte_value = value.encode('utf-8')
write_xattr(filename, xattrname, byte_value)
- return True, info
+ return [], info
except (subprocess.CalledProcessError, OSError):
self._downloader.report_error("This filesystem doesn't support extended attributes. (You may have to enable them in your /etc/fstab)")
- return False, info
-
+ return [], info