o
    i>                     @   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 )	ImgurBaseIE546c25a59c58ad7c                 C   s   |  d| t|S )Nzhttps://imgur.com/)
url_resultImgurIE)clsitem_id r   J/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/imgur.py_imgur_result   s   zImgurBaseIE._imgur_resultc                 K   s*   | j d| d| d| j d|fi |S )Nzhttps://api.imgur.com/post/v1//z?client_id=z&include=media,account)_download_json
_CLIENT_ID)selfendpointvideo_idkwargsr   r   r   	_call_api   s   zImgurBaseIE._call_apic                 C   s   d| v 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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 d!gZd"d# Zd$S )%r   zYhttps?://(?:i\.)?imgur\.com/(?!(?:a|gallery|t|topic|r)/)(?:[^/?#]+-)?(?P<id>[a-zA-Z0-9]+)zhttps://imgur.com/A61SaA1A61SaA1mp4z+MRW gifv is up and running without any bugsit@mT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_dictzAhttps://imgur.com/mrw-gifv-is-up-running-without-any-bugs-A61SaA1z https://i.imgur.com/A61SaA1.gifvTr7   only_matchingzhttps://i.imgur.com/crGpqCV.mp4z https://i.imgur.com/jxBXAMC.gifvjxBXAMCzFahaka puffer feedingixl[20180809g      >@z https://i.imgur.com/jxBXAMCh.jpg)r,   r-   r.   r/   r0   r4   r5   durationr2   r3   r6   r1   zhttps://imgur.com/zV03bd5 59df97884e8ba76143ff6b640a0e2904zV03bd5z	Ive - Liziwe20240315g(\uL@z https://i.imgur.com/zV03bd5h.jpg)r,   r-   r.   r/   r0   r5   r1   r=   r2   r3   r4   r6   )r7   md5r8   c                    s|    |} d|}t|ddddd hfdffdds%t| d	d
d jd| d|ddp2d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srt	t|dpot
||d< t|ddkrd|d< |dd ||  jd d!d d"}|r fd#d$}|d%}	t|	 s|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(|| |s6 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|||g dO }r|dPdQidRgnd dPdQidSS )TNmediar   typec                 S   s   | dkpd S )Nvideor   )tr   r   r   <lambda>w       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 r7   r-   widthheightsizerH   	has_soundc                 S   s   | rd S dS )Nnoner   )br   r   r   rF      rG   )r7   r-   rN   rO   filesizeacodec)rB   r   	mime_type)rB   r   rC   imagerR   rU   
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 ):NrY   )r   _og_search_property).0p)
media_typer   webpager   r   
<dictcomp>   s    z>ImgurIE._real_extract.<locals>.og_get_size.<locals>.<dictcomp>)rN   rO   r   r_   r   r`   rb   r   og_get_size   s   z*ImgurIE._real_extract.<locals>.og_get_sizerD   z7<source\s+src="(?P<src>[^"]+)"\s+type="(?P<type>[^"]+)".c                 S   s   |  dd S )Nr   r   )	partitionr!   r   r   r   rF      s    src)	format_idr7   r-   zvar\s+videoItem\s*=zGIF info)transform_sourcerL   gifUrl)r7   rT   gif)rg   rX   r-   rU   vcodec	container)htmlrZ   twitterztwitter:player:streamz"twitter:player:stream:content_typeztwitter:widthztwitter:height)rg   r7   r-   rN   rO   zNo sources found for video z. Maybe a plain image?r.   description
account_idc                 S   s   t | rt| S d S N)r   str)ar   r   r   rF      s    accountusernamec                 S      t | pd S rr   r   xr   r   r   rF      rG   
avatar_urlupvote_countdownvote_countr2   	is_maturec                 S   s   | rdS d S )N   r   ry   r   r   r   rF      rG   )
updated_at
created_atr   )	uploader_iduploaderuploader_urlr5   r1   r2   	age_limitr/   r3   r.   c                 S   rw   rr   rx   ry   r   r   r   rF      rG   rp   r=   )r.   rp   r=   r/   r3   )thumbnailUrlztwitter:imagezog:imageAcceptz*/*)r7   http_headers)r,   formats
thumbnailsr   ) 	_match_idr    r   r   _download_webpager   rs   r   getr
   r   
setdefaultappend_search_regexanyvaluesrefinditer_proto_relative_urlupdate_search_jsonr	   	functoolspartial_html_search_metaraise_no_formats_remove_duplicate_formats_og_search_titler#   _og_search_descriptionr   r   )r   r7   r   datar   	media_fmt	media_urlvideo_elementsrd   rP   fgif_jsonsearchtwitter_fmtthumbnail_urlr   rc   r   _real_extracts   s   




















zImgurIE._real_extractN)r$   r%   r&   
_VALID_URLint_TESTSr   r   r   r   r   r   '   s    Ir   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
rVt|ddd ddd hf}d }| jrAt|dkrA|d }|sT| t| j||}|	| |S |}| |}d|d< |	| |S )NalbumsFi  )rL   expected_statusr.   c                 S   rw   rr   rx   ry   r   r   r   rF      rG   z2ImgurGalleryBaseIE._real_extract.<locals>.<lambda>rp   ro   is_albumrB   c                 S   s   | ddkp|d d S )NrC   rD   rH   rI   )r   )_vr   r   r   rF      s    r,   c                 S   rw   rr   )r   ry   r   r   r   rF      rG   r   r   url_transparent_type)
r   r    r   r#   _GALLERYlenplaylist_resultmapr   r   )r   r7   
gallery_idr   infoitemsmedia_idresultr   r   r   r      s2   






z ImgurGalleryBaseIE._real_extractN)r$   r%   r&   r   r   r   r   r   r   r      s    r   c                   @   s  e Zd ZdZdZdddddgdd	d
ddddddddeee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!d"d#d$d%d'dgd(d	d)d*d+d*d+eeed,d-d.dd/dgd0d	d1d2d3d4eed,ed3d5d4d6dg	Zd7S )8ImgurGalleryIEzimgur:galleryzbhttps?://(?:i\.)?imgur\.com/(?:gallery|(?:t(?:opic)?|r)/[^/?#]+)/(?:[^/?#]+-)?(?P<id>[a-zA-Z0-9]+)z http://imgur.com/topic/Aww/ll5VkTr9   z!https://imgur.com/gallery/YcAQlkxImgurYcAQlkxr*   zRClassic Steve Carell gif...cracks me up everytime....damn the repost downvotes....iP201301191648642wittyusernameherez https://i.imgur.com/YcAQlkxh.jpgz=https://i.imgur.com/N5Flb2v_d.png?maxwidth=290&fidelity=grand)r,   r-   r.   r/   r0   r   r   r3   r6   r4   r   r2   r1   r5   )r7   add_iesr8   zbhttps://imgur.com/gallery/classic-steve-carell-gif-cracks-me-up-everytime-repost-downvotes-YcAQlkx)r,   r-   r.   r/   r0   r   r   r3   r4   r6   r   r2   r1   r5   z$http://imgur.com/topic/Funny/N8rOuddzhttp://imgur.com/r/aww/VQcQPhMVQcQPhMzThe boss is hereiX2016101519138530thematrixcamz=https://i.imgur.com/qCjr5Pi_d.png?maxwidth=290&fidelity=grandz https://i.imgur.com/VQcQPhMh.jpg)r,   r-   r.   r/   r0   r   r   r2   r1   r   r3   r5   r4   r6   z#https://imgur.com/t/unmuted/6lAn9VQ6lAn9VQz
Penguins !r,   r.      r7   r8   playlist_countz5https://imgur.com/t/unmuted/penguins-penguins-6lAn9VQz#https://imgur.com/t/unmuted/kx2uD3CZVMv45iIntruderih[20180604gHz>@z https://i.imgur.com/ZVMv45ih.jpg)r,   r-   r.   r/   r0   r3   r4   r5   r1   r2   r=   r6   z#https://imgur.com/t/unmuted/wXSK0YH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[20180531z https://i.imgur.com/JCAP4ioh.jpg)r,   r-   r.   rp   r/   r0   r5   r1   r=   r2   r3   r6   r4   N)r$   r%   r&   IE_NAMEr   r   r   r   r   r   r   r     s    r   c                   @   sR   e Zd ZdZdZdZdddddd	d
ddddd	d
dddddiddgZdS )ImgurAlbumIEzimgur:albumz?https?://(?:i\.)?imgur\.com/a/(?:[^/?#]+-)?(?P<id>[a-zA-Z0-9]+)Fzhttp://imgur.com/a/j6OrjTr9   zhttps://imgur.com/a/iX265HXiX265HXzenen-no-shouboutair   r   r   z.https://imgur.com/a/enen-no-shouboutai-iX265HXzhttps://imgur.com/a/8pih2Edr,   8pih2Edr   )r7   r8   playlist_mincountN)r$   r%   r&   r   r   r   r   r   r   r   r   r     s2    		r   )r   r   commonr   utilsr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s    4 F%|