a
    h[W                     @   s   d dl Z d dlZ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mZmZmZ G dd deZG dd	 d	eZG d
d deZdS )    N   )InfoExtractor   )ExtractorError
clean_htmldetermine_extdict_getextract_attributesfloat_or_noneint_or_nonejoin_nonemptyparse_durationstr_or_nonetry_calltry_getunified_strdateurl_or_nonec                   @   s4  e Zd ZdZde dZdddddd	d
ddddddddeedddddddddddddededddd giid!d"d#d$d%dd&d'd(d)d)d*ded+dedd,d-d.d/d0d1d2d0d1d3d0d1d4d0d1d5d0d1d6d0d1d7d0d1d8d0d1d9d0d1d:d0d1d;d0d1d<d0d1d=d0d1d>d0d1d?d0d1gZd@ZdAdB ZdCdD Z	dES )F
XHamsterIEzX(?:xhamster\.(?:com|one|desi)|xhms\.pro|xhamster\d+\.(?:com|desi)|xhday\.com|xhvid\.com)zI(?x)
                    https?://
                        (?:[^/?#]+\.)?z/
                        (?:
                            movies/(?P<id>[\dA-Za-z]+)/(?P<display_id>[^/]*)\.html|
                            videos/(?P<display_id_2>[^/]*)-(?P<id_2>[\dA-Za-z]+)
                        )
                    zIhttps://xhamster.com/videos/femaleagent-shy-beauty-takes-the-bait-1509445Z e009ea6b849b129e3bebaeb9cf0dee51Z1509445z%femaleagent-shy-beauty-takes-the-baitmp4z%FemaleAgent Shy beauty takes the baitiVzPZ20121014ZRuseful2011Zruseful2011i}     re:https?://.+\.jpgz&https://xhamster.com/users/ruseful2011 )id
display_idexttitle	timestampupload_dateuploaderuploader_idduration	age_limit	thumbnailuploader_urldescription
view_countcomment_count)urlmd5	info_dictzAhttps://xhamster.com/videos/britney-spears-sexy-booty-2221348?hd=Z2221348zbritney-spears-sexy-bootyzBritney Spears  Sexy Bootyi3RZ20130914Z
jojo747400   )r   r   r   r   r   r   r   r    r!   r$   r%   r"   r&   ZgenericZimpersonateZchromem3u8)Zextractor_argsskip_downloadr'   r)   paramsz(http://xhamster.com/movies/5667973/.htmlZ5667973z....iVZ20160208Z
parejafreeH   z%https://xhamster.com/users/parejafree)r   r   r   r   r   r   r   r    r!   r&   r#   r$   r%   r"   zInvalid URL)r'   r)   skipzLhttps://m.xhamster.com/videos/cute-teen-jacqueline-solo-masturbation-8559111Tr'   Zonly_matchingzChttps://xhamster.com/movies/2272726/amber_slayed_by_the_knight.htmlz9https://it.xhamster.com/movies/7263980/la_mia_vicina.htmlz9https://pt.xhamster.com/videos/euro-pedal-pumping-7937821zIhttps://xhamster.one/videos/femaleagent-shy-beauty-takes-the-bait-1509445zJhttps://xhamster.desi/videos/femaleagent-shy-beauty-takes-the-bait-1509445zJhttps://xhamster2.com/videos/femaleagent-shy-beauty-takes-the-bait-1509445zKhttps://xhamster11.com/videos/femaleagent-shy-beauty-takes-the-bait-1509445zKhttps://xhamster26.com/videos/femaleagent-shy-beauty-takes-the-bait-1509445zMhttp://xhamster.com/movies/1509445/femaleagent_shy_beauty_takes_the_bait.htmlzDhttp://xhamster.com/movies/2221348/britney_spears_sexy_booty.html?hdzRhttp://de.xhamster.com/videos/skinny-girl-fucks-herself-hard-in-the-forest-xhnBJZxz4https://xhday.com/videos/strapless-threesome-xhh7yVfz&https://xhvid.com/videos/lk-mm-xhc6wn6zPhttps://xhamster20.desi/videos/my-verification-video-scottishmistress23-11937369s   xh7999c                    s   t  fddpd gd \}}}|r(|s>| d| d d S |dkrntdd t| t| jD  S |d	krt	||S | d| d
| d d S )Nc                      s   t   dS )N_)base64	b64decodedecode	partition 
format_urlr7   N/mnt/pikpak/tmp/myenv/lib/python3.9/site-packages/yt_dlp/extractor/xhamster.py<lambda>       z1XHamsterIE._decipher_format_url.<locals>.<lambda>   zSkipping format "z": failed to decipher URLxorc                 s   s   | ]\}}||A V  qd S )Nr7   ).0abr7   r7   r:   	<genexpr>   s   z2XHamsterIE._decipher_format_url.<locals>.<genexpr>rot13z": unsupported cipher type "")
r   Zreport_warningbyteszipencode	itertoolscycle_XOR_KEYr5   codecs)selfr9   	format_idZcipher_typer2   Z
ciphertextr7   r8   r:   _decipher_format_url   s     
zXHamsterIE._decipher_format_urlc           4         s    |}|dp|d}|dp0|d}tdd|} ||\}} jd|dd d	}|rrt|d
d |}	 fdd}
 j j	d|ddd	|dd}|r|d }|d }g }t
 }i }t|dd tpi }| D ]\}}t|tsqt|dd tpi }| D ],\}}t|ts0qt|d||< q| D ]z\}}|dkrdqN|}t|}|rN||v rqN|| || d| |t|d|
