]>
jfr.im git - yt-dlp.git/blob - yt_dlp/postprocessor/xattrpp.py
1 from .common
import PostProcessor
2 from ..compat
import compat_os_name
12 class XAttrMetadataPP(PostProcessor
):
14 # More info about extended attributes for media:
15 # http://freedesktop.org/wiki/CommonExtendedAttributes/
16 # http://www.freedesktop.org/wiki/PhreedomDraft/
17 # http://dublincore.org/documents/usageguide/elements.shtml
20 # * capture youtube keywords and put them in 'user.dublincore.subject' (comma-separated)
21 # * figure out which xattrs can be used for 'duration', 'thumbnail', 'resolution'
25 """ Set extended attributes on downloaded file (if xattr support is found). """
27 # Write the metadata to the file's xattrs
28 self
.to_screen('Writing metadata to file\'s xattrs')
30 filename
= info
['filepath']
34 'user.xdg.referrer.url': 'webpage_url',
35 # 'user.xdg.comment': 'description',
36 'user.dublincore.title': 'title',
37 'user.dublincore.date': 'upload_date',
38 'user.dublincore.description': 'description',
39 'user.dublincore.contributor': 'uploader',
40 'user.dublincore.format': 'format',
44 for xattrname
, infoname
in xattr_mapping
.items():
46 value
= info
.get(infoname
)
49 if infoname
== 'upload_date':
50 value
= hyphenate_date(value
)
52 byte_value
= value
.encode('utf-8')
53 write_xattr(filename
, xattrname
, byte_value
)
58 except XAttrUnavailableError
as e
:
59 raise PostProcessingError(str(e
))
61 except XAttrMetadataError
as e
:
62 if e
.reason
== 'NO_SPACE':
64 'There\'s no disk space left, disk quota exceeded or filesystem xattr limit exceeded. '
65 + (('Some ' if num_written
else '') + 'extended attributes are not written.').capitalize())
66 elif e
.reason
== 'VALUE_TOO_LONG':
68 'Unable to write extended attributes due to too long values.')
70 msg
= 'This filesystem doesn\'t support extended attributes. '
71 if compat_os_name
== 'nt':
72 msg
+= 'You need to use NTFS.'
74 msg
+= '(You may have to enable them in your /etc/fstab)'
75 raise PostProcessingError(str(e
))