U
    $PfI                     @   s   d dl mZ d dlZd dlZddlm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 G dd	 d	eZG d
d deZG dd deZdS )    )unicode_literalsN   )InfoExtractor   )
compat_str)
clean_htmldetermine_extdict_getextract_attributesExtractorErrorfloat_or_noneint_or_noneparse_durationstr_or_nonetry_getunified_strdateurl_or_noneurljoinc                   @   s   e Zd ZdZde Zddddddd	d
dddd	dddddddddddd	ddidddddddd d!dd"ddidd#dd$d%dd$d&dd$d'dd$d(dd$d)dd$d*dd$d+dd$d,dd$d-dd$d.dd$d/dd$gZd0d1 Zd2S )3
XHamsterIEz9(?:xhamster\.(?:com|one|desi)|xhms\.pro|xhamster\d+\.com)a8  (?x)
                    https?://
                        (?:.+?\.)?%s/
                        (?:
                            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 98b4687efb1ffd331c4197854dc09e8fZ1509445z%femaleagent-shy-beauty-takes-the-baitmp4z%FemaleAgent Shy beauty takes the baitiVzPZ20121014ZRuseful2011i}     )	id
display_idexttitle	timestampupload_dateuploaderduration	age_limit)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   Zskip_downloadT)r    r"   paramsz(http://xhamster.com/movies/5667973/.htmlZ5667973z....iVZ20160208Z
parejafreeH   r   r   r   r   r   r   r   r   zLhttps://m.xhamster.com/videos/cute-teen-jacqueline-solo-masturbation-8559111)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-xhnBJZxc           2         s  t  j|}|dp |d}|dp4|d}t dd|} ||\}} jd|dd d	}|rvt|d
d |}	 fdd}
 j	 j
