U
    Mf	                     @   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_datedescriptionZuploaderformat)zuser.xdg.referrer.urlzuser.dublincore.titlezuser.dublincore.datezuser.dublincore.descriptionzuser.dublincore.contributorzuser.dublincore.formatc              
   C   s  t |d j}| d zJ| j D ]:\}}||}|r&|dkrLt|}t|d ||	  q&W n t
k
r } ztt|W 5 d }~X Y nl tk
r } zN|jdkr| d n4|jdkr| d ntdkrd	nd
}td| W 5 d }~X Y nX | |d || g |fS )Nfilepathz!Writing metadata to file's xattrsr   ZNO_SPACEz|There's no disk space left, disk quota exceeded or filesystem xattr limit exceeded. Some extended attributes are not writtenZVALUE_TOO_LONGz;Unable to write extended attributes 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-zk9bgjdq/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   	