]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/postprocessor/xattrpp.py
fbdfa02acc88ff8ba82684a2e5545aebe3fce5da
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',
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
)
58 except XAttrUnavailableError
as e
:
59 self
._downloader
.report_error(str(e
))
62 except XAttrMetadataError
as e
:
63 if e
.reason
== 'NO_SPACE':
64 self
._downloader
.report_warning(
65 'There\'s no disk space left or disk quota exceeded. ' +
66 'Extended attributes are not written.')
67 elif e
.reason
== 'VALUE_TOO_LONG':
68 self
._downloader
.report_warning(
69 'Unable to write extended attributes due to too long values.')
71 msg
= 'This filesystem doesn\'t support extended attributes. '
72 if compat_os_name
== 'nt':
73 msg
+= 'You need to use NTFS.'
75 msg
+= '(You may have to enable them in your /etc/fstab)'
76 self
._downloader
.report_error(msg
)