d|ddd	|dd}|rt|d }|d }g }t }i }t|dd tpi }| D ]\}}t|tsqt|dd tpi }| D ],\}}t|ts4qt|d||< q| D ]z\}}|dkrhqR|}t|}|rR||krqR|| |d||f |t|d|
|||d| id qRqt|dd t}|r|d}t|tr`d D ]^}||}|sq t||}|r ||kr6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||!}!|!r|!|krq||! t|!d}"|"d$kr(| j|!|dd!ddd" qt|d%pJt|d&pJd'}|d||f |!|"|
|||d|!id qqq~ j|d(d) |d*}#t|#trg }$|#D ]6}%t|%tsƐq|%d+}&t|&tr|$|& qnd }$||||d,t|d-t|d.d t|d/t|d0t|d1tt|d2d ttt|d3d tt|d1|	|$|d4S  d5d6d7g|d}g }t } j	 j
d8|d9dd	|dd}| D ]J\}}t|}|sҐq||krq|| ||||
|d: q j
d;d<d=g|d>dd d?}'|'r<|'|kr<|d@|'i  | t  dA|}|rb|dBnd }(t! j
dC|dDdd}) jdE|dFdGd	}* j
dHdIg|dJddJdK}+t" j
dLdMg|d0dd},t j
dN|dOdd}-t  dP|}|r|dQ|dRfndS\}.}/t  dT|}|r |dUndV}0 j
dW|d*d d	}1|1rRdXdY t #dZ|1D nd }$||||(|)|*|+|,|-t|.t|/t|0|	|$|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]heightr(   )r   _search_regex)sself A/tmp/pip-unpacked-wheel-7zdooeg3/youtube_dl/extractor/xhamster.py
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sourcesr0   xr0   r0   r1   <lambda>       z*XHamsterIE._real_extract.<locals>.<lambda>c                 S   s   | d S )Ndownloadr0   r6   r0   r0   r1   r8      r9   sizer:   z%s-%sr   ZReferer)	format_idr    r   r+   filesizeZhttp_headersc                 S   s   | d d S )NZxplayerSettingsr5   r0   r6   r0   r0   r1   r8      r9   Zhls)r    fallbackZm3u8_native)Zentry_protocolZm3u8_idr4   standardZm3u8qualitylabel )r+   widthZtbrr<   )Zfield_preference
categoriesnamedescriptioncreatedc                 S   s   | d d S )NauthorrE   r0   r6   r0   r0   r1   r8      r9   ZthumbURLr   Zviewsc                 S   s   | d d S )NratingZlikesr0   r6   r0   r0   r1   r8     r9   c                 S   s   | d d S )NrI   Zdislikesr0   r6   r0   r0   r1   r8     r9   )r   r   r   rF   r   r   	thumbnailr   
view_count
like_countdislike_countcomment_countr   rD   formatsz<h1[^>]*>([^<]+)</h1>z6<meta[^>]+itemprop=".*?caption.*?"[^>]+content="(.+?)"zY<title[^>]*>(.+?)(?:,\s*[^,]*?\s*Porn\s*[^,]*?:\s*xHamster[^<]*| - xHamster\.com)</title>zsources\s*:\s*({.+?})\s*,?\s*\nr5   )r<   r    r+   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)groupr)   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)[^>]*>rJ   )r4   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 r0   )r   ).0categoryr0   r0   r1   
<listcomp>Y  s     z,XHamsterIE._real_extract.<locals>.<listcomp>z<a[^>]+>(.+?)</a>)r   r   r   rF   r   r   rJ   r   rK   rL   rM   rN   r   rD   rO   )$rematch
_VALID_URLrP   subZ_download_webpage_handleZ_html_search_regexr   Z_rta_search_parse_jsonr,   setr   dictitems
isinstancer   getr   addappendr   geturlr   extendZ_extract_m3u8_formatslistr   Z_sort_formatsr   r   intsearchr   r   findall)2r/   r    mobjvideo_idr   Zdesktop_urlwebpageZurlhr'   r   r2   r3   videor   rO   Zformat_urlsZformat_sizesr5   r<   Zformats_dictZdownload_sourcesr@   Zformat_dictZformat_itemZ
format_urlZxplayer_sourcesZhls_sourcesZhls_format_keyZhls_urlZstandard_sourcesZformats_listZstandard_formatZstandard_format_keyZstandard_urlr   Zcategories_listrD   cZc_name	video_urlrF   r   r   rJ   r   rK   rL   rM   rN   Zcategories_htmlr0   r.   r1   _real_extractz   s2     
  



 
  



    





    
 


          

    
          "   zXHamsterIE._real_extractN)__name__
__module____qualname___DOMAINSrV   _TESTSrl   r0   r0   r0   r1   r      s   	  Wr   c                
   @   sF   e Zd Zdej Zdddddddd	d
ddZedd Zdd Z	dS )XHamsterEmbedIEz4https?://(?:.+?\.)?%s/xembed\.php\?video=(?P<id>\d+)z,http://xhamster.com/xembed.php?video=3328539Z3328539r   zPen MasturbationieSZ20140728ZManyakisArt   r   r&   )r    r"   c                 C   s   dd t d| D S )Nc                 S   s   g | ]\}}|qS r0   r0   )rQ   _r    r0   r0   r1   rS     s     z1XHamsterEmbedIE._extract_urls.<locals>.<listcomp>z_<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?xhamster\.com/xembed\.php\?video=\d+)\1)rT   re   )rh   r0   r0   r1   _extract_urls  s    
zXHamsterEmbedIE._extract_urlsc                 C   s^   |  |}| ||}| jd||dd d}|sR| | d|d|}t|d}| |dS )NzPhref="(https?://xhamster\.com/(?:movies/{0}/[^"]*\.html|videos/[^/]*-{0})[^"]*)"zxhamster urlr(   zvars\s*:\s*({.+?})\s*,\s*\nvars)ZdownloadLinkZhomepageLinkZcommentsLinkZshareUrlZXHamster)	_match_id_download_webpager,   formatrX   r	   
url_result)r/   r    rg   rh   rk   rv   r0   r0   r1   rl     s    
  
zXHamsterEmbedIE._real_extractN)
rm   rn   ro   r   rp   rV   Z_TESTstaticmethodru   rl   r0   r0   r0   r1   rr   o  s   

rr   c                   @   sF   e Zd Zdej Zdddidddddid	dgZd
d Zdd ZdS )XHamsterUserIEz,https?://(?:.+?\.)?%s/users/(?P<id>[^/?#&]+)z/https://xhamster.com/users/netvideogirls/videosr   Znetvideogirlsi  )r    r"   Zplaylist_mincountz+https://xhamster.com/users/firatkaan/videosZ	firatkaanr   c                 c   s   d| }t dD ]}| ||d| }td|D ]J}t|}t|d}|r4t	|s^q4t
|}| j|t |dV  q4td|}	|	s qt|	d}
t|
d}|s qqd S )	Nz&https://xhamster.com/users/%s/videos/1r   zDownloading page %sz;(<a[^>]+class=["\'].*?\bvideo-thumb__image-container[^>]+>)href)Zierg   z <a[^>]+data-page=["\']next[^>]+>r   )	itertoolscountrx   rT   re   r
   r   r]   r   Zsuitablerw   rz   Zie_keyrd   rP   )r/   user_idZnext_page_urlZpagenumpageZ	video_tagri   rk   rg   rf   Z	next_pager0   r0   r1   _entries  s8      
  
zXHamsterUserIE._entriesc                 C   s   |  |}| | ||S )N)rw   Zplaylist_resultr   )r/   r    r   r0   r0   r1   rl     s    
zXHamsterUserIE._real_extractN)	rm   rn   ro   r   rp   rV   rq   r   rl   r0   r0   r0   r1   r|     s    
 	 r|   )
__future__r   r~   rT   commonr   compatr   utilsr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   rr   r|   r0   r0   r0   r1   <module>   s   <  X(