1 from __future__ import unicode_literals
3 from .common import PostProcessor
4 from ..compat import compat_os_name
13 class XAttrMetadataPP(PostProcessor):
16 # More info about extended attributes for media:
17 # http://freedesktop.org/wiki/CommonExtendedAttributes/
18 # http://www.freedesktop.org/wiki/PhreedomDraft/
19 # http://dublincore.org/documents/usageguide/elements.shtml
22 # * capture youtube keywords and put them in 'user.dublincore.subject' (comma-separated)
23 # * figure out which xattrs can be used for 'duration', 'thumbnail', 'resolution'
27 """ Set extended attributes on downloaded file (if xattr support is found). """
29 # Write the metadata to the file's xattrs
30 self._downloader.to_screen('[metadata] Writing metadata to file\'s xattrs')
32 filename = info['filepath']
36 'user.xdg.referrer.url': 'webpage_url',
37 # 'user.xdg.comment': 'description',
38 'user.dublincore.title': 'title',
39 'user.dublincore.date': 'upload_date',
40 'user.dublincore.description': 'description',
41 'user.dublincore.contributor': 'uploader',
42 'user.dublincore.format': 'format',
46 for xattrname, infoname in xattr_mapping.items():
48 value = info.get(infoname)
51 if infoname == 'upload_date':
52 value = hyphenate_date(value)
54 byte_value = value.encode('utf-8')
55 write_xattr(filename, xattrname, byte_value)
60 except XAttrUnavailableError as e:
61 self._downloader.report_error(str(e))
64 except XAttrMetadataError as e:
65 if e.reason == 'NO_SPACE':
66 self._downloader.report_warning(
67 'There\'s no disk space left, disk quota exceeded or filesystem xattr limit exceeded. ' +
68 (('Some ' if num_written else '') + 'extended attributes are not written.').capitalize())
69 elif e.reason == 'VALUE_TOO_LONG':
70 self._downloader.report_warning(
71 'Unable to write extended attributes due to too long values.')
73 msg = 'This filesystem doesn\'t support extended attributes. '
74 if compat_os_name == 'nt':
75 msg += 'You need to use NTFS.'
77 msg += '(You may have to enable them in your /etc/fstab)'
78 self._downloader.report_error(msg)