U
    g
                     @   sP   d dl Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 G dd deZdS )	    N   )PostProcessor   )compat_os_name)PostProcessingErrorXAttrMetadataErrorXAttrUnavailableErrorhyphenate_datewrite_xattrc                   @   s*   e Zd ZdZdddddddZd	d
 ZdS )XAttrMetadataPPa  Set extended attributes on downloaded file (if xattr support is found)

    More info about extended attributes for media:
        http://freedesktop.org/wiki/CommonExtendedAttributes/
        http://www.freedesktop.org/wiki/PhreedomDraft/
        http://dublincore.org/documents/usageguide/elements.shtml

    TODO:
        * capture youtube keywords and put them in 'user.dublincore.subject' (comma-separated)
        * figure out which xattrs can be used for 'duration', 'thumbnail', 'resolution'
    Zwebpage_urltitleupload_dateZuploaderformatdescription)zuser.xdg.referrer.urlzuser.dublincore.titlezuser.dublincore.datezuser.dublincore.contributorzuser.dublincore.formatzuser.dublincore.descriptionc                 C   s*  t |d j}| d | j D ]\}}z6||}|r`|dkrLt|}t|d ||	  W q$ t
k
r } ztt|W 5 d }~X Y q$ tk
r } z^|jdkr| d| d n<|jdkr| d| d	 ntd
krdnd}td| W 5 d }~X Y q$X q$| |d || g |fS )Nfilepathz!Writing metadata to file's xattrsr   ZNO_SPACEzhThere's no disk space left, disk quota exceeded or filesystem xattr limit exceeded. Extended attribute "z" was not written.ZVALUE_TOO_LONGz$Unable to write extended attribute "z" due to too long values.ntzYou need to use NTFSz0You may have to enable them in your "/etc/fstab"z5This filesystem doesn't support extended attributes. )osstatst_mtimeZ	to_screenXATTR_MAPPINGitemsgetr	   r
   encoder   r   strr   reasonZreport_warningr   Z	try_utime)selfinfomtimeZ	xattrnameZinfonamevalueeZtip r    @/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/postprocessor/xattrpp.pyrun'   s0    




"zXAttrMetadataPP.runN)__name__
__module____qualname____doc__r   r"   r    r    r    r!   r      s   r   )r   commonr   compatr   utilsr   r   r   r	   r
   r   r    r    r    r!   <module>   s   	