U
    g                    @   s|  d dl Z d dlZ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 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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)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.G dd de%Z/G dd de%Z0dS )     N   )InfoExtractor   )HEADRequestRequest)	HTTPError)ExtractorErrorOnDemandPagedList
clean_htmldetermine_extget_element_by_classint_or_nonejoin_nonempty
js_to_jsonmerge_dictsparse_filesizeparse_iso8601parse_qs	qualitiessmuggle_urlstr_or_nonetraverse_objtry_getunified_timestampunsmuggle_urlurlencode_postdataurlhandle_detect_exturljoinc                   @   sx   e Zd ZdZdZdZedd Zdd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd Zdd ZdddZdddZdS )VimeoBaseInfoExtractorvimeoFzhttps://vimeo.com/log_inc                 C   s   t | d|iS )Nreferer)r   )urlZreferrer_url r"   :/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/vimeo.py_smuggle_referrer*   s    z(VimeoBaseInfoExtractor._smuggle_referrerc                 C   s:   t |i \}}| d }d|kr0|d |d< |||fS )z&@returns (url, smuggled_data, headers)http_headersr    Referer)r   	get_paramcopy)selfr!   dataheadersr"   r"   r#   _unsmuggle_headers.   s
    z)VimeoBaseInfoExtractor._unsmuggle_headersc              
   C   s   |  dd d}d||d|d d}| d|d  z&| j| jd dt|d	| jd
d W nN tk
r } z0t|jtr|jj	dkrtdddtdW 5 d }~X Y nX d S )Nhttps://vimeo.com/_next/viewerzDownloading login tokenloginr   xsrft)actionemailpasswordZservicetokenvuidz
Logging in!application/x-www-form-urlencoded)Content-Typer&   r*   r+     z*Unable to log in: bad username or passwordTexpectedzUnable to log in)
_download_json_set_vimeo_cookie_download_webpage
_LOGIN_URLr   r   
isinstancecauser   status)r)   usernamer2   viewerr*   er"   r"   r#   _perform_login6   s2      
z%VimeoBaseInfoExtractor._perform_loginc                 C   s"   | j r| dds|   d S )Nhttps://vimeo.comr4   )_LOGIN_REQUIRED_get_cookiesgetZ_raise_login_required)r)   r"   r"   r#   _real_initializeN   s    z'VimeoBaseInfoExtractor._real_initializec                 C   s"   |  d}|d krtddd|S )NvideopasswordzFThis video is protected by a password, use the --video-password optionTr9   )r'   r   )r)   r2   r"   r"   r#   _get_video_passwordR   s    
z*VimeoBaseInfoExtractor._get_video_passwordc              
   C   s   d| }z:| j | d|dtj||ddd dd|d	d
