3 from .common
import PostProcessor
13 class XAttrMetadataPP(PostProcessor
):
14 """Set extended attributes on downloaded file (if xattr support is found)
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 'user.xdg.referrer.url': 'webpage_url',
28 'user.dublincore.title': 'title',
29 'user.dublincore.date': 'upload_date',
30 'user.dublincore.contributor': 'uploader',
31 'user.dublincore.format': 'format',
32 # We do this last because it may get us close to the xattr limits
33 # (e.g., 4kB on ext4), and we don't want to have the other ones fail
34 'user.dublincore.description': 'description',
35 # 'user.xdg.comment': 'description',
39 mtime
= os
.stat(info
['filepath']).st_mtime
40 self
.to_screen('Writing metadata to file\'s xattrs')
41 for xattrname
, infoname
in self
.XATTR_MAPPING
.items():
43 value
= info
.get(infoname
)
45 if infoname
== 'upload_date':
46 value
= hyphenate_date(value
)
47 write_xattr(info
['filepath'], xattrname
, value
.encode())
49 except XAttrUnavailableError
as e
:
50 raise PostProcessingError(str(e
))
51 except XAttrMetadataError
as e
:
52 if e
.reason
== 'NO_SPACE':
54 'There\'s no disk space left, disk quota exceeded or filesystem xattr limit exceeded. '
55 f
'Extended attribute "{xattrname}" was not written.')
56 elif e
.reason
== 'VALUE_TOO_LONG':
57 self
.report_warning(f
'Unable to write extended attribute "{xattrname}" due to too long values.')
59 tip
= ('You need to use NTFS' if os
.name
== 'nt'
60 else 'You may have to enable them in your "/etc/fstab"')
61 raise PostProcessingError(f
'This filesystem doesn\'t support extended attributes. {tip}')
63 self
.try_utime(info
['filepath'], mtime
, mtime
)