3 from .common
import PostProcessor
4 from ..compat
import compat_os_name
14 class XAttrMetadataPP(PostProcessor
):
15 """Set extended attributes on downloaded file (if xattr support is found)
17 More info about extended attributes for media:
18 http://freedesktop.org/wiki/CommonExtendedAttributes/
19 http://www.freedesktop.org/wiki/PhreedomDraft/
20 http://dublincore.org/documents/usageguide/elements.shtml
23 * capture youtube keywords and put them in 'user.dublincore.subject' (comma-separated)
24 * figure out which xattrs can be used for 'duration', 'thumbnail', 'resolution'
28 'user.xdg.referrer.url': 'webpage_url',
29 # 'user.xdg.comment': 'description',
30 'user.dublincore.title': 'title',
31 'user.dublincore.date': 'upload_date',
32 'user.dublincore.description': 'description',
33 'user.dublincore.contributor': 'uploader',
34 'user.dublincore.format': 'format',
38 mtime
= os
.stat(info
['filepath']).st_mtime
39 self
.to_screen('Writing metadata to file\'s xattrs')
41 for xattrname
, infoname
in self
.XATTR_MAPPING
.items():
42 value
= info
.get(infoname
)
44 if infoname
== 'upload_date':
45 value
= hyphenate_date(value
)
46 write_xattr(info
['filepath'], xattrname
, value
.encode())
48 except XAttrUnavailableError
as e
:
49 raise PostProcessingError(str(e
))
50 except XAttrMetadataError
as e
:
51 if e
.reason
== 'NO_SPACE':
53 'There\'s no disk space left, disk quota exceeded or filesystem xattr limit exceeded. '
54 'Some extended attributes are not written')
55 elif e
.reason
== 'VALUE_TOO_LONG':
56 self
.report_warning('Unable to write extended attributes due to too long values.')
58 tip
= ('You need to use NTFS' if compat_os_name
== 'nt'
59 else 'You may have to enable them in your "/etc/fstab"')
60 raise PostProcessingError(f
'This filesystem doesn\'t support extended attributes. {tip}')
62 self
.try_utime(info
['filepath'], mtime
, mtime
)