dW S  tk
r } z*t|jtrz|jjdkrztdd
d W 5 d }~X Y nX d S )Nhttps://vimeo.com/z	/passwordzSubmitting video passwordr2   r3   ),:)
separatorsz*/*application/json)Acceptr6   r&   T)r*   r+   impersonater8   Wrong passwordr9   )	r=   jsondumpsencoder   r?   r@   r   rA   )r)   video_idr2   r3   r!   errorr"   r"   r#   _verify_video_passwordZ   s,    
  
z-VimeoBaseInfoExtractor._verify_video_passwordc                 O   s*   | j d|df||}|r&| ||S d S )Nz<vimeo\.config\s*=\s*(?:({.+?})|_extend\([^,]+,\s+({.+?})\));zvimeo config)_search_regex_parse_json)r)   webpagerY   argskwargsvimeo_configr"   r"   r#   _extract_vimeo_configl   s     z,VimeoBaseInfoExtractor._extract_vimeo_configc                 C   s   |  d|| d S )Nz	vimeo.com)Z_set_cookie)r)   namevaluer"   r"   r#   r<   s   s    z(VimeoBaseInfoExtractor._set_vimeo_cookiec           '         sB  |d }| d}| dpi }ddddd | d}|dk}| d	pNi }g }	i }
| d
pn| d
pni }| dp|g D ]b}| d}|sq~|	|d| ddt| dt| dt| dt| dd q~d}t|}d}dD ] t| fddpi  D ]\}}| d}|s6q  d| }g }t||rdD ].\}}||| t	|d| d|f qZn
||fg}|D ]\}} dkr.| j
||d||d| d d!d"\}}|D ]<}td#d$| d%|d&  }r||d'|d< q|	| | j||
d( nz d)krd*|krh| j||d!d+pVi  d}|rh|}| j|d,d-||d| d.d!d+\}}|	| | j||
d( qqq| d/pi }| d0}|r| dd1kr|	d2|dd3 | d4pg D ],} |
| d5 g d6td7| d d8 qg }!|s| d9pJi  D ] \}"}#|!|"t|"|#d: qP| d;}$|$r|!d|$i | d<pi }%|% d}&t| d=p|||% d>|&r|&dd? nd |&|!t| d@tt|dAdBdCd dthfdDthfdEfdFd dGp$d |	|
|t|dHdIthfdJdKS )LNvideotitle
live_eventZis_upcomingis_liveZ	post_live)pendingactivestartedZendedrA   requestfilesZprogressiver!   zhttp-{}quality
   widthheightfpsZbitrate)r!   	format_idZsource_preferencerp   rq   rr   Ztbr)lowZmediumhighz/sep/video/)hlsdashc                    s   |   d S )NZcdnsr"   xZ
files_typer"   r#   <lambda>       z6VimeoBaseInfoExtractor._parse_config.<locals>.<lambda>-)) re   )Z_sepz	sep/video/rv   mp4zDownloading z m3u8 informationF)ZliveZm3u8_idnotefatalzaudio-(|)rs   r   )targetrw   zjson=1r   z/master.jsonz/master.mpdz MPD informationarchive
source_urldonezlive-archive-source)rs   r!   rn   Ztext_trackslangZvttrF   )extr!   Zthumbs)idrp   r!   	thumbnailownerr   rc   durationembedchaptersc                 S   s   t |d d k	S )Ntimecode)int)_vr"   r"   r#   r{      r|   r   )rf   
start_timec                 S   s   | d S )Nr   r"   )cr"   r"   r#   r{      r|   )keyZingestZscheduled_start_time)rn   resrr   zhdr:12source)r   rf   uploaderuploader_iduploader_url
thumbnailsr   r   formats	subtitleslive_statusrelease_timestamp_format_sort_fields)rI   appendformatr   r   r   itemsresearchsubZ#_extract_m3u8_formats_and_subtitlesjoingroupextendZ_merge_subtitlesr;   Z"_extract_mpd_formats_and_subtitlesreplace
setdefaultr   r   splitsortedr   strr   )'r)   configrY   Z
video_datavideo_titlerg   r   rh   rl   r   r   config_filesf	video_urlZ	QUALITIESrn   Zsep_patternZcdn_nameZcdn_dataZmanifest_urlrs   Zsep_manifest_urlssuffixreplZf_idZm_urlZfmtssubsmobjZ
real_m_urlZlive_archiveZlive_archive_source_urlttr   r   Zthumbr   r   Zvideo_uploader_urlr"   rz   r#   _parse_configv   s   



&
 
 

    

$



  




 
  z$VimeoBaseInfoExtractor._parse_configNc                 K   sB   | j td| |dd|dfd| dddd	d
id|S )Nzhttps://api.vimeo.com/videos/rP   )delimzDownloading API JSONjwt rR   AuthorizationrS   fieldsrO   )	
config_urlZcreated_timedescriptiondownloadlicensez#metadata.connections.comments.totalz metadata.connections.likes.totalZrelease_timezstats.playsr+   query)r;   r   r   )r)   rY   Z	jwt_tokenunlisted_hashr`   r"   r"   r#   _call_videos_api   s      
z'VimeoBaseInfoExtractor._call_videos_apic                 C   s  |  ddsd S ddi}|r(||d< | j||dd|dd	id
dpFi }|d}t|dd }	|	r|ds|ds|dd}
| |	||
 drt|dd tpt|	d pd }|	|t|dt|dt	|d|
ddS |pt
| jd|ddddthf}|sd S |p2| j|||dd
d}t
|d d!thfD ]}|d"}	|	rF|d#d$krnqFtt|	d%d&gd'  d d(}|s| jt|	|dd)d*}|ot|}|	|pd+|ddt|dt|dt|d,t|ddd-  S d S ).NrM   r   r0   Zload_download_configr   zLoading download config JSONFX-Requested-WithXMLHttpRequest)  i  )r   r   r+   expected_statussource_filec                 S   s   | d S )Ndownload_urlr"   rx   r"   r"   r#   r{     r|   zAVimeoBaseInfoExtractor._extract_original_format.<locals>.<lambda>Zis_coldZis_defrostingZpublic_nameZOriginalz videoc                 S   s   | d S )N	extensionr"   rx   r"   r"   r#   r{     r|   r   rp   rq   sizer   )r!   r   rp   rq   filesizers   rn   https://vimeo.com/_rv/viewerzDownloading jwt tokenr   jwt)r   r   r   .linkrn   r   filenamer~   r   )Zdefault_extzDetermining source extension)r   r   Zunknown_videorr   )r!   r   rs   rp   rq   rr   r   rn   )rH   rI   r;   r   Z_is_valid_urlr   r   lowerr   r   r   r   dictr   Z_request_webpager   r   )r)   r!   rY   r   r   api_datar   Zdownload_datar   r   Zsource_namer   original_responseurlhr"   r"   r#   _extract_original_format  s        
  
   
    
"   
z/VimeoBaseInfoExtractor._extract_original_format)N)NNN)__name__
__module____qualname__Z_NETRC_MACHINErG   r>   staticmethodr$   r,   rE   rJ   rL   r[   rb   r<   r   r   r   r"   r"   r"   r#   r   %   s   

r   c                .       s  e Zd ZdZdZdZdddgZ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"d#ddid$gd%d&d'd(d)d
d*d+d,d+d,d-d.d/deed0d1dd2d3d$gd%d4d5d6d
d7d8d9d:d;d<d=d>d?d@dAeeedBddCid$gdDdEdFdGd
dHedIdJdIdJdKdLdMdNeedOdPdPdPdPdQdRdSd$gdTdUdVdWd
dXdYdZd[d\d]d#d$gdTd^d_d
d`dadbdcdddedfdgeedhedidjd$gdkdldmdnd
dodpdqdrdsdtdudvdwdxd$gdydzd{d
d|d}d~dddddedeededdddgdddid$gdddd
dddddddd	ddidddd'd)d
d*d-d.d/dd0ddd2d3d$gdDddddddddddddddddd
dddeddddedeeddd2d3d$gdddddddd
ddddddddededddddid$gdddd
ddddddddddeeedɜddid$gdddd
ddddddddeededdddלddid$gddddddd
dddededddddddddid$gdddd
dddddddddddddddddddddddddddddddddddddddddddd ddd dddddddgd	ddidؐdd$gdd	d
d
ddddddddddeeeddd$gdkddd
dddddddd$gdkdddgZ	e
 fdd Ze
d!d" Zd#d$ Zd,d&d'Zd(d) Zd*d+ Z  ZS (-  VimeoIEz$Information extractor for vimeo.com.ab  (?x)
                     https?://
                         (?:
                             (?:
                                 www|
                                 player
                             )
                             \.
                         )?
                         vimeo\.com/
                         (?:
                             (?P<u>user)|
                             (?!(?:channels|album|showcase)/[^/?#]+/?(?:$|[?#])|[^/]+/review/|ondemand/)
                             (?:.*?/)??
                             (?P<q>
                                 (?:
                                     play_redirect_hls|
                                     moogaloop\.swf)\?clip_id=
                             )?
                             (?:videos?/)?
                         )
                         (?P<id>[0-9]+)
                         (?(u)
                             /(?!videos|likes)[^/?#]+/?|
                             (?(q)|/(?P<unlisted_hash>[\da-f]{10}))?
                         )
                         (?:(?(q)[&]|(?(u)|/?)[?]).*?)?(?:[#].*)?$
                 r   zP<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//player\.vimeo\.com/video/\d+.*?)\1zV<embed[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/moogaloop\.swf.+?)\1zJ<video[^>]+src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?vimeo\.com/[0-9]+)\1zhttp://vimeo.com/56015672#at=0Z 8879b6cc097e987f02484baf890129e5Z56015672r   u.   youtube-dl test video '' ä↭𝕐-BaW jenozKcz$md5:2d3305bad981a06ff79f027f19865021iPZ20121220z,re:https?://(?:www\.)?vimeo\.com/user7108434Zuser7108434zFilippo Valsordaro   zby-sa)r   r   rf   r   	timestampupload_dater   r   r   r   r   r   best[protocol=https]zNo longer available)r!   md5	info_dictparamsskipz'https://player.vimeo.com/video/54469442Z 619b811a4417aa4abe78dc653becf511z,Videos that embed the url in the player pageZ54469442zIKathy Sierra: Building the minimum Badass User, Business of Software 2012zBusiness of Softwarez3re:https?://(?:www\.)?vimeo\.com/businessofsoftwareZbusinessofsoftwarei  znhttps://i.vimeocdn.com/video/376682406-f34043e7b766af6bef2af81366eacd6724f3fc3173179a11a97a1e26587c9529-d_1280)r   r   rf   r   r   r   r   r   z$Failed to parse XML: not well-formed)r!   r   r   r   r   expected_warningszhttp://vimeo.com/68375962Z aaf896bdb7ddd6476df50007a0ac0ae7zVideo protected with passwordZ68375962z(youtube-dl password protected test videoiQZ20130614z-re:https?://(?:www\.)?vimeo\.com/user18948128Zuser18948128u   Jaime Marquínez Ferrándizznhttps://i.vimeocdn.com/video/440665496-b2c5aee2b61089442c794f64113a8e8f7d5763c3e6b3ebfaf696ae6413f8b1f4-d_1280)r   r   rf   r   r   r   release_dater   r   r   r   comment_count
like_countr   
youtube-dl)r   rK   z+http://vimeo.com/channels/keypeele/75629013Z 2f86a05afe9d7abc0b9126d229bbe15dZ75629013z$Key & Peele: Terrorist Interrogationz$md5:6173f270cd0c0119f22817204b3eb86cz(re:https?://(?:www\.)?vimeo\.com/atencioZatenciozPeter AtencioZkeypeelez2re:https?://(?:www\.)?vimeo\.com/channels/keypeeleiOFRZ20130928   znhttps://i.vimeocdn.com/video/450239872-a05512d9b1e55d707a7c04365c10980f327b06d966351bc403a5d5d65c95e572-d_1280)r   r   rf   r   r   r   r   
channel_idchannel_urlr   r   r   r   
view_countr   r   z
http-1080pr!   r   r   r   r   zhttp://vimeo.com/76979871zVideo with subtitlesZ76979871z+The New Vimeo Player (You Know, For Videos)i]RZ20131015z&re:https?://(?:www\.)?vimeo\.com/staffZstaffVimeo>   znhttps://i.vimeocdn.com/video/452001751-8216e0571c251a09d7a8387550942d89f7f86f6398f8ed886e639b0dd50d3c90-d_1280zcount:3)deenesfr)r   r   rf   r   r   r   r   r   r   r   r   r   r   r   r   r   z2Ignoring subtitle tracks found in the HLS manifest)r!   r   r   r   z'https://player.vimeo.com/video/98044508zCThe js code contains assignments to the same variable as the configZ98044508z Pier Solar OUYA Official Traileru   Tulio Gonçalvesz-re:https?://(?:www\.)?vimeo\.com/user28849593Zuser28849593v   znhttps://i.vimeocdn.com/video/478636036-c18440305ef3df9decfb6bf207a61fe39d2d17fa462a96f6f2d93d30492b037d-d_1280zhttps://vimeo.com/33951933Z33951933z1FOX CLASSICS - Forever Classic ID - A Full MinutezThe DMCIz%re:https?://(?:www\.)?vimeo\.com/dmciZdmciiNZ20111220z$md5:ae23671e82d05415868f7ad1aec21147<   znhttps://i.vimeocdn.com/video/231174622-dd07f015e9221ff529d451e1cc31c982b5d87bfafa48c4189b1da72824ee289a-d_1280zcount:11)r   r   rf   r   r   r   r   r   r   r   r   r   r   r   tags)r!   r   r   z0Contains source format not accessible in webpagezhttps://vimeo.com/393756517Z	393756517i3U^Zframeworklaz#Straight To Hell - Sabrina: NetflixzFramework Studioz$md5:f2edc61af3ea7a5592681ddbb683db73Z20200225   znhttps://i.vimeocdn.com/video/859377297-836494a4ef775e9d4edbace83937d9ad34dc846c688c0c419c0e87f7ab06c4b3-d_1280zhttps://vimeo.com/frameworkla)r   r   r   r   rf   r   r   r   r   r   r   )r   r!   r   r   z+https://vimeo.com/channels/tributes/6213729Z6213729zVimeo Tribute: The ShiningzCasey Donahuez-re:https?://(?:www\.)?vimeo\.com/caseydonahueZcaseydonahuez2re:https?://(?:www\.)?vimeo\.com/channels/tributestributesiJZ20090821iA  zmhttps://i.vimeocdn.com/video/22728298-bfc22146f930de7cf497821c7b0b9f168099201ecca39b00b6bd31fcedfca7a6-d_1280z[the shiningZvimeohqZcvzvimeo tribute])r   r   rf   r   r   r   r   r   r   r   r   r   r   r   r   r   r   skip_downloadTr!   r   r   r   zhttps://vimeo.com/73445910Z73445910zThe Reluctant Revolutionaryz
10Ft Filmsz-re:https?://(?:www\.)?vimeo\.com/tenfootfilmsZtenfootfilmsz$md5:0fa704e05b04f91f40b7f3ca2e801384Z20130830i_ R)	r   r   rf   r   r   r   r   r   r   z!this page is no longer available.)r!   r   r   r   z'https://player.vimeo.com/video/68375962)r   r   rf   r   r   r   r   r   z.http://vimeo.com/moogaloop.swf?clip_id=2539741r!   only_matchingzhttps://vimeo.com/109815029z4Video not completely processed, "failed" seed status)r!   r   r  z1https://vimeo.com/groups/travelhd/videos/22439234z.https://vimeo.com/album/2632481/video/79010983z2https://vimeo.com/showcase/3253534/video/119195465z0A video in a password protected album (showcase)Z	119195465zPhilipp HagemeisterZuser20132939Z20150209ic*Tz)https://i.vimeocdn.com/video/default_1280zhttps://vimeo.com/user20132939)r   r   rf   r   r   r   r   r   r   r   r   r   r   r   )r!   r   r   r   r   zhttps://vimeo.com/7809605zDirect URL with hashz&https://vimeo.com/160743502/abd0e13fb4Z	160743502zJulian TrybaZaliniamediazHarrisville New HampshireiVZ20160329zby-nc   znhttps://i.vimeocdn.com/video/562802436-585eeb13b5020c6ac0f171a2234067938098f84737787df05ff0d767f6d54ee9-d_1280zhttps://vimeo.com/aliniamedia)r   r   r   r   rf   r   r   r   r   r   r   r   r   r   r   )r   r!   r   r   r   zhttps://vimeo.com/138909882Z	138909882z3Eastnor Castle 2015 Firework Champions - The Promo!z$md5:5967e090768a831488f6e74b7821b3c1ZfireworkchampionszFirework ChampionsZ20150910iGUznhttps://i.vimeocdn.com/video/534715882-6ff8e4660cbf2fea68282876d8d44f318825dfe572cc4016e73b3266eac8ae3a-d_1280z#https://vimeo.com/fireworkchampionszcount:6   )r   r   rf   r   r   r   r   r   r   r   r   r   r   r   r   z/https://vimeo.com/channels/staffpicks/143603739Z	143603739zKarim Huu Doi-VZ20151026z+The Shoes - Submarine Feat. Blaine HarrisonZkarimhdz$md5:8e2eea76de4504c2e8020a9bcfa1e843Z
staffpicksiP  znhttps://i.vimeocdn.com/video/541243181-b593db36a16db2f0096f655da3f5a4dc46b8766d77b0f440df937ecb0c418347-d_1280zhttps://vimeo.com/karimhdz%https://vimeo.com/channels/staffpicks)r   r   r   r   r   rf   r   r   r   r   r   r   r   r   r   r   r   m3u8z&https://vimeo.com/392479337/a52724358ez&https://vimeo.com/581039021/9603038895Z	581039021iai  zohttps://i.vimeocdn.com/video/1202249320-4ddb2c30398c0dc0ee059172d1bd5ea481ad12f0e0e3ad01d2266f56c744b015-d_1280zhttps://vimeo.com/txwestcapitalZ20210730zChristopher Inksz0Thursday, July 29, 2021 BMA Evening Video UpdateZtxwestcapital)r   r   r   r   r   r   r   r   r   r   r   rf   r   r   z(https://player.vimeo.com/video/756714419Z	756714419z8Dr Arielle Schwartz - Therapeutic yoga for optimum sleepzAlex HowardZuser54729178zhttps://vimeo.com/user54729178z<re:https://i\.vimeocdn\.com/video/1520099929-[\da-f]+-d_1280iL
  r   z<Untitled Chapter 1>)r   Zend_timerf   j   zWelcoming Dr Arielle Schwartzi1  zWhat is therapeutic yoga?iR  zVagal toning practicesix  z Trauma and difficulty letting goi#  z Dr Schwartz' insomnia experiencei  z#A strategy for helping sleep issuesi  z
Yoga nidraiI  zWisdom in stillnessiR	  z%What helps us be more able to let go?i	  z Practical tips to help ourselveszWhere to find out more)	r   r   rf   r   r   r   r   r   r   r&   z https://sleepsuperconference.com)r%   r   z&https://vimeo.com/144579403/ec02229140Z	144579403ZSALESMANSHIPz$md5:4338302f347a1ff8841b4a3aecaa09f0zOff the Picture PicturesZoffthepicturepicturesz'https://vimeo.com/offthepicturepicturesi  Z20151104iLy9Vz<re:https://i\.vimeocdn\.com/video/1018638656-[\da-f]+-d_1280)r   r   rf   r   r   r   r   r   r   r   r   r   r   r   r   r   z(https://player.vimeo.com/video/859028877Z	859028877z3Ariana Grande - Honeymoon Avenue (Live from London)z
Raja VirdiZ	rajavirdizhttps://vimeo.com/rajavirdii5  z<re:https://i\.vimeocdn\.com/video/1716727772-[\da-f]+-d_1280r   r   rf   r   r   r   r   r   z0https://vimeo.com/user26785108/newspiritualguidec                 #   s&   t  ||D ]}| ||V  qd S Nsuper_extract_embed_urlsr$   clsr!   r^   Z	embed_url	__class__r"   r#   r  I  s    zVimeoIE._extract_embed_urlsc                 C   s   t | ||d S r  )nextr  )r  r!   r^   r"   r"   r#   _extract_urlN  s    zVimeoIE._extract_urlc                 C   sr   |   }tdt| i}t|ddi}| jtj	|j
d d  d|d||d}|dkrntd	d
d|S )Nr2   r6   r5   )r   z/check-passwordVerifying the passwordr7   FWrong video passwordTr9   )rL   r   base64	b64encoderX   r   r;   urllibparseurlsplit_replacegeturlr   )r)   r!   rY   r+   r2   r*   checkedr"   r"   r#   _verify_player_video_passwordR  s&         z%VimeoIE._verify_player_video_passwordNc           
         s  |  d|d}dD ]}z| ||d |W q tk
r } zh|st|jtr|jjdkrdt|jj	 t
jhtjhddd	fkr| ||  |d
  W Y q W 5 d }~X Y qX q| |  d ||}| jd| |||d d}|r|d | fdd}|dd|d|dttdd d tdd tpVi }	dD ]$ tt|	 fdd| d < q\|S )Nr-   zDownloading viewer info)FTr     r2   Zinvalid_parameters.fieldr/   r   rM   )r   r   r   c                    s   t  | d S )N_time)r   rI   rx   )re   r"   r#   r{   z  r|   z+VimeoIE._extract_from_api.<locals>.<lambda>r   r   releasecreatedc                 S   s   | d d S )NstatsZplaysr"   rx   r"   r"   r#   r{     r|   )r   r   r   r   r   c                 S   s   | d d S )Nmetadataconnectionsr"   rx   r"   r"   r#   r{     r|   )commentlikec                    s   |  d  d S )Nstotalr"   rx   )kr"   r#   r{     r|   _count)r;   r   r   r?   r@   r   rA   r   responsereadbytesdecoderV   loadsr[   rL   r   r   r   updaterI   r   r   r   )
r)   rY   r   rC   retryrD   infosource_formatZget_timestampr$  r"   )r)  re   r#   _extract_from_apia  sn      
         "zVimeoIE._extract_from_apic           	   
   C   sD  | j d|dd d}|sd S | jd|dd}|sT| ||}| |  d|d|d	 }|d
 }| jd| |d| ddddid}t|dd dkr@| d}|stddd| d|d  z2| jd| d|dt||d ddd id! W nN tk
r> } z.t	|j
tr,|j
jd"kr,td#dd W 5 d }~X Y nX d S )$Nz%vimeo\.com/(?:album|showcase)/([^/]+)zalbum iddefaultr   Fr   %bootstrap_data\s*=\s*({.+?})</script>bootstrap datarC   r   https://api.vimeo.com/albums/r   rR   r   r   description,name,privacyr   c                 S   s   | d d S NZprivacyviewr"   rx   r"   r"   r#   r{     r|   z-VimeoIE._try_album_password.<locals>.<lambda>r2   rK   FThis album is protected by a password, use the --video-password optionTr9   r4   https://vimeo.com/showcase//authr  r/   rN   r   r   r7     rU   )r\   r;   r=   r]   r   r'   r   r<   r   r?   r@   r   rA   )	r)   r!   album_idrC   r^   r   albumr2   rD   r"   r"   r#   _try_album_password  sp           

   
zVimeoIE._try_album_passwordc           $         s  |  \}}d|kr |d< |  }|d |d }}|rR| ||S tfdddD rpd| |  tj	j
dk}z | j|||d	\}|j}	W n tk
r }
 zt|
jtr|
jjd
krڂ |
jj }d|krtddd|
jj}d}|
jjjd }r8td| d| d| n|sVtd| d| ddtd| jdd d| dddW 5 d }
~
X Y nX dkr| dd|  ddkr| |	|| |  |}| d| ||}|r|d | |S | j|d d }|rL|d!p i }|d"d#krLtd$| j|d% ddd }d }d }i }d }| jd&d'd d }|r| j d(d)d d }t!t"d*}|#|d+| d, |s*| j$| jd-d.d/d |d0d1}|s| |S |d2 d3 }|d4}|d5pi }|d6}t!|d*p&|d7}| %||  d8pDi }|d9pTi  fd:d;}| rd<rd=}|r|d>d0s| &t'd?| d>did@S |s| j dAd*d d }|s| j(d*dBdCgd d }|s| )dD |s| jdEdFd d }t*| jdGdHd d }t*| jdIdJd d }t*| jdKdLd d } g }!| d| ||d}|r~|!| |  |}"|!+|"d  |"dM |dM< | j,|i d }#|s| jdNdOd dOdP}|#|!t-||||| |dQ t.||"|#S )RNr&   r   r   c                 3   s   | ]}| kV  qd S r  r"   ).0p)r!   r"   r#   	<genexpr>  s     z(VimeoIE._real_extract.<locals>.<genexpr>)Zplay_redirect_hlszmoogaloop.swfrM   https)r+   rT   )r   i  sA   Because of its privacy settings, this video cannot be played herez{Cannot download embed-only video without embedding URL. Please call yt-dlp with the URL of the page that embeds this video.Tr9   zFIf you are using a data center IP or VPN/proxy, your IP may be blockedrT   zGot HTTP Error z  when using impersonate target "z". z. zThis request has been blocked due to its TLS fingerprint. Install a required impersonation dependency if possible, or else if you are okay with z"compromising your security/cookiesz	light redz8, try replacing "https:" with "http:" in the input URL. .z://player.vimeo.com/video/z\b(?:playerC|c)onfig\s*=zinfo sectionr<     r   r5  seed_statusstatefailedz{} said: {}rf   zvimeo\.com/channels/([^/]+)z
channel idz\bdata-config-url="([^"]+)"z
config URLr   zhttps://vimeo.com/channels/)r   r   z4vimeo\.(?:clip|vod_title)_page_config\s*=\s*({.+?});zpage configz{}Fr   Zplayerr   
cc_licenseclipZuploaded_onZdescription_html_escapedre   vodc                     sn   dkrdS t  dd rdS dp*g D ]<} | dr@ dS | d}|r,|dsb|d	r, dS q,d
S )Nz>You rented this title.<Tc                 S   s   | d d S )Nuser	purchasedr"   rx   r"   r"   r#   r{     r|   z:VimeoIE._real_extract.<locals>.is_rented.<locals>.<lambda>Zpurchase_optionsrQ  Zlabel_stringzYou rented thisz
 remainingF)r   rI   
startswithendswith)Zpurchase_optionlabel)r   rO  r^   r"   r#   	is_rented  s    

z(VimeoIE._real_extract.<locals>.is_rentedZ
is_trailer
feature_idZforce_feature_idz https://player.vimeo.com/player/r   z9(?s)<div\s+class="[^"]*description[^"]*"[^>]*>(.*?)</div>zog:descriptionztwitter:descriptionzCannot find video descriptionz<time[^>]+datetime="([^"]+)"r   zUserPlays:(\d+)z
view countzUserLikes:(\d+)z
like countzUserComments:(\d+)zcomment countr   zK<link[^>]+rel=["\']license["\'][^>]+href=(["\'])(?P<license>(?:(?!\1).)+)\1r   )r6  r   )r   r   r   Zwebpage_urlr   r   r   r   )/r,   _match_valid_url	groupdictrI   r4  anyrC  r  r  urlparseschemeZ_download_webpage_handler!   r   r?   r@   r   rA   r+  r,  
extensionsZ_downloaderZ_format_errZ_search_jsonr  r   r   r   rb   r   IE_NAMEr\   _html_search_regexr
   r   r0  r]   r;   
url_resultr   _html_search_metaZreport_warningr   r   Z_search_json_ldr   r   )$r)   r!   r*   r+   r   rY   r   Z	is_securer   Zredirect_urlrZ   errmsgrA   Zdcip_msgr   r2  r3  ra   rJ  rM  r   Zvideo_descriptionr   r   r   Zpage_configrN  re   rU  rV  r   r   r   r   Zinfo_dict_configZjson_ldr"   )r   r!   rO  r^   r#   _real_extract  sj   
   


                



   
    
   zVimeoIE._real_extract)N)r   r   r   __doc__
_VALID_URLr]  _EMBED_REGEXr   r   _TESTSclassmethodr  r  r  r4  rC  rb  __classcell__r"   r"   r  r#   r   <  sP  
  !

    









#      g'&r   c                   @   s   e Zd ZdZdZddddddd	d
ddddeddeedddidgddddddddddddeed ed!d"d#idgd$d%d#d&d'd#d&d(d#d&gZd)S )*VimeoOndemandIEzvimeo:ondemandzBhttps?://(?:www\.)?vimeo\.com/ondemand/(?:[^/]+/)?(?P<id>[^/?#&]+)z https://vimeo.com/ondemand/20704Z c424deda8c7f73c1dfb3edd7630e2f35Z	105442900r   u+   המעבדה - במאי יותם פלדמןu   גם סרטיםz)re:https?://(?:www\.)?vimeo\.com/gumfilmsZgumfilmsz$md5:aeeba3dbd4d04b0fa98a4fdc9c639998Z20140906iEcTznhttps://i.vimeocdn.com/video/488238335-d7bf151c364cff8d467f1b73784668fe60aae28a54573a35d53a1210ae283bd8-d_1280z2https://creativecommons.org/licenses/by-nc-nd/3.0/5   )r   r   rf   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z Unable to download JSON metadatar   z*https://vimeo.com/ondemand/36938/126682985Z	126584684u%   Rävlock, rätt läte på rätt platszLindroth & Norinz.re:https?://(?:www\.)?vimeo\.com/lindrothnorinZlindrothnorinz$md5:c3c46a90529612c8279fb6af803fc0dfZ20150502i6EUy   znhttps://i.vimeocdn.com/video/517077723-7066ae1d9a79d3eb361334fb5d58ec13c8f04b52f8dd5eadfbd6fb0bcf11f613-d_1280)r   r   rf   r   r   r   r   r   r   r   r   r   r   r   r   Tr   z$https://vimeo.com/ondemand/nazmaalikr  z$https://vimeo.com/ondemand/141692381z2https://vimeo.com/ondemand/thelastcolony/150274832N)r   r   r   r]  rd  r   rf  r"   r"   r"   r#   ri  V  sp     ri  c                   @   s`   e Zd ZdZdZdZdZdZdddd	d
dgZdZ	dd Z
dd Zdd Zdd Zdd ZdS )VimeoChannelIEzvimeo:channelz7https://vimeo\.com/channels/(?P<id>[^/?#]+)/?(?:$|[?#])z<a.+?rel="next"Nz(<link rel="alternate"[^>]+?title="(.*?)"z#https://vimeo.com/channels/tributesr   zVimeo Tributesr   rf      r!   r   playlist_mincountzhttps://vimeo.com/channels/%sc                 C   s   | d| dS )Nz/videos/page:r   r"   r)   base_urlpagenumr"   r"   r#   	_page_url  s    zVimeoChannelIE._page_urlc                 C   s   | j p| j| j|dddS )Nz
list titleFr   )_TITLEr^  	_TITLE_RE)r)   r^   r"   r"   r#   _extract_list_title  s    
   z"VimeoChannelIE._extract_list_titlec           
      c   s   t dD ]}| ||}| ||d| }|dkrB| |V  td|}|r|D ],\}}}	| jtj	
||t ||	dV  qVn.td|D ] }| jd| t |dV  qt| j|tjd kr
 qq
d S )Nr   Downloading page zPid="clip_(\d+)"[^>]*>\s*<a[^>]+href="(/(?:[^/]+/)*\1)(?:[^>]+\btitle="([^"]+)")?)rY   r   zid=["\']clip_(\d+)rM   )rY   )	itertoolscountrt  r=   rw  r   findallr_  r  r  r   r   ie_keyr   _MORE_PAGES_INDICATORDOTALL)
r)   list_idrr  rs  page_urlr^   ZclipsrY   r   r   r"   r"   r#   _title_and_entries  s:         
z!VimeoChannelIE._title_and_entriesc                 C   s"   |  ||}t|}| |||S r  )r  r  playlist_result)r)   r  rr  Ztitle_and_entriesZ
list_titler"   r"   r#   _extract_videos  s    zVimeoChannelIE._extract_videosc                 C   s   |  |}| || j| S r  )	_match_idr  _BASE_URL_TEMPL)r)   r!   r   r"   r"   r#   rb    s    
zVimeoChannelIE._real_extract)r   r   r   r]  rd  r}  ru  rv  rf  r  rt  rw  r  r  rb  r"   r"   r"   r#   rl    s"   rl  c                   @   s8   e Zd ZdZdZdZdddddd	d
ddgZdZdS )VimeoUserIEz
vimeo:userz\https://vimeo\.com/(?!(?:[0-9]+|watchlater)(?:$|[?#/]))(?P<id>[^/]+)(?:/videos)?/?(?:$|[?#])z"<a[^>]+?class="user">([^<>]+?)</a>z"https://vimeo.com/nkistudio/videosZNkiZ	nkistudiorf   r   B   ro  zhttps://vimeo.com/nkistudio/Tr  zhttps://vimeo.com/%sN)r   r   r   r]  rd  rv  rf  r  r"   r"   r"   r#   r    s   r  c                   @   sX   e Zd ZdZdZdZdddddd	d
dddddddidgZdZdd Zdd Z	dS )VimeoAlbumIEzvimeo:albumzFhttps://vimeo\.com/(?:album|showcase)/(?P<id>\d+)(?:$|[?#]|/(?!video))z,<header id="page_header">\n\s*<h1>(.*?)</h1>zhttps://vimeo.com/album/2632481Z2632481zStaff Favorites: November 2013rm     ro  zPassword-protected albumzhttps://vimeo.com/album/3253534testZ3253534r  r   rK   r   )r   r!   r   Zplaylist_countr   d   c              
   c   s   |d }d|| j d}|r"||d< z4| jd| d|d| |d| d	d
dd }W nF tk
r } z(t|jtr|jjdkrW Y 
d S  W 5 d }~X Y nX |D ]L}	|	d}
|
sq|	d}|r| jd|dd dnd }| 	|
t
 |V  qd S )Nr   zlink,uri)r   pageZper_pageZ_hashed_passr9  z/videosrx  r   rR   r   )r   r+   r*   r  r   uriz/videos/(\d+)rY   r5  )
_PAGE_SIZEr;   r   r?   r@   r   rA   rI   r\   r_  r   r|  )r)   rA  authorizationhashed_passr  Zapi_pager   ZvideosrD   re   r   r  rY   r"   r"   r#   _fetch_page  s<    
  


zVimeoAlbumIE._fetch_pagec              
   C   sn  |  |}| jd|dd}|sD| ||}| | d|d|d }|d }| jd| |d	| d
dddid}d }t|dd dkr8| d}|stddd| d|d  z6| jd| d|dt	||d dddidd }W nN tk
r6 }	 z.t
|	jtr$|	jjd kr$td!dd W 5 d }	~	X Y nX tt| j|||| j}
| |
||d"|d#S )$Nr   Fr   r7  r8  rC   r   r9  r   rR   r   r   r:  r   c                 S   s   | d d S r;  r"   rx   r"   r"   r#   r{   )  r|   z,VimeoAlbumIE._real_extract.<locals>.<lambda>r2   rK   r=  Tr9   r4   r>  r?  r  r/   rN   r   r   r7   r  r@  rU   rc   r   )r  r;   r=   r]   r\   r   r'   r   r<   r   r?   r@   r   rA   r	   	functoolspartialr  r  r  rI   )r)   r!   rA  rC   r^   r   rB  r  r2   rD   entriesr"   r"   r#   rb    s    
    

         zVimeoAlbumIE._real_extractN)
r   r   r   r]  rd  rv  rf  r  r  rb  r"   r"   r"   r#   r    s.    r  c                   @   s,   e Zd ZdZdZddddddgZd	Zd
S )VimeoGroupsIEzvimeo:groupz=https://vimeo\.com/groups/(?P<id>[^/]+)(?:/(?!videos?/\d+)|$)zhttps://vimeo.com/groups/meetupZmeetupzVimeo Meetup!rm     ro  zhttps://vimeo.com/groups/%sN)r   r   r   r]  rd  rf  r  r"   r"   r"   r#   r  C  s   r  c                   @   s   e Zd ZdZdZdZdddddd	d
dddddidg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/d0d1d2d3id)d4gZd5d6 Zd7S )8VimeoReviewIEzvimeo:reviewzReview pages on vimeozNhttps?://vimeo\.com/(?P<user>[^/?#]+)/review/(?P<id>\d+)/(?P<hash>[\da-f]{10})z;https://vimeo.com/user170863801/review/996447483/a316d6ed8dZ	996447483r   zRodeo day 1-_2Z	BROADKASTZuser170863801zhttps://vimeo.com/user170863801   zohttps://i.vimeocdn.com/video/1912612821-09a43bd2e75c203d503aed89de7534f28fc4474a48f59c51999716931a246af5-d_1280r  r   r  zFailed to parse XMLr   z9https://vimeo.com/user21297594/review/75524534/3c257a1b5dZ c507a72f780cacc12b2248bb4006d253Z75524534zDICK HARDWICK 'Comedian'zRichard HardwickZuser21297594zkComedian Dick Hardwick's five minute demo filmed in front of a live theater audience.
Edit by Doug Mattocksi0  znhttps://i.vimeocdn.com/video/450115033-43303819d9ebe24c2630352e18b7056d25197d09b3ae901abdac4c4f1d68de71-d_1280zhttps://vimeo.com/user21297594)	r   r   rf   r   r   r   r   r   r   z404 Not Found)r!   r   r   r   zvideo player needs Refererz9https://vimeo.com/user22258446/review/91613211/13f927e053Z 6295fdab8f4bf6a002d058b2c6dce276Z91613211zCre:(?i)^Death by dogma versus assembling agile . Sander HoogendoornzDevWeek Eventsi
  zre:^https?://.*\.jpg$Zuser22258446)r   r   rf   r   r   r   r   z
video gone)r   r!   r   r   r   zPassword protectedz:https://vimeo.com/user37284429/review/138823582/c4d865efdeZ	138823582z%EFFICIENT PICKUP MASTERCLASS MODULE 1ZTMBZuser37284429)r   r   rf   r   r   rK   Z	holygrail)r   r!   r   r   r   c                 C   s  |  |ddd\}}}d| d| d| }| ||}i }|ddkr|  }| d	|}| |||d
  | ||}|d }	|	d }
| |
|}| ||}| jd| d| d| d||	d|dd}|r|d | t	|	d|d< |S )NrP  r   hashrM   z/review/data/r   ZisLockedTr   r/   ZclipDataZ	configUrlz/review/z/actionZunlistedHashr   )r   r   r   r   )
rW  r   r;   rI   rL   r[   r   r   r   r
   )r)   r!   rP  rY   Zreview_hashZdata_urlr*   rC   Zvideo_passwordZ	clip_datar   r   r   r3  r"   r"   r#   rb    s4       zVimeoReviewIE._real_extractN)r   r   r   r]  IE_DESCrd  rf  rb  r"   r"   r"   r#   r  Q  st   
	 ;r  c                   @   s<   e Zd ZdZdZdZdZdZdddgZdd	 Z	d
d Z
dS )VimeoWatchLaterIEzvimeo:watchlaterzLVimeo watch later list, ":vimeowatchlater" keyword (requires authentication)z8https://vimeo\.com/(?:home/)?watchlater|:vimeowatchlaterzWatch LaterThttps://vimeo.com/watchlaterr  c                 C   s&   | d| d}t |}d|jd< |S )N/page:r   r   r   )r   r+   )r)   rr  rs  r!   rl   r"   r"   r#   rt    s    
zVimeoWatchLaterIE._page_urlc                 C   s   |  ddS )NZ
watchlaterr  )r  )r)   r!   r"   r"   r#   rb    s    zVimeoWatchLaterIE._real_extractN)r   r   r   r]  r  rd  ru  rG   rf  rt  rb  r"   r"   r"   r#   r    s   r  c                   @   sD   e Zd ZdZdZdZdddddd	d
ddgZdd Zdd ZdS )VimeoLikesIEzBhttps://(?:www\.)?vimeo\.com/(?P<id>[^/]+)/likes/?(?:$|[?#]|sort:)zvimeo:likeszVimeo user likesz#https://vimeo.com/user755559/likes/i%  Z
user755559u   urza’s Likesrm  )r!   rp  r   z"https://vimeo.com/stormlapse/likesTr  c                 C   s   | d| dS )Nr  r   r"   rq  r"   r"   r#   rt    s    zVimeoLikesIE._page_urlc                 C   s   |  |}| |d| dS )NrM   z/likes)r  r  )r)   r!   Zuser_idr"   r"   r#   rb    s    
zVimeoLikesIE._real_extractN)	r   r   r   rd  r]  r  rf  rt  rb  r"   r"   r"   r#   r    s   r  c                       s6   e Zd ZdZdZdgZe fddZdd Z  Z	S )
VHXEmbedIEz	vhx:embedz*https?://embed\.vhx\.tv/videos/(?P<id>\d+)zB<iframe[^>]+src="(?P<url>https?://embed\.vhx\.tv/videos/\d+[^"]*)"c                 #   s&   t  ||D ]}| ||V  qd S r  r	  r  r  r"   r#   r    s    zVHXEmbedIE._extract_embed_urlsc           	      C   sj   |  |}| |\}}}| j|||d}| | d|d|td }| ||}| ||}||d< |S )N)r+   zwindow\.OTTData\s*=\s*({.+})zott datar   r   )r  r,   r=   r]   r\   r   r;   r   )	r)   r!   rY   r   r+   r^   r   r   r2  r"   r"   r#   rb    s"    
  zVHXEmbedIE._real_extract)
r   r   r   r]  rd  re  rg  r  rb  rh  r"   r"   r  r#   r    s   r  c                   @   sz   e Zd ZdZdZddddddd	d
dddddddeeeddddidddddddddddd d!
d"d#d$d%gZd&d' Zd(S ))
VimeoProIEz	vimeo:prozZhttps?://(?:www\.)?vimeopro\.com/[^/?#]+/(?P<slug>[^/?#]+)(?:(?:/videos?/(?P<id>[0-9]+)))?zKhttp://vimeopro.com/openstreetmapus/state-of-the-map-us-2013/video/68093876Z 3b5ca6aa22b60dfeeadf50b72e44ed82zVimeo Pro video (#1197)Z68093876r   z0re:https?://(?:www\.)?vimeo\.com/openstreetmapusZopenstreetmapuszOpenStreetMap USz=Andy Allan - Putting the Carto into OpenStreetMap Cartographyz$md5:2c362968038d4499f4d79f88458590c1i;  Z20130610id+QZbyzmhttps://i.vimeocdn.com/video/440260469-19b0d92fca3bd84066623b53f1eb8aaa3980c6c809e2d67b6b39ab7b4a77a344-d_960zcount:1)r   r   r   r   r   rf   r   r   r   r   r   r   r   r   r   r   r   r   )r!   r   r   r   r   zShttps://vimeopro.com/cadfem/simulation-conference-mechanische-systeme-in-perfektionZ	764543723uI   Mechanische Systeme in Perfektion: Realität erfassen, Innovation treibenzohttps://i.vimeocdn.com/video/1543784598-a1a750494a485e601110136b9fe11e28c2131942452b3a5d30391cb3800ca8fd-d_1280z$md5:2a9d195cd1b0f6f79827107dc88c2420ZCADFEMZcadfemzhttps://vimeo.com/cadfemi0  zcount:10)
r   r   rf   r   r   r   r   r   r   r   ZConference2022T)rK   r   )r!   r   r   c           	   
   C   s  |  |dd\}}|r|}| ||}| jd|dd d}|rz,| j||td|  i| |dd}W nH tk
r } z*t|j	t
r|j	jd	krtd
dd W 5 d }~X Y nX d }t||}|r| jd|d d}n|rd| }ntddd| j|t|d|dS )NZslugr   zB(?is)<form[^>]+?method=["\']post["\'][^>]*>(.+?password.+?)</form>zpassword formr5  r2   zLogging in with video password)r*   r   r8   r  Tr9   r   rM   z:No Vimeo embed or video ID could be found in VimeoPro page)Zurl_transparentr   )rW  r   r=   r\   r   rL   Z_hidden_inputsr   r?   r@   r   rA   r   r  r`  r_  )	r)   r!   Z
display_idrY   r^   Zpassword_formrD   r   Z	vimeo_urlr"   r"   r#   rb     sJ      
 
 zVimeoProIE._real_extractN)r   r   r   r]  rd  r   rf  rb  r"   r"   r"   r#   r    sX    /r  )1r  r  ry  rV   r   urllib.parser  commonr   Z
networkingr   r   Znetworking.exceptionsr   utilsr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ri  rl  r  r  r  r  r  r  r  r  r"   r"   r"   r#   <module>   s:   `         ?>^W