|||d|jid qNqt|dd t}|r|d}t|trdd D ]f}||}|sq |d!| }|r||v r:q|| | j||dd"ddd# q|d$}t|tr| D ]\}}t|tsq|D ]} t| tsqd D ]}!| |!}"|"sАqt| d%pt| d&pd'}t||} |"|}"|"r|"|v rq||" t|"d}#|#d(kr\| j|"|dd"ddd# q|||"|#|
|||d|"id qqq|d)}$t|$trg }%|$D ]6}&t|&tsq|&d*}'t|'tr|%|' qnd }%tt|d+d }(||||d,t|d-t|d.d t|(|(r:|(d/d0 nd |d1t|d2t|d3tt|d4d ttt|d5d tt|d6|	d ur|	nd7|%|d8S  g d9|d}g }t
 } j j	d:|d;dd	|dd}| D ]J\}}t|}|sq||v rq|| ||||
|d< q j	g d=|d>dd d?})|)rj|)|vrj|d@|)i t dA|}|r|dBnd }*t! j	dC|dDdd}+ jdE|dFdGd	}, j	dHdIg|dJddJdK}-t" j	dLdMg|d2dd}.t j	dN|dOdd}/t dP|}|r |dQ|dRfndS\}0}1t dT|}|rD|dUndV}2 j	dW|d)d d	}3|3rvdXdY t#dZ|3D nd }%||||*|+|,|,r|,$ nd |-|.|/t|0t|1t|2|	|%|d[S )\Nr   Zid_2r   Zdisplay_id_2z^(https?://(?:.+?\.)?)m\.z\1z2<div[^>]+id=["\']videoClosed["\'][^>]*>(.+?)</div>errordefaultT)expectedc                    s   t  jd| dd dS )Nz
^(\d+)[pP]heightrP   )r   _search_regex)srL   r7   r:   
get_height   s    z,XHamsterIE._real_extract.<locals>.get_height)z.window\.initials\s*=\s*({.+?})\s*;\s*</script>z"window\.initials\s*=\s*({.+?})\s*;initialsz{}F)fatalZ
videoModelr   c                 S   s   | d S )Nsourcesr7   xr7   r7   r:   r;      r<   z*XHamsterIE._real_extract.<locals>.<lambda>c                 S   s   | d S )Ndownloadr7   r[   r7   r7   r:   r;      r<   sizer]   -r   ZReferer)rM   r'   r   rS   filesizeZhttp_headersc                 S   s   | d d S )NZxplayerSettingsrZ   r7   r[   r7   r7   r:   r;      r<   Zhls)r'   fallbackzhls-Zm3u8_native)Zentry_protocolZm3u8_idrY   standardqualitylabelr   r+   
categoriesnamec                 S   s   | d d S )NauthorZpageURLr7   r[   r7   r7   r:   r;   &  r<   r$   createdc                 S   s   | d d S )Nrg   rf   r7   r[   r7   r7   r:   r;   .  r<   /ZthumbURLr    Zviewsc                 S   s   | d d S )NratingZlikesr7   r[   r7   r7   r:   r;   5  r<   c                 S   s   | d d S )Nrk   Zdislikesr7   r[   r7   r7   r:   r;   7  r<   commentsr   )r   r   r   r$   r   r   r#   r   r"   r    r%   
like_countdislike_countr&   r!   re   formats)z<h1[^>]*>([^<]+)</h1>z6<meta[^>]+itemprop=".*?caption.*?"[^>]+content="(.+?)"zY<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>zsources\s*:\s*({.+?})\s*,?\s*\nrZ   )rM   r'   rS   )z(file\s*:\s*(?P<q>["'])(?P<mp4>.+?)(?P=q)z<<a\s+href=(?P<q>["'])(?P<mp4>.+?)(?P=q)\s+class=["']mp4Thumbz3<video[^>]+file=(?P<q>["'])(?P<mp4>.+?)(?P=q)[^>]*>z	video url)grouprQ   r'   z!<span>Description: </span>([^<]+)r   z:hint=["\'](\d{4}-\d{2}-\d{2}) \d{2}:\d{2}:\d{2} [A-Z]{3,4}zupload datez><span[^>]+itemprop=["\']author[^>]+><a[^>]+><span[^>]+>([^<]+)r   Z	anonymousz:["']thumbUrl["']\s*:\s*(?P<q>["'])(?P<thumbnail>.+?)(?P=q)z=<video[^>]+"poster"=(?P<q>["'])(?P<thumbnail>.+?)(?P=q)[^>]*>r"   )rY   rp   zA<[^<]+\bitemprop=["\']duration["\'][^<]+\bcontent=["\'](.+?)["\']zRuntime:\s*</span>\s*([\d:]+)z%content=["\']User(?:View|Play)s:(\d+)z
view countzChint=[\'"](?P<likecount>\d+) Likes / (?P<dislikecount>\d+) DislikesZ	likecountZdislikecount)NNz0</label>Comments \((?P<commentcount>\d+)\)</div>Zcommentcountr   z+(?s)<table.+?(<span>Categories:.+?)</table>c                 S   s   g | ]}t |qS r7   )r   )r?   categoryr7   r7   r:   
<listcomp>  r<   z,XHamsterIE._real_extract.<locals>.<listcomp>z<a[^>]+>(.+?)</a>)r   r   r   r$   r   r   r   r"   r    r%   rm   rn   r&   r!   re   ro   )%_match_valid_urlrp   resubZ_download_webpage_handleZ_html_search_regexr   Z_rta_search_parse_jsonrT   setr   dictitems
isinstancer
   getr   addappendr   r'   rN   extendZ_extract_m3u8_formatslistr   r   strr   splitintsearchr   r   findalllower)4rL   r'   mobjvideo_idr   Zdesktop_urlwebpageZurlhrO   r!   rW   rX   videor   ro   Zformat_urlsZformat_sizesrZ   rM   Zformats_dictZdownload_sourcesrc   Zformat_dictZformat_itemr9   Zxplayer_sourcesZhls_sourcesZhls_format_keyZhls_urlZstandard_sources
