a
    h                     @   sL   d dl Z d dl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   )PostProcessingErrorXAttrMetadataErrorXAttrUnavailableErrorhyphenate_datewrite_xattrc                   @   s0   e Zd ZdZddddddddZ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.description$com.apple.metadata:kMDItemWhereFromsz<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<string>%s</string>
</array>
</plist>c                 C   sX  t |d j}| d | j D ]\}}zX||}|r|dkrPt|}n |dkrptj	dkrfW q$| j
| }t|d ||  W q$ ty } ztt|W Y d }~q$d }~0  ty: } zl|jdkr| d| d nB|jd	kr| d
| d n"t jdkrdnd}td| W Y d }~q$d }~0 0 q$| |d || g |fS )Nfilepathz!Writing metadata to file's xattrsr   r   darwinZ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   sysplatformAPPLE_PLIST_TEMPLATEr	   encoder   r   strr   reasonZreport_warningnameZ	try_utime)selfinfomtimeZ	xattrnameZinfonamevalueeZtip r%   Q/mnt/pikpak/tmp/myenv/lib/python3.9/site-packages/yt_dlp/postprocessor/xattrpp.pyrun0   s<    




 
&zXAttrMetadataPP.runN)__name__
__module____qualname____doc__r   r   r'   r%   r%   r%   r&   r
      s   r
   )r   r   commonr   utilsr   r   r   r   r	   r
   r%   r%   r%   r&   <module>   s   	