U
    Mf7                     @   s   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	m
Z
mZmZmZmZmZ G dd deZG dd	 d	eZG d
d deZG dd deZG dd deZdS )    N   )InfoExtractor   )ExtractorErrordetermine_extfloat_or_noneint_or_none
js_to_jsonmimetype2extparse_iso8601str_or_nonestrip_or_nonetraverse_objurl_or_nonec                   @   s0   e Zd ZdZedd Zdd Zedd ZdS )	ImgurBaseIEZ546c25a59c58ad7c                 C   s   |  d| t|S )Nzhttps://imgur.com/)Z
url_resultImgurIE)clsZitem_id r   :/tmp/pip-unpacked-wheel-zk9bgjdq/yt_dlp/extractor/imgur.py_imgur_result   s    zImgurBaseIE._imgur_resultc                 K   s&   | j d| d| d| j d|f|S )Nzhttps://api.imgur.com/post/v1//z?client_id=z&include=media,account)Z_download_json
_CLIENT_ID)selfZendpointvideo_idkwargsr   r   r   	_call_api   s    zImgurBaseIE._call_apic                 C   s   d| krd S | pd S )Nz+Discover the magic of the internet at Imgurr   sr   r   r   get_description    s    zImgurBaseIE.get_descriptionN)	__name__
__module____qualname__r   classmethodr   r   staticmethodr   r   r   r   r   r      s   
r   c                   @   s   e Zd ZdZddddddeeddedd	d
dddddddddddddededdedd
dddddddeededdddgZd d! Zd"S )#r   zLhttps?://(?:i\.)?imgur\.com/(?!(?:a|gallery|t|topic|r)/)(?P<id>[a-zA-Z0-9]+)zhttps://imgur.com/A61SaA1ZA61SaA1mp4z+MRW gifv is up and running without any bugsit@mTZ20141120z https://i.imgur.com/A61SaA1h.jpg)idexttitle	timestampupload_datedislike_countcomment_countrelease_timestamprelease_date
like_count	thumbnail)url	info_dictz https://i.imgur.com/A61SaA1.gifvTr0   Zonly_matchingzhttps://i.imgur.com/crGpqCV.mp4z https://i.imgur.com/jxBXAMC.gifvZjxBXAMCzFahaka puffer feedingixl[Z20180809g      >@z https://i.imgur.com/jxBXAMCh.jpg)r%   r&   r'   r(   r)   r-   r.   durationr+   r,   r/   r*   zhttps://imgur.com/zV03bd5Z 59df97884e8ba76143ff6b640a0e2904ZzV03bd5z	Ive - LiziweZ20240315g(\uL@)r%   r&   r'   r(   r)   r.   r*   r3   r+   r,   r-   )r0   md5r1   c                    sj    |} d|}t|ddddd hfdffddsJt| d	d
d jd| d|ddpddg }t|dddthfdthfdthfdthfdthfdddd hfdf}|d}|r|dst	t|dpt
||d< t|ddkr
d|d< |dd ||  jd d!d d"}|r fd#d$}|d%}	t|	 sX|d}	ttd&|d'dd(d hfd) jhfdt	hfd*f}|D ]}
|
|	 qt jd+d,|tdd-d. jhfdthfd/}|r||	 |d0dd0dd0d0d1 || tj jd d2}d3t|d4t	|d5t|d6t|d7d8}|d r\|| |sx jd9| d:d
d  |  jd d"  jdd"d;t|d<d=d hfd>d?d@d hfd>dAthfdBthfdCthfdDthfdEdFd hfdGthfdHthfdI	ddt|ddddJdKd hfdL jhfdMthfdGthfdHthfdNfdd||t|dOdPdQidRS )SNmediar   typec                 S   s   | dkp
d S )Nvideor   )tr   r   r   <lambda>f       z'ImgurIE._real_extract.<locals>.<lambda>)metadatais_animatedF)get_allz! is not a video or animated imageT)expectedzhttps://i.imgur.com/z.gifv)fatal r0   r&   widthheightsizer;   Z	has_soundc                 S   s   | rd S dS )Nnoner   )br   r   r   r9   s   r:   )r0   r&   rA   rB   filesizeacodec)r5   r   Z	mime_type)r5   r   r6   imagerD   rG   
preferenceiz+(?s)<div class="video-elements">(.*?)</div>zvideo elementsdefaultc                    s    fdddD S )Nc              	      s,   i | ]$}|t j  d | ddqS ):NrJ   )r   Z_og_search_property).0p)
media_typer   webpager   r   
<dictcomp>   s    z>ImgurIE._real_extract.<locals>.og_get_size.<locals>.<dictcomp>)rA   rB   r   rO   r   rP   rR   r   og_get_size   s    z*ImgurIE._real_extract.<locals>.og_get_sizer7   z7<source\s+src="(?P<src>[^"]+)"\s+type="(?P<type>[^"]+)".c                 S   s   |  dd S )Nr   r   )	partitionr   r   r   r   r9      r:   src)	format_idr0   r&   zvar\s+videoItem\s*=zGIF info)Ztransform_sourcer?   ZgifUrl)r0   rF   Zgif)rW   rI   r&   rG   Zvcodec	container)htmlrK   Ztwitterztwitter:player:streamz"twitter:player:stream:content_typeztwitter:widthztwitter:height)rW   r0   r&   rA   rB   zNo sources found for video z. Maybe a plain image?r'   descriptionZ
account_idc                 S   s   t | rt| S d S N)r   str)ar   r   r   r9      r:   accountusernamec                 S   s   t | p
d S r\   r   xr   r   r   r9      r:   Z
avatar_urlZupvote_countZdownvote_countr+   Z	is_maturec                 S   s   | rdS d S )N   r   rb   r   r   r   r9      r:   )Z
updated_at
created_atre   )	uploader_iduploaderuploader_urlr.   r*   r+   Z	age_limitr(   r,   r'   c                 S   s   t | p
d S r\   ra   rb   r   r   r   r9      r:   r[   r3   )r'   r[   r3   r(   r,   ZthumbnailUrlAcceptz*/*)r%   formatsr/   Zhttp_headers) 	_match_idr   r   r   Z_download_webpager   r]   r   getr
   r   
setdefaultappendZ_search_regexanyvaluesrefinditerZ_proto_relative_urlupdateZ_search_jsonr	   	functoolspartialZ_html_search_metaZraise_no_formatsZ_remove_duplicate_formatsZ_og_search_titler   Z_og_search_descriptionr   r   )r   r0   r   datarj   Z	media_fmtZ	media_urlZvideo_elementsrT   rC   fZgif_jsonsearchZtwitter_fmtr   rS   r   _real_extractb   s    

  


 
  

    









 