identifierZformats_listZstandard_formatZstandard_format_keyZstandard_urlr   Zcategories_listre   cZc_namer#   	video_urlr$   r   r   r"   r    r%   rm   rn   r&   Zcategories_htmlr7   rV   r:   _real_extract   s   






















"zXHamsterIE._real_extractN)
__name__
__module____qualname___DOMAINS
_VALID_URLr   _TESTSrJ   rN   r   r7   r7   r7   r:   r      s   	or   c                   @   s   e Zd Zdej dZdgZddddedd	d
dddddddeddgZdddddedddddddddedd d!id"gZ	d#d$ Z
d%S )&XHamsterEmbedIEhttps?://(?:[^/?#]+\.)?z/xembed\.php\?video=(?P<id>\d+)z_<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1z,http://xhamster.com/xembed.php?video=3328539Z3328539r   zPen Masturbationr   zpen-masturbationieSZ20140728ZManyakisArt   r   r   Zmanyakisartz&https://xhamster.com/users/manyakisart)r   r   r   r&   r$   r   r   r   r   r    r!   r"   r   r#   r%   )r'   r)   z https://xhamster.com/awards/2023Zxh2VnYnz"xHamster Awards 2023 - The Winnersz xhamster-awards-2023-the-winnersi$  z$re:https?://ic-vt-nss\.xhcdn\.com/.+iUeZ20231116ZxHamsterZxhamsterz#https://xhamster.com/users/xhamster)r   r   r   r!   r&   r$   r   r    r"   r   r   r   r   r#   r%   r,   r+   r-   c                 C   sf   |  |}| ||}| jd| d| d|dd d}|sZ| | d|d|}t|d}| |d	S )
Nz(href="(https?://xhamster\.com/(?:movies/z/[^"]*\.html|videos/[^/]*-z)[^"]*)"zxhamster urlrP   zvars\s*:\s*({.+?})\s*,\s*\nvars)ZdownloadLinkZhomepageLinkZcommentsLinkZshareUrlZXHamster)	_match_id_download_webpagerT   rv   r   
url_result)rL   r'   r   r   r   Zplayer_varsr7   r7   r:   r     s    

