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