zImgurIE._real_extractN)r   r    r!   
_VALID_URLint_TESTSry   r   r   r   r   r   '   sj   8r   c                   @   s   e Zd ZdZdd ZdS )ImgurGalleryBaseIETc                 C   s   |  |}| jd|ddd}t|ddd hfd| jhfd	}t|d
rt|ddd ddd hf}d }| jrt|dkr|d }|s| t| j||}|	| |S |}| |}d|d< |	| |S )NZalbumsFi  )r?   Zexpected_statusr'   c                 S   s   t | p
d S r\   ra   rb   r   r   r   r9      r:   z2ImgurGalleryBaseIE._real_extract.<locals>.<lambda>r[   rZ   Zis_albumr5   c                 S   s   | ddkp|d d S )Nr6   r7   r;   r<   )rl   )_vr   r   r   r9      r:   r%   c                 S   s   t | p
d S r\   )r   rb   r   r   r   r9      r:   r   r   Zurl_transparent_type)
rk   r   r   r   _GALLERYlenZplaylist_resultmapr   rs   )r   r0   Z
gallery_idrv   infoitemsZmedia_idresultr   r   r   ry      s8    


  
 


z ImgurGalleryBaseIE._real_extractN)r   r    r!   r   ry   r   r   r   r   r}      s   r}   c                   @   s   e Zd ZdZdZddddddd	d
ddddgdddddddddddeeedddddddgdddddd d!eed"dedd#d$dd%d&d'dd(d)d*dgd+dd,d-d.d-d.eeed/d0d1dd2dgd3dd4d5d6d7eed/ed6d8d7d9dgZd:S );ImgurGalleryIEzimgur:galleryzUhttps?://(?:i\.)?imgur\.com/(?:gallery|(?:t(?:opic)?|r)/[^/?#]+)/(?P<id>[a-zA-Z0-9]+)zhttp://imgur.com/gallery/Q95koZQ95koz"Adding faces make every GIF betterr%   r'      z"Zoinks! You've taken a wrong turn.)r0   r1   playlist_countskipz http://imgur.com/topic/Aww/ll5VkTr2   z!https://imgur.com/gallery/YcAQlkxZImgurZYcAQlkxr$   zRClassic Steve Carell gif...cracks me up everytime....damn the repost downvotes....iPZ20130119Z1648642Zwittyusernameherez https://i.imgur.com/YcAQlkxh.jpgz=https://i.imgur.com/u3R4I2S_d.png?maxwidth=290&fidelity=grand)r%   r&   r'   r(   r)   rf   rg   r,   r/   r-   rh   r+   r*   r.   )r0   Zadd_iesr1   z$http://imgur.com/topic/Funny/N8rOuddzhttp://imgur.com/r/aww/VQcQPhMZVQcQPhMzThe boss is hereiXZ20161015Z19138530Zthematrixcamz=https://i.imgur.com/qCjr5Pi_d.png?maxwidth=290&fidelity=grandz https://i.imgur.com/VQcQPhMh.jpg)r%   r&   r'   r(   r)   rf   rg   r+   r*   rh   r,   r.   r-   r/   z#https://imgur.com/t/unmuted/6lAn9VQZ6lAn9VQz
Penguins !   r0   r1   r   z#https://imgur.com/t/unmuted/kx2uD3CZZVMv45iZIntruderih[Z20180604gHz>@z https://i.imgur.com/ZVMv45ih.jpg)r%   r&   r'   r(   r)   r,   r-   r.   r*   r+   r3   r/   z#https://imgur.com/t/unmuted/wXSK0YHZJCAP4iozre:I got the blues$ud   Luka’s vocal stylings.

FP edit: don’t encourage me. I’ll never stop posting Luka and friends.i[Z20180531z https://i.imgur.com/JCAP4ioh.jpg)r%   r&   r'   r[   r(   r)   r.   r*   r3   r+   r,   r/   r-   N)r   r    r!   IE_NAMErz   r{   r|   r   r   r   r   r      s   
r   c                   @   sB   e Zd ZdZdZdZdddddd	d
dddddiddgZdS )ImgurAlbumIEzimgur:albumz2https?://(?:i\.)?imgur\.com/a/(?P<id>[a-zA-Z0-9]+)Fzhttp://imgur.com/a/j6OrjTr2   zhttps://imgur.com/a/iX265HXZiX265HXzenen-no-shouboutair   r   r   zhttps://imgur.com/a/8pih2Edr%   Z8pih2Edr   )r0   r1   Zplaylist_mincountN)r   r    r!   r   rz   r   r|   r   r   r   r   r   f  s&    r   )rt   rq   commonr   utilsr   r   r   r   r	   r
   r   r   r   r   r   r   r   r}   r   r   r   r   r   r   <module>   s   4 2%i