3
uQh                 @   s:   d dl Z d dlZddlmZ ddlmZ G dd dZdS )    N   )utils)typesc               @   s   e Zd ZdZdd Zedd Zedd Zedd	 Zed
d Z	edd Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Zdd ZdS )Filea3  
    Convenience class over media like photos or documents, which
    supports accessing the attributes in a more convenient way.

    If any of the attributes are not present in the current media,
    the properties will be `None`.

    The original media is available through the ``media`` attribute.
    c             C   s
   || _ d S )N)media)selfr    r   ;/tmp/pip-build-2nz6shyl/telethon/telethon/tl/custom/file.py__init__   s    zFile.__init__c             C   s   t j| jS )a  
        The old bot-API style ``file_id`` representing this file.

        .. warning::

            This feature has not been maintained for a long time and
            may not work. It will be removed in future versions.

        .. note::

            This file ID may not work under user accounts,
            but should still be usable by bot accounts.

            You can, however, still use it to identify
            a file in for example a database.
        )r   Zpack_bot_file_idr   )r   r   r   r	   id   s    zFile.idc             C   s   | j tjdS )z1
        The file name of this document.
        	file_name)
_from_attrr   ZDocumentAttributeFilename)r   r   r   r	   name)   s    z	File.namec             C   s&   t j| jp$tjj| jpdd p$dS )z
        The extension from the mime type of this file.

        If the mime type is unknown, the extension
        from the file name (if any) will be used.
            N)	mimetypesguess_extension	mime_typeospathsplitextr   )r   r   r   r	   ext0   s    	zFile.extc             C   s,   t | jtjrdS t | jtjr(| jjS dS )z-
        The mime-type of this file.
        z
image/jpegN)
isinstancer   r   PhotoDocumentr   )r   r   r   r	   r   >   s    zFile.mime_typec             C   s8   t | jtjr$tdd | jjD S | jtjtjfdS )zO
        The width in pixels of this media if it's a photo or a video.
        c             s   s   | ]}t |d dV  qdS )wr   N)getattr).0sr   r   r	   	<genexpr>N   s    zFile.width.<locals>.<genexpr>r   )	r   r   r   r   maxsizesr   DocumentAttributeImageSizeDocumentAttributeVideo)r   r   r   r	   widthH   s    z
File.widthc             C   s8   t | jtjr$tdd | jjD S | jtjtjfdS )zP
        The height in pixels of this media if it's a photo or a video.
        c             s   s   | ]}t |d dV  qdS )hr   N)r   )r   r   r   r   r	   r    Y   s    zFile.height.<locals>.<genexpr>r&   )	r   r   r   r   r!   r"   r   r#   r$   )r   r   r   r	   heightS   s    zFile.heightc             C   s   | j tjtjfdS )z@
        The duration in seconds of the audio or video.
        duration)r   r   DocumentAttributeAudior$   )r   r   r   r	   r(   ^   s    zFile.durationc             C   s   | j tjdS )z(
        The title of the song.
        title)r   r   r)   )r   r   r   r	   r*   f   s    z
File.titlec             C   s   | j tjdS )z,
        The performer of the song.
        	performer)r   r   r)   )r   r   r   r	   r+   m   s    zFile.performerc             C   s   | j tjdS )zM
        A string with all emoji that represent the current sticker.
        Zalt)r   r   DocumentAttributeSticker)r   r   r   r	   emojit   s    z
File.emojic             C   s   | j tjdS )zN
        The :tl:`InputStickerSet` to which the sticker file belongs.
        Z
stickerset)r   r   r,   )r   r   r   r	   sticker_set{   s    zFile.sticker_setc             C   sF   t | jtjr,ttdttj| jj	ddS t | jtj
rB| jjS dS )z
        The size in bytes of this file.

        For photos, this is the heaviest thumbnail, as it often repressents the largest dimensions.
        N)default)r   r   r   r   r!   filtermapr   Z_photo_size_byte_countr"   r   size)r   r   r   r	   r2      s    z	File.sizec             C   s:   t | jtjr6x&| jjD ]}t ||rt||d S qW d S )N)r   r   r   r   
attributesr   )r   clsfieldattrr   r   r	   r      s    
zFile._from_attrN)__name__
__module____qualname____doc__r
   propertyr   r   r   r   r%   r'   r(   r*   r+   r-   r.   r2   r   r   r   r   r	   r      s   	
r   )r   r   r   r   tlr   r   r   r   r   r	   <module>   s   