zXHamsterEmbedIE._real_extractN)r   r   r   r   r   r   Z_EMBED_REGEXr   r   Z_WEBPAGE_TESTSr   r7   r7   r7   r:   r     sP   r   c                   @   sh   e Zd Zdej dZdddiddddd	id
ddddiddddddddgZdd Zdd ZdS )XHamsterUserIEr   z./(?:(?P<user>users)|creators)/(?P<id>[^/?#&]+)z/https://xhamster.com/users/netvideogirls/videosr   Znetvideogirlsi  )r'   r)   Zplaylist_mincountz+https://xhamster.com/users/firatkaan/videosZ	firatkaanr   z.https://xhamster.com/creators/squirt-orgasm-69zsquirt-orgasm-69.   z!https://xhday.com/users/mobhunterTr1   z!https://xhvid.com/users/pelushe21c                 c   s   |rdnd\}}d| d| d| d}t dD ]}| ||d| }td|D ]J}t|}	t|	d	}
|
rVt	|
sqVt
|
}| j|
t |d
V  qVtd|}|s qt|d}t|d	}|s2 qq2d S )N)ZusersZvideos)ZcreatorsZ	exclusivezhttps://xhamster.com/ri   z/1r   zDownloading page z;(<a[^>]+class=["\'].*?\bvideo-thumb__image-container[^>]+>)href)Zier   z <a[^>]+data-page=["\']next[^>]+>r   )rH   countr   rt   r   r	   r   r{   r   Zsuitabler   r   Zie_keyr   rp   )rL   user_idZis_userprefixsuffixZnext_page_urlZpagenumpageZ	video_tagr   r   r   r   Z	next_pager7   r7   r:   _entries  s2    


zXHamsterUserIE._entriesc                 C   s.   |  |dd\}}| | |t||S )Nuserr   )rs   rp   Zplaylist_resultr   bool)rL   r'   r   r   r7   r7   r:   r     s    zXHamsterUserIE._real_extractN)	r   r   r   r   r   r   r   r   r   r7   r7   r7   r:   r     s2   	r   )r3   rK   rH   rt   commonr   utilsr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r7   r7   r7   r:   <module>   s   @   	@