U
    gE                    @   s  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 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 e	Z$G dd de Z%G dd de Z&dS )    N   )InfoExtractor)PeriscopeBaseIEPeriscopeIE   )	HTTPError)ExtractorErrordict_getfilter_dictfloat_or_noneformat_fieldint_or_nonejoin_nonemptymake_archive_id
remove_endstr_or_nonestrip_or_nonetraverse_objtry_calltry_getunified_timestampupdate_url_queryurl_or_none
xpath_textc                ,   @   s&  e Zd ZdZdZdZdZdZdZdZ	e
jdi d	d
i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ddddd)ddd Zdd Zdd Zedd Zedd Zdd  Zejd!d" Zd#d$ Zd2d&d'Zi dfd(d)Zd*d+ Zi d%fd,d-Zd.d/ Zd0d1 ZdS )3TwitterBaseIEtwitterzhttps://api.x.com/1.1/zhttps://x.com/i/api/graphql/zzhttps?://(?:(?:www|m(?:obile)?)\.)?(?:(?:twitter|x)\.com|twitter3e4tixl4xyajtrzo62zg5vztmjuricljdp2c5kshju4avyoid\.onion)/zhAAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnAzpAAAAAAAAAAAAAAAAAAAAAIK1zgAAAAAA2tUWuhGZ2JceoId5GwYWU5GspY4%3DUq7gzFoCZs1QfwGoVdvSac3IniczZEYXIcDyumCauIXpcAPorENZflow_contextlocationunknown)Zdebug_overridesZstart_locationr   r      r            ))Zaction_listZalert_dialogZapp_download_ctacheck_logged_in_accountZchoice_selectionZ$contacts_live_sync_permission_promptZctaZemail_verificationZend_flowZ
enter_dateZenter_emailenter_passwordZenter_phoneZenter_recaptcha
enter_textZenter_usernameZgeneric_urtZin_app_notificationZinterest_pickerjs_instrumentationZmenu_dialogZnotifications_permission_promptZopen_accountZopen_home_timelineZ	open_linkZphone_verificationZprivacy_optionsZsecurity_keyZselect_avatarZselect_bannersettings_list	show_codeZsign_upZsign_up_reviewZtweet_selection_urtZupdate_usersZupload_mediaZuser_recommendations_listZuser_recommendations_urtZwait_spinnerZ	web_modal)Zinput_flow_dataZsubtask_versions,:
separatorsc           	      C   s   | d}|sg i fS d|kr|| j||ddddd\}}t|dd	 D ],}td
|d  }rFt|dd|d< qF||fS tt|ddpd }|td||d}| 	|| |gi fS d S )Nurlz.m3u8mp4m3u8_nativeZhlsF)m3u8_idfatalc                 S   s   |d dko| dd kS )Nvcodecnonetbrget_v r:   </tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/twitter.py<lambda>g       z8TwitterBaseIE._extract_variant_formats.<locals>.<lambda>z hls-[Aa]udio-(?P<bitrate>\d{4,})	format_idbitrate  r4   )r?   Zbit_ratehttp)r-   r>   r4   )
r6   Z#_extract_m3u8_formats_and_subtitlesr   rematchr   groupr	   r   _search_dimensions_in_video_url)	selfvariantvideo_idZvariant_urlfmtssubsfmobjr4   r:   r:   r;   _extract_variant_formats_   s.    
    
z&TwitterBaseIE._extract_variant_formatsc                 C   s   t |}|sg i fS | ||}g }i }g }|dD ]T}tj|jd |jd< ||jd  | |j|\}}	|	| | 
||	}q6tt|d}
|
|kr| d|
i|\}}	|	| | 
||	}||fS )Nz:.//{http://twitter.com/schema/videoVMapV2.xsd}videoVariantr-   z.//MediaFile)r   Z_download_xmlfindallurllibparseunquoteattribappendrM   extend_merge_subtitlesr   r   )rF   vmap_urlrH   Z	vmap_dataformats	subtitlesurlsZvideo_variantrI   rJ   	video_urlr:   r:   r;   _extract_formats_from_vmap_urlu   s0    
 

z,TwitterBaseIE._extract_formats_from_vmap_urlc                 C   s8   t d|}|r4| t|dt|dd d S )Nz /(?P<width>\d+)x(?P<height>\d+)/widthheightr\   r]   )rB   searchupdateintrD   )Za_formatrZ   mr:   r:   r;   rE      s    z-TwitterBaseIE._search_dimensions_in_video_urlc                 C   s   t | | jdS )N
auth_token)bool_get_cookies	_API_BASEr6   rF   r:   r:   r;   is_logged_in   s    zTwitterBaseIE.is_logged_inc                 C   s*   | j s| ddsd S dt_dt_d S )Nhttps://twitter.com/rc   zhttps://api.twitter.com/1.1/z"https://twitter.com/i/api/graphql/)rh   re   r6   r   rf   _GRAPHQL_API_BASErg   r:   r:   r;   _real_initialize   s    zTwitterBaseIE._real_initializec                 C   s   | j ddgddd S )NapigraphqlTwitter)ie_keyr   )Z_configuration_argrg   r:   r:   r;   _selected_api   s    zTwitterBaseIE._selected_apic              	   C   sJ   t | j| j d|dd| j|o&| jdkdddthf}|sFtd|S )	Nzguest/activate.jsonzDownloading guest tokenr=   legacyrq   )dataheadersguest_tokenzCould not retrieve guest token)r   _download_jsonrf   _set_base_headersrp   strr   )rF   
display_idru   r:   r:   r;   _fetch_guest_token   s    
   z TwitterBaseIE._fetch_guest_tokenFc                    s6   |r j s jn j}td| t fdddS )NzBearer c                      s      jd jS )NZct0)re   rf   valuer:   rg   r:   r;   r<      r=   z1TwitterBaseIE._set_base_headers.<locals>.<lambda>)Authorizationzx-csrf-token)rh   _LEGACY_AUTH_AUTHr
   r   )rF   rq   Zbearer_tokenr:   rg   r;   rw      s
    zTwitterBaseIE._set_base_headersc              	   C   s   | j | j dd ||||dd}t|dddthf}|rLtd| dd	nt|d
dkrbtdt|dddthfdd}|std|d | _|S )Nzonboarding/task.json  )rt   queryrs   expected_statuserrorsr   messagez Login failed, Twitter API says: TexpectedstatussuccesszLogin was unsuccessfulZsubtasks.
subtask_idFget_allz-Twitter API did not return next login subtask
flow_token)rv   rf   r   rx   r   _flow_token)rF   notert   r   rs   responseerrorZsubtaskr:   r:   r;   _call_login_api   s.    
       
zTwitterBaseIE._call_login_apic              	      s   j r
d S  d }  d|ddddd} fdd}d	d
 } jd|ddi jd} j s|dkr jd|||ddddd}qZ|dkrƈ jd|||ddd|iidgdddd}qZ|dkr jd|||| d d}qZ|d!kr jd"||||dd#d$d}qZ|d%krF jd&|||d'd(id)d}qZ|d*krr jd+|||| d,d}qZ|d-kr jd.|||| d/d}qZ|d0kr jd1d2d3 qZ|d4kr҈ jd5d2d3 qZ|d6krtd7qZtd8| d9qZ   d S ):Nzapplication/jsonenyeszhttps://x.com/zhttps://x.com)zcontent-typex-guest-tokenx-twitter-client-languagex-twitter-active-userRefererZOriginc                     s   t j j| ddd S )N)r   subtask_inputsr(   r+   )jsondumpsr   encode)r   rg   r:   r;   build_login_json   s    z6TwitterBaseIE._perform_login.<locals>.build_login_jsonc                 S   s   | |dddS )N	next_link)textlink)r   r$   r:   )r   r   r:   r:   r;   
input_dict   s
    z0TwitterBaseIE._perform_login.<locals>.input_dictzDownloading flow tokenZ	flow_namelogin)r   rs   ZLoginJsInstrumentationSubtaskz&Submitting JS instrumentation responsez{}r   )r   r   )r   r%   )rs   ZLoginEnterUserIdentifierSSOzSubmitting usernameZuser_identifierZ	text_dataresult)keyZresponse_data)Zsetting_responsesr   )r   r&   Z$LoginEnterAlternateIdentifierSubtaskzSubmitting alternate identifierzFone of username, phone number or email that was not used as --usernameZLoginEnterPasswordzSubmitting password)passwordr   )r   r#   ZAccountDuplicationCheckz$Submitting account duplication checkr   ZAccountDuplicationCheck_false)r   r"   ZLoginTwoFactorAuthChallengezSubmitting 2FA tokenztwo-factor authentication tokenZ	LoginAcidzSubmitting confirmation codez-confirmation code sent to your email or phoneZArkoseLoginz3Twitter is requiring captcha for this login attemptcookies)methodZDenyLoginSubtaskz1Twitter rejected this login attempt as suspiciousZLoginSuccessSubtaskz+Twitter API did not grant auth token cookiezUnrecognized subtask ID "")	rh   rz   rw   r   _LOGIN_INIT_DATAZ_get_tfa_inforaise_login_requiredr   Zreport_login)rF   usernamer   ru   rt   r   r   Znext_subtaskr:   rg   r;   _perform_login   s    

	     	    

  	
   
   
   



zTwitterBaseIE._perform_loginc           	   	   C   s   | j | o| jdkd}|| jr.ddddnd| |i |rNdd	d
dhnd
h}| j|rb| jn| j| ||||d|r|dnd dd}|drd	t
t|dddthf}|rd|kr| t|d td|pd |S )Nrq   rr   ZOAuth2Sessionr   r   )zx-twitter-auth-typer   r   r   r   i  i  i  zDownloading ZGraphQLz
legacy APIz JSON)rt   r   r   r   r   , .r   znot authorized.zError(s) while querying API: Unknown error)rw   rp   r`   rh   rz   rv   rj   rf   r6   joinsetr   rx   r   r   r   )	rF   pathrH   r   rm   rt   Zallowed_statusr   r   r:   r:   r;   	_call_api6  s6        
zTwitterBaseIE._call_apic                 C   s   t dd S )Nz-Method must be implemented to support GraphQL)NotImplementedErrorrF   media_idr:   r:   r;   _build_graphql_queryM  s    z"TwitterBaseIE._build_graphql_queryc                 C   s4   |  |}dd | D }t| j|||dddS )Nc                 S   s    i | ]\}}|t j|d dqS )r(   r+   )r   r   ).0r   r{   r:   r:   r;   
<dictcomp>R  s      z3TwitterBaseIE._call_graphql_api.<locals>.<dictcomp>T)r   rm   rs   )r   itemsr   r   )rF   Zendpointr   rs   r   r:   r:   r;   _call_graphql_apiP  s    
zTwitterBaseIE._call_graphql_api)F)__name__
__module____qualname__Z_NETRC_MACHINErf   rj   _BASE_REGEXr~   r}   r   r   r   r   r   rM   r[   staticmethodrE   propertyrh   rk   	functoolscached_propertyrp   rz   rw   r   r   r   r   r   r:   r:   r:   r;   r       s    	4
6


	
nr   c                   @   s  e Zd ZdZejd Zdddddddd	d
dddeg eeddddddddddddddddeeedgdddidd d!d"dd#d$d%d&d'd(d)ed*d+d,d-gded.ed/ed0d&d1d2d3gd4d5d6dd7d8d9d:d;d:eed<eed=d>gd?d@idAdBdCdDddEdFdGdHdIdJdKdLdMdNd1dOgZdPdQ Z	dRS )STwitterCardIEztwitter:cardz0i/(?:cards/tfw/v1|videos(?:/tweet)?)/(?P<id>\d+)z5https://twitter.com/i/cards/tfw/v1/560070183650213889Z560070131976392705r.   zwTwitter - You can now shoot, edit and share video on Twitter. Capture life's most moving moments from your perspective.z$md5:18d3e24bb4f6e5007487dd546e53bd96rn   re:^https?://.*\.jpgg r>@iTZ20150127r   Z560070183650213889zhttps://twitter.com/Twitter)idexttitledescriptionuploaderuploader_id	thumbnailduration	timestampupload_date	age_limitcomment_counttagsrepost_count
like_country   uploader_urlr-   	info_dictz5https://twitter.com/i/cards/tfw/v1/623160978427936768Z 7137eca597f72b9abbe61e5ae0161399Z623160978427936768zjNASA - Fly over Pluto's icy Norgay Mountains and Sputnik Plain in this @NASANewHorizons #PlutoFlyby video.z{Fly over Pluto's icy Norgay Mountains and Sputnik Plain in this @NASANewHorizons #PlutoFlyby video. https://t.co/BJYgOjSeGAZNASAiUZ20150720zhttps://twitter.com/NASAZ
PlutoFlyby)r   r   r   r   r   r   r   r   r   r   r   r   r   r   format[protocol=https]r-   md5r   paramsz5https://twitter.com/i/cards/tfw/v1/654001591733886977Z b6d9683dd3f48e340ded81c0e917ad46Zdq4Oj5quskIzUbuntu 11.10 Overviewz$md5:a831e97fa384863d6e26ce48d1c43376Z20111013zOMG! UBUNTU!Z	omgubuntuz8https://www.youtube.com/channel/UCIiSwcm9xiFb3Y4wjzR41eQZUCIiSwcm9xiFb3Y4wjzR41eQzcount:8z%http://www.youtube.com/user/omgubuntu   zFilm & Animationpublicz4https://i.ytimg.com/vi/dq4Oj5quskI/maxresdefault.jpgzcount:12T)r   r   r   r   r   r   r   Zchannel_url
channel_idZchannel_follower_countZchaptersr   r   
categoriesr   r   Zavailabilityr   r   
view_countr   ZchannelZplayable_in_embedZYoutuber-   r   r   add_iez5https://twitter.com/i/cards/tfw/v1/665289828897005568ZiBb2x00UVlv20151113Z1189339351084113920ZArsenalTerjezVine by ArsenalTerjeiZFVzre:^https?://[^?#]+\.jpg)r   r   r   r   r   r   r   	alt_titler   r   r   r   r   Vineskip_downloadm3u8r-   r   r   r   z5https://twitter.com/i/videos/tweet/705235433198714880Z 884812a2adc8aaf6fe52b15ccbfa3b88705235433198714880aBrent Yarina - Khalil Iverson's missed highlight dunk. And made highlight dunk. In one highlight.jKhalil Iverson's missed highlight dunk. And made highlight dunk. In one highlight. https://t.co/OrxcJ28BnsBrent YarinaBTNBrentYarinaLV20160303)r   r   r   r   r   r   r   r   z$This content is no longer available.)r-   r   r   skipz/https://twitter.com/i/videos/752274308186120192r-   Zonly_matchingc                 C   s    |  |}| d| t |S )Nzhttps://twitter.com/statuses/)	_match_id
url_result	TwitterIEro   )rF   r-   Z	status_idr:   r:   r;   _real_extract  s    
 zTwitterCardIE._real_extractN
r   r   r   IE_NAMEr   r   
_VALID_URLra   _TESTSr   r:   r:   r:   r;   r   V  s   

tr   c                7   @   s	  e Zd ZdZejd Zddddddd	d
ddddddeeeg ddgdddddddddddd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d0d1gd2d3d4d5dd6d7d8d9d:d;d<eeeg d0d=d>d?id@dAdBdCdDddEdFddGdHdIdJdKdLdMeeedNgd0dOgdPd3dQdRdSddTdUdVdWdXddYeeeedZd[gd\d]d^d_dd`dadbdcdddedfdgdhdeeeg d0digdjd3dkdlddmdndodpdqddrdsgdtdudvdwddxdydzd{d|d}d~ddd0ddg eeedgdd3ddddddddddddddeeedgd0dgdd>d?idddddddddddddddeeeg d0dgdd>d?iddddddddddddddeeeeg d0dddddddddddgeddgdduddddddddddddddeeeg d0dgdd>d?idddddddddddddddeeeg d0dgdϜd>d?idddddddddddeeeg d0dڜdd>d?idܜddddddddddddddeeedgd0dgdd3ddddeededddddeeedg dgdd>diddAdddeg deedd0eddedd dddddeddeeeddd	g ed
d0dddddeddeddd
d0deeedgddddddddddddd d d!d"gd>d#id$d%dd&d'd(d)ed*d+ed,d-d.gd/d0d0d1ed2dd3d4dd5dd(d+d*d0eed,d-d.gd6d1d&ed)d/d0d7gd8d9d?idd:d;d<dd=d>d?d@dAdBdCdDdEdFdg eeedGgdHdddIdJdKddLdMdNedOdPedQedRd0dSg dTdUdVgdWd9d?iddXdYdZdd[d\d]d^d0d_ed`daeeg dbdcdddegdfd3dgdhdiddjdkdldmdnd0g dodpdqdreedsdtddudvddwdxdydzd{d|d}d0g d~dddeeedgdd3dudvddwdxdydzd{d|d}d0g d~dddeedgdddddgiiiddddddddddddeeddgddddddg dddddddeeedddddddddddddddddddgeeed0dgddddddddddddddddg eeedd0dgdddd?ddd?ddd?ddd?ddd?ddd?ddd?ddd?ddd?dg+Z	e
dȡZedɐdʄ Zdːd̄ Zd͐d΄ ZdϐdЄ Zdѐd҄ ZdӐdԄ ZdS (  r   r   zS(?:(?:i/web|[^/]+)/status|statuses)/(?P<id>\d+)(?:/(?:video|photo)/(?P<index>\d+))?z;https://twitter.com/freethenipple/status/643211948184596480Z643211870443208704Z643211948184596480r.   z9FREE THE NIPPLE - FTN supporters on Hollywood Blvd today!r   z>FTN supporters on Hollywood Blvd today! http://t.co/c7jHH749xJZ	549749560zFREE THE NIPPLEZfreethenipplegMb)@imUZ20150913z!https://twitter.com/freethenipple   ztwitter 643211948184596480)r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _old_archive_idszRequires authenticationr-   r   r   z;https://twitter.com/giphz/status/657991469417025536/photo/1Z f36dcd5fb92bf7057f155e7d927eeb42Z657991469417025536z=Gifs - tu vai cai tu vai cai tu nao eh capaz disso tu vai caizaGifs on Twitter: "tu vai cai tu vai cai tu nao eh capaz disso tu vai cai https://t.co/tM46VHFlO5"zre:^https?://.*\.pngZGifsZgiphz)r   r   r   r   r   r   r   r]   r\   zAccount suspended)r-   r   r   Zexpected_warningsr   z6https://twitter.com/starwars/status/665052190608723968Z665052190608723968z5re:Star Wars.*A new beginning is coming December 18.*zA new beginning is coming December 18. Watch the official 60 second #TV spot for #StarWars: #TheForceAwakens. https://t.co/OkSqT2fjWJZ20106852Zstarwarszre:Star Wars.*iEVr   zhttps://twitter.com/starwarsZTVZStarWarsZTheForceAwakensr   ztwitter 665052190608723968)r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z<https://twitter.com/BTNBrentYarina/status/705235433198714880r   r   r   r   r   r   r   z"https://twitter.com/BTNBrentYarina)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   TzDead external link)r-   r   r   r   z8https://twitter.com/jaydingeer/status/700207533655363584Z700207414000242688Z700207533655363584z4jaydin donte geer - BEAT PROD: @suhmeduh #DamndanielzQBEAT PROD: @suhmeduh  https://t.co/HBrQ4AfpvZ #Damndaniel https://t.co/byBooq2ejZZ
1383165541zjaydin donte geerZ
jaydingeerg      >@ifVZ20160218zhttps://twitter.com/jaydingeerZ
Damndanielztwitter 700207533655363584)r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z7https://twitter.com/Filmdrunk/status/713801302971588609Z 89a15ed345d13b86e9a5a5e051fa308aZMIOxnrUteUdu@   Dr.Pepperの飲み方 #japanese #バカ #ドクペ #電動ガンZTAKUMAZ1004126642786242560ioSZ20140615zVine by TAKUMA)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z<https://twitter.com/captainamerica/status/719944021058060289Z717462543795523584Z719944021058060289z[Captain America - @King0fNerd Are you sure you made the right choice? Find out in theaters.za@King0fNerd Are you sure you made the right choice? Find out in theaters. https://t.co/GpgYi9xMJIZ	701615052ZCaptainAmericazCaptain Americag\(\	@i3WZ20160412z"https://twitter.com/CaptainAmericaztwitter 719944021058060289)r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z5https://twitter.com/OPP_HSD/status/779210622571536384Z1zqKVVlkqLaKBzqSgt Kerry Schmidt - Ontario Provincial Police - Road rage, mischief, assault, rollover and fire in one occurrenceZ20160923Z1PmKqpJdOJQoYz-Sgt Kerry Schmidt - Ontario Provincial PoliceiW)r   r   r   r   r   r   r   r   Z	PeriscopezBroadcast not found)r-   r   r   r   z9https://twitter.com/news_al3alm/status/852138619213144067Z852077943283097602u   عالم الأخبار - كلمة تاريخية بجلسة الجناسي التاريخية.. النائب خالد مؤنس العتيبي للمعارضين : اتقوا الله .. الظلم ظلمات يوم القيامةu   كلمة تاريخية بجلسة الجناسي التاريخية.. النائب خالد مؤنس العتيبي للمعارضين : اتقوا الله .. الظلم ظلمات يوم القيامة   https://t.co/xg6OhpyKfNZ
2526757026u   عالم الأخبارZnews_al3almgfffffVq@iXZ20170412Z852138619213144067zhttps://twitter.com/news_al3almztwitter 852138619213144067)r   r   r   r   r   r   r   r   r   r   ry   r   r   r   r   r   r   r   r   z3https://twitter.com/i/web/status/910031516746514432Z910030238373089285Z910031516746514432u   Préfet de Guadeloupe - [Direct] #Maria Le centre se trouve actuellement au sud de Basse-Terre. Restez confinés. Réfugiez-vous dans la pièce la + sûre.u   [Direct] #Maria Le centre se trouve actuellement au sud de Basse-Terre. Restez confinés. Réfugiez-vous dans la pièce la + sûre. https://t.co/mwx01Rs4loZ
2319432498u   Préfet de GuadeloupeZ	Prefet971g=
ףpG@iYZ20170919zhttps://twitter.com/Prefet971ZMariaztwitter 910031516746514432r-   r   r   z8https://twitter.com/LisPower1/status/1001551623938805763Z1001551417340022785Z1001551623938805763z re:.*?Shep is on a roll today.*?z$md5:37b9f2ff31720cef23b2bd42ee8a0f09Z	255036353z	Lis PowerZ	LisPower1go[@iA[Z20180529zhttps://twitter.com/LisPower1ztwitter 1001551623938805763z5https://twitter.com/foobar/status/1087791357756956680Z1087791272830607360Z1087791357756956680zX - A new is coming.  Some of you got an opt-in to try it now. Check out the emoji button, quick keyboard shortcuts, upgraded trends, advanced search, and more. Let us know your thoughts!z$md5:6dfd341a3310fb97d80d2bf7145df976XgjtN@iDlG\Z20190122zhttps://twitter.com/X)r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   zThis Tweet is unavailablez<https://twitter.com/ViviEducation/status/1136534865145286656Z1vOGwqejwoWxBzjVivi - Vivi founder @lior_rauchy announcing our new student feedback tool live at @EduTECH_AU #EduTECH2019ZViviZ1eVjYOLGkGrQLZEduTECH2019)r   r   r   r   r   r   r   r   ZTwitterBroadcastBroadcast no longer existsz@https://twitter.com/BrooklynNets/status/1349794411333394432?s=20Z1349774757969989634Z1349794411333394432z$md5:d1c4941658e4caaa6cb579260d85dcbaz$md5:71ead15ec44cee55071547d6447c6a3eZ18552281zBrooklyn NetsZBrooklynNetsg9vGt@i `Z20210114z https://twitter.com/BrooklynNetsztwitter 1349794411333394432z5https://twitter.com/oshtru/status/1577855540407197696Z1577855447914409984Z1577855540407197696z$md5:466a3a8b049b5f5a13164ce915484b51z$md5:b9c3699335447391d11753ab21c70a74Z20221006Z	143077138ZOshtruZoshtruzhttps://twitter.com/oshtrugHz>@iD>cztwitter 1577855540407197696)r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z<https://twitter.com/UltimaShadowX/status/1577719286659006464Z1577719286659006464zUltima Reload - TestzTest https://t.co/Y3KEZD7DadZ	168922496zUltima ReloadZUltimaShadowXz!https://twitter.com/UltimaShadowXZ20221005i5=c)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   )r-   r   playlist_countr   z9https://twitter.com/MesoMax919/status/1575560063510810624Z1575559336759263233Z1575560063510810624z$md5:eec26382babd0f7c18f041db8ae1c9c9z$md5:95aea692fda36a12081b9629b02daa92Z
1094109584z	Max OlsonZ
MesoMax919zhttps://twitter.com/MesoMax919gV-R5@iF5cZ20220929ZHurricaneIanztwitter 1575560063510810624)r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z7https://twitter.com/Rizdraws/status/1575199173472927762Z1575199163847000068Z1575199173472927762Z1217167793541480450ZRizdrawszhttps://twitter.com/RizdrawsZ20220928i+4czre:^https?://.+\.jpgztwitter 1575199173472927762)r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   zThe media could not be playedz;https://twitter.com/Srirachachau/status/1395079556562706435r   Z1395079556562706435Z21539378Z20210519zHere it is! Finished my gothic western cartoon. Pretty proud of it. It's got some goofs and lots of splashy over the top violence, something for everyone, hope you like it https://t.co/fOsG5glUnwZSrirachachauz https://twitter.com/SrirachachauiT`)r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r-   playlist_mincountr   z:https://twitter.com/DavidToons_/status/1578353380363501568Z1578353380363501568Z
2195866214ZDavidToons_i@czhttps://twitter.com/DavidToons_zkChris sounds like Linda from Bob's Burgers, so as an animator: this had to be done. https://t.co/WgJauwIW1wZ20221007)r   r   r   r   r   r   r   r   r   r   r   r   r   r   z;https://twitter.com/primevideouk/status/1578401165338976258Z1578401165338976258z$md5:659a6b517a034b4cee5d795381a2dc41Z19338359ZprimevideoukiA@@cz https://twitter.com/primevideoukZTheRingsOfPower)r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r-   r   r   z=https://twitter.com/MoniqueCamarra/status/1550101959377551360Z1lPJqmBeeNAJbm4az9EuroFile@6 Ukraine Up-date-Draghi Defenestration-the Westzre:Monique Camarra.+?ZMoniqueCamarrawas_liveiqbz2re:Twitter Space participated by Sergej Sumlenny.+i[KbZ20220721)r   r   r   r   r   live_statusrelease_timestampr   r   release_dater   ZTwitterSpacesr   r   zBhttps://twitter.com/CTVJLaidlaw/status/1600649710662213632/video/1Z1600649710662213632z$md5:be05989b0722e114103ed3851a0ffae2g   5LAz$md5:591c19ce66fadc2359725d5cd0d1052cZCTVJLaidlawZ80082014ZcolorectalcancerZcancerjourneyZimnotaquitterZ20221208zJocelyn Laidlawzhttps://twitter.com/CTVJLaidlaw)r   r   r   r   r   r   r   r   r   r   r   r   r   r   zBhttps://twitter.com/CTVJLaidlaw/status/1600649710662213632/video/2Z1600649511827013632z$md5:7662a0a27ce6faa3e5b160340f3cfab1gX9vY@ztwitter 1600649710662213632)r   r   r   r   r   r   r   r   r   r   r   r   r   ry   r   r   r   r   r   Z
noplaylistz6https://twitter.com/s2FAKER/status/1621117700482416640Z1621117577354424321Z1621117700482416640u$   뽀 - 아 최우제 이동속도 봐u6   아 최우제 이동속도 봐 https://t.co/dxu2U5vXXBg+8@Z1281839411068432384u   뽀Zs2FAKERzhttps://twitter.com/s2FAKERZ20230202g  @Azre:https?://pbs\.twimg\.com/.+ztwitter 1621117700482416640)r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z@https://twitter.com/hlo_again/status/1599108751385972737/video/2Z1599108643743473680Z1599108751385972737u	   ۪ - 💋Z1347791436809441283zhttps://twitter.com/hlo_againZ	hlo_againzbhttps://pbs.twimg.com/ext_tw_video_thumb/1599108643743473680/pu/img/UG3xjov4rgg5sbYM.jpg?name=origgZd;#@Z20221203g  lAu   ۪u   💋 https://t.co/bTj9Qz7vQPztwitter 1599108751385972737)r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z<https://twitter.com/MunTheShinobi/status/1600009574919962625Z1600009362759733248Z1600009574919962625Z	211814412z!https://twitter.com/MunTheShinobiuJ   This is a genius ad by Apple. 🔥🔥🔥🔥🔥 https://t.co/cNsA0MoOmlzbhttps://pbs.twimg.com/ext_tw_video_thumb/1600009362759733248/pu/img/XVhFQivj75H_YxxV.jpg?name=origu   MünZ20221206u9   Mün - This is a genius ad by Apple. 🔥🔥🔥🔥🔥ZMunTheShinobig$a@g   *Aztwitter 1600009574919962625)r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   z9https://twitter.com/liberdalau/status/1623739803874349067Z1623274794488659969Z1623739803874349067zQJohnny Bullets - Me after going viral to over 30million people:    Whoopsie-daisyz$md5:b06864cd3dc2554821cc327f5348485azJohnny BulletsZJohnnybull3tsz!https://twitter.com/Johnnybull3tsg7A` @g  AZ20230208z0re:https://pbs\.twimg\.com/ext_tw_video_thumb/.+)r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   zProtected tweetz=https://twitter.com/playstrumpcard/status/1695424220702888009Z1694928337846538240Z1695424220702888009z$md5:e8daa9527bc2b947121395494f786d9dz$md5:004f2d37fd58737724ec75bc7e679938Z15212187zBenny JohnsonZbennyjohnsonz https://twitter.com/bennyjohnsong㥛 F@g  #:AZ20230825z1re:https://pbs\.twimg\.com/amplify_video_thumb/.+ztwitter 1695424220702888009)r   r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zextractor_argsrl   rq   z>https://twitter.com/JessicaDobsonWX/status/1731121063248175384Z1rmxPMjLzAXKNz*WAVE Weather Now - Saturday 12/2/23 UpdatezJessica DobsonZJessicaDobsonWXz#https://twitter.com/JessicaDobsonWXikeZ20231203z re:https://[^/]+pscp\.tv/.+\.jpg)r   r   r   r   r   r   r   r   r  r   Zconcurrent_view_countr   )r-   r   r   z8https://twitter.com/BAKKOOONN/status/1696256659889565950Z1696256659889565950z BAKOON - https://t.co/zom968d0a0zhttps://t.co/zom968d0a0Z
1263540390ZBAKOONZ	BAKKOOONNzhttps://twitter.com/BAKKOOONNg  @o@;AZ20230828)r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r-   r   r   r   z>https://twitter.com/RobertKennedyJr/status/1724884212803834154Z 511377ff8dfa7545307084dca4dce319Z1724883339285544960z$md5:cc56716f9ed0b368de2ba54c478e493cz$md5:9dc14f5b0f1311fc7caf591ae253a164Z1724884212803834154Z	337808606zRobert F. Kennedy JrZRobertKennedyJrz#https://twitter.com/RobertKennedyJrZ20231115g  @IUAgT㥛Pu@Z	Kennedy24ztwitter 1724884212803834154)r   r   r   r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r-   r   r   z7https://x.com/historyinmemes/status/1790637656616943991Z daca3952ba0defe2cfafb1276d4c1ea5Z1790637589910654976z:Historic Vids - One of the most intense moments in historyzBOne of the most intense moments in history https://t.co/Zgzhvix8ESZ1790637656616943991zHistoric VidsZhistoryinmemesz"https://twitter.com/historyinmemesZ855481986290524160Z20240515g   9Ag`".@ztwitter 1790637656616943991)r   r   r   r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   zmhttps://twitter3e4tixl4xyajtrzo62zg5vztmjuricljdp2c5kshju4avyoid.onion/TwitterBlue/status/1484226494708662273r   z5https://twitter.com/GunB1g/status/1163218564784017422z9https://twitter.com/poco_dandy/status/1047395834013384704z9https://twitter.com/poco_dandy/status/1150646424461176832z7https://twitter.com/qarev001/status/1348948114569269251z9https://twitter.com/CAF_Online/status/1349365911120195585z>https://twitter.com/SamsungMobileSA/status/1348609186725289984z<https://twitter.com/SouthamptonFC/status/1347577658079641604z_video/(\d+)/c                 C   s   | j r
dS dS )Nz"zZXycP0V6H7m-2r0mOnFcA/TweetDetailz*2ICDjqPd81tulZcYrtpTuQ/TweetResultByRestIdrh   rg   r:   r:   r;   _GRAPHQL_ENDPOINT  s    zTwitterIE._GRAPHQL_ENDPOINTc           	         s  | j r6t|dddd fddddd	d
dthfi ddnt|dd
thfi d}|d}|dkrt| jd|  dd d|krtt|dddthfd}td|pd ddnj|dkr|d}|dkr| d n|dkr| d  t|pd!ddn |d"krt|d#thfpi }|d$i }|	t|d%d&d'd(d)ti d* |d+rxt|d,d
d-d.d
d$thfpni |d+ d/< d0d1 t|d2d3d4thfD }|r||d2 d3< |S )5NZ(threaded_conversation_with_injections_v2Zinstructionsr   entriesc                    s   |d d  kS )NZentryIdztweet-r:   r7   twidr:   r;   r<     r=   z.TwitterIE._graphql_to_legacy.<locals>.<lambda>contentZitemContentZtweet_resultsr   )tweetNF)defaultr   ZtweetResultr  Z
__typename)ZTweetTweetWithVisibilityResultsZTweetTombstoneTweetUnavailableNzUnknown typename: TZ	only_onceZ	tombstoner   z. Learn morezTwitter API says: r   r   r  reasonZNsfwLoggedOutz"NSFW tweet requires authenticationZ	Protectedz3You are not authorized to view this protected tweetzRequested tweet is unavailabler  r  rq   )coreuser_resultsr   rq   )cardrq   )Zquoted_status_resultr   rq   )rq   retweeted_status_resultr   rq   )userr  quoted_statusretweeted_status)expected_typer  r  r  r  r  r  c                 S   s   i | ]}| d | dqS )r   r{   r5   )r   Zbinding_valuer:   r:   r;   r     s    z0TwitterIE._graphql_to_legacy.<locals>.<dictcomp>r  binding_values.)
rh   r   dictr6   report_warningr   rx   r   r   r`   )	rF   rs   r
  r   typenamecauser  r   r  r:   r	  r;   _graphql_to_legacy  s       
       
 



       
zTwitterIE._graphql_to_legacyc                 C   s   | j rH|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S |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	S )
NTF)ZfocalTweetIdincludePromotedContentZwith_rux_injectionsZwithBirdwatchNoteswithCommunitywithDownvotePerspectiveZ&withQuickPromoteEligibilityTweetFieldswithReactionsMetadatawithReactionsPerspectivewithSuperFollowsTweetFieldswithSuperFollowsUserFieldsZwithV2Timeline	withVoice):graphql_is_translatable_rweb_tweet_is_translatable_enabledinteractive_text_enabled%responsive_web_edit_tweet_api_enabled$responsive_web_enhance_cards_enabled2responsive_web_graphql_timeline_navigation_enabledZ)responsive_web_text_conversations_enabledresponsive_web_uc_gql_enabledstandardized_nudges_misinfoGtweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled(tweetypie_unmention_optimization_enabledZFunified_cards_ad_metadata_container_dynamic_card_content_query_enabledverified_phone_label_enabledvibe_api_enabled	variablesfeatures)ZtweetIdr"  r!  r(  )Z/creator_subscriptions_tweet_preview_api_enabledr1  r+  r)  Z"view_counts_everywhere_api_enabledZ'longform_notetweets_consumption_enabledZ8responsive_web_twitter_article_tweet_consumption_enabledZ tweet_awards_web_tipping_enabledZ)freedom_of_speech_not_reach_fetch_enabledr/  r0  Z*longform_notetweets_rich_text_read_enabledZ(longform_notetweets_inline_media_enabledZ0responsive_web_graphql_exclude_directive_enabledr2  Z+responsive_web_media_download_video_enabledZAresponsive_web_graphql_skip_user_profile_image_extensions_enabledr-  r,  ZwithArticleRichContentState)r5  r6  ZfieldTogglesr  r   r:   r:   r;   r   #  sz     ! zTwitterIE._build_graphql_queryc                 C   s   | j d|dd | jd|dddi|dtjd	d
ddd}|sJtdg }t|dddthfD ]6}t|dddd| jj	hdfddp||d< |
| qbd|i|d< |S )Nz?Not all metadata or media is available via syndication endpointTr  z.https://cdn.syndication.twimg.com/tweet-resultzDownloading syndication JSON
User-AgentZ	Googlebot Z#123456789abcdefghijklmnopqrstuvwxyz
   )k)r   token)rt   r   z1Syndication endpoint returned empty JSON response)NZquoted_tweetZmediaDetails.
video_infovariantsr-   r   Fr   id_strmediaextended_entities)r  rv   r   randomchoicesr   r   r  _MEDIA_ID_REr_   rS   )rF   r
  r   r?  Zdetailr:   r:   r;   _call_syndication_apid  sB             zTwitterIE._call_syndication_apic              
   C   s   | j dkrt| j dddzX| js0| j dkrH| | | j||}n,| j dkrt| d| d|d	d
d
ddd}W nP tk
r } z2t|jt	r|jj
dks | d | |}W 5 d }~X Y nX | j dkr| |}t|dd tdpi S )N)rm   rq   syndicationz is not a valid API selectionTr   rm   rq   zstatuses/show/z.jsonzWeb-12r   r   extended)Zcards_platformZinclude_cardsZinclude_reply_countZinclude_user_entitiesZ
tweet_modei  z9Rate-limit exceeded; falling back to syndication endpointrE  r  r  )rp   r   rh   r   r   r  r   
isinstancer  r   r   r  rD  r   r  )rF   r
  r   er:   r:   r;   _extract_statusz  s*    




zTwitterIE._extract_statusc                    s   |dd\}}t|ddd hfddp:d }}td	d|}|d
pZi }|d}|rx| d| }|d}|||t|dt|dpt|d|t	|d dt
|dt
|dt
|d|drdndt|ddfdd  fdd}	t|ddd d!d thf}
j|d"d#rbt |
|	|d$}nt|ddd t|d% thfdd}|std&| d'd(d)n$|d*d+krtd,| d-d(d)t|
d%D ]h\}}|d|dkrq|d%kr
tgd.< t|
d%kr.d/  d0| 7  <  q8qΈ |d1iS fd2d3|D }|st|d4td5}|r||krjd6d(d) S j|fd1iS tg|d d.< t|d%kr|d S t|d%D ] \}}|d/  d0| 7  < qވj|fS )7Nr   index)Z	full_textr   c                 S   s   |  ddS )N
 )replacexr:   r:   r;   r<     r=   z)TwitterIE._real_extract.<locals>.<lambda>Fr   r8  z\s+(https?://[^ ]+)r  namez - screen_name
created_atZuser_id_strr>  https://twitter.com/%sZfavorite_countZretweet_countZreply_countZpossibly_sensitiver   r   )entitiesZhashtags.r   )r   r   r   r   r   r   r   r   r   r   r   r   r   c           
   	      s   t | ddtd}d|  g }i }t | dD ]*}|\}}||}|| q2g | dpt| d  r fdd	}| d
i  D ]\}}	|||	 q|d| dpi  |||t | ddthft	t | ddddS )Nr>  r   rG  zExtracting from video info: )r<  r=  .Zmedia_url_https	media_urlc              	      sJ    | t d| it|dp&|dt|dp<|dd d S )NrQ  wr\   hr]   r   r-   r\   r]   )rS   r   r   r6   )rQ  sizerV  
thumbnailsr:   r;   add_thumbnail  s    zOTwitterIE._real_extract.<locals>.extract_from_video_info.<locals>.add_thumbnailZsizesorigZoriginal_infoZ
mediaStatsZ	viewCount)r<  Zduration_millisr@   )resz
proto:m3u8brrZ  )r   rW   rX   r\  r   r   Z_format_sort_fields)
r   r   write_debugrM   rU   rT   r6   r   r   r   )
r?  r   rW   rX   rG   rI   rJ   r]  rQ  rZ  )rF   r
  r[  r;   extract_from_video_info  s.    z8TwitterIE._real_extract.<locals>.extract_from_video_infoc              
   3   s  | sd S  d| d  | d   fdd}| d dd }|d	kr`d|d
dV  n|dkrd|dpx|d
t dV  nx|dkrd|dt dV  nV|dkrdd|d t dV  n.|dkrd|ddV  n|dkr&|d}tt	|dt
dE d H  n|dk}|r<|dn|d}|d|rR|nd	 }||ph\}}g }	dD ]p}
|d|
 pi }|d}|rxd|krqx|	|
r|
dd  nd |t|d!t|d"d# qx|||	t|d$d%V  d S )&NzExtracting from card info: r-   r  c                    s     | pi }t|dd S )Nc                 S   s   | | d   d  S )Ntype_value)lowerrO  r:   r:   r;   r<     r=   zdTwitterIE._real_extract.<locals>.extract_from_card_info.<locals>.get_binding_value.<locals>.<lambda>)r6   r   )r:  or  r:   r;   get_binding_value  s    zRTwitterIE._real_extract.<locals>.extract_from_card_info.<locals>.get_binding_valuerQ  r*   playerZ
player_url)_typer-   Zperiscope_broadcast)rk  r-   ro   	broadcastZbroadcast_urlZ
audiospacezhttps://twitter.com/i/spaces/r   summaryZcard_urlunified_card)Zmedia_entities.rG  ZamplifyZamplify_url_vmapZplayer_stream_urlz%s_content_id)Z_smallr8  Z_largeZ_x_largeZ	_originalZplayer_imagez/player-placeholderr   Zmediumr\   r]   rY  Zcontent_duration_seconds)rW   rX   r\  r   )ra  r6   splitr   ro   TwitterBroadcastIETwitterSpacesIEZ_parse_jsonmapr   r  r[   rS   r   )r  rh  Z	card_namern  Z
is_amplifyrV   Z
content_idrW   rX   r\  suffiximageZ	image_url)rb  rF   r
  rg  r;   extract_from_card_info  sv    
  
z7TwitterIE._real_extract.<locals>.extract_from_card_info)Nr  r@  r?  c                 S   s   |d dkS )Nrc  Zphotor:   )r8   rb   r:   r:   r;   r<   !  r=   zURL-specified video number)Zvideo_labelr  r   zVideo #z is unavailableTr   rc  videozMedia #z is not a videor   r   z #ry   c                    s   g | ]} |d iqS )ry   r:   )r   rs   )infor
  r:   r;   
<listcomp>9  s     z+TwitterIE._real_extract.<locals>.<listcomp>)rU  rY   r   expanded_urlrG  z%No video could be found in this tweet)_match_valid_urlrD   rJ  r   rB   subr6   r   r   r   r   r  Z_yes_playlistrr  ra   r   	enumerater   lenr   raise_no_formatsr   Zplaylist_result)rF   r-   Zselected_indexr   r   r   r  r   r   ru  ZvideosZselected_entriesZdesired_objrK  entryr  ry  r:   )rb  rw  rF   r
  r;   r     s    
  


$J       
 

zTwitterIE._real_extractN)r   r   r   r   r   r   r   ra   rx   r   rB   compilerC  r   r  r   r   rD  rJ  r   r:   r:   r:   r;   r     s  
	 
  
             0Ar   c                   @   s8   e Zd ZdZdZddddddd	d
didZdd ZdS )TwitterAmplifyIEztwitter:amplifyz1https?://amp\.twimg\.com/v/(?P<id>[0-9a-f\-]{36})z<https://amp.twimg.com/v/0ba0c3c7-0af3-4c0a-bed5-7efd1ffa2951Z fec25801d18a4557c5c9f33d2c379ffaz$0ba0c3c7-0af3-4c0a-bed5-7efd1ffa2951r.   Twitter Videozre:^https?://.*)r   r   r   r   r   r   r   c                    s     |} || dd} ||\}}g } jdddd} fdd}|rz|d	\}	}
|||	|
d
 |d\}}|d ||d |d||dS )Nztwitter:amplify:vmapzvmap urlztwitter:image:srcr   Fr1   c                    s@   t  jd|  ddd}t  jd|  ddd}||fS )Nztwitter:z:widthFr  z:height)r   _html_search_meta)targetrW  rX  rF   Zwebpager:   r;   _find_dimensioni  s    
  
  z7TwitterAmplifyIE._real_extract.<locals>._find_dimensionrt  )r-   r\   r]   rj  r   r^   r  )r   r   rW   r\  )r   Z_download_webpager  r[   rS   r`   )rF   r-   rH   rV   rW   r8   r\  r   r  Zthumbnail_wZthumbnail_hZvideo_wZvideo_hr:   r  r;   r   ]  sB    
     zTwitterAmplifyIE._real_extractN)r   r   r   r   r   Z_TESTr   r:   r:   r:   r;   r  M  s   r  c                   @   s   e Zd ZdZejd Zddddddd	d
dded
ddddddddddded
ddddddddddded
dgZdd Z	dS )rp  ztwitter:broadcastz$i/broadcasts/(?P<id>[0-9a-zA-Z]{13})z.https://twitter.com/i/broadcasts/1yNGaQLWpejGjZ1yNGaQLWpejGjr.   z(Andrea May Sahouri - Periscope BroadcastzAndrea May SahouriZandreamsahouriz"https://twitter.com/andreamsahouriiT^Z20200601z re:^https?://[^?#]+\.jpg\?token=)
r   r   r   r   r   r   r   r   r   r   r   z.https://twitter.com/i/broadcasts/1ZkKzeyrPbaxvZ1ZkKzeyrPbaxvz+Starship | SN10 | High-Altitude Flight TestZSpaceXzhttps://twitter.com/SpaceXi@`Z20210303z.https://twitter.com/i/broadcasts/1OyKAVQrgzwGbZ1OyKAVQrgzwGbzStarship Flight Testi0AdZ20230420c                 C   s$  |  |}| d|d|id | }|s4tddd| ||}|dpR|d|d< |d	pj|d
|d
< t|d	dd d|d< |d dkr|S |d }| d| |d }|dp|d }d|kr|   tj	tj
|jdd gd }| |\}	}
}| ||||	|
||d< |S )Nzbroadcasts/show.jsonidsZ
broadcastsr   Tr   r   r   Ztwitter_usernamer   rT  r  r   r  is_upcoming	media_keylive_video_stream/status/sourcenoRedirectPlaybackUrlr   z/live_video_stream/geoblocked/rc  r   rW   )r   r   r   Z_parse_broadcast_datar6   r   Zraise_geo_restrictedrO   rP   parse_qsurlparser   Z_extract_common_format_infoZ_extract_pscp_m3u8_formats)rF   r-   Zbroadcast_idrl  rw  r  r  Zm3u8_urlr0   stater\   r]   r:   r:   r;   r     s\    
        z TwitterBroadcastIE._real_extractNr   r:   r:   r:   r;   rp    sV   
-rp  c                   @   s   e Zd ZdZejd 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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 d*d+d,d-d$d.d/d
d0d1d2d1d3d4ddid gZd5d
d6dd7Zd8d9 Z	d:d; Z
d<S )=rq  ztwitter:spacesz i/spaces/(?P<id>[0-9a-zA-Z]{13})z*https://twitter.com/i/spaces/1RDxlgyvNXzJLZ1RDxlgyvNXzJLr  z;King Carlo e la mossa Kansas City per fare il Grande CentrozdTwitter Space participated by annarita digiorgio, Signor Ernesto, Raffaello Colosimo, Simone M. Sepezre:Lucio Di Gaetano.*?Zluciodigaetanor  iDbZ20220807i b)r   r   r   r   r   r   r  r   r   r  r  zNo longer availabler   z*https://twitter.com/i/spaces/1vAxRAVQWONJlZ1vAxRAVQWONJlz Framing Up FinOps: Billing Toolsz5Twitter Space participated by rupa, Alfonso HernandezzGoogle CloudZgooglecloud	post_liveiF8dZ20230413i>dZ20230418r   m4a_dash)r   r   r   r   r   r   r  r   r   r  r  protocol	containerr   r   z*https://twitter.com/i/spaces/1eaKbrQbjoRKXZ1eaKbrQbjoRKXu   あz(Twitter Space participated by nobody yetu   息根とめるZtomeru_ikinonei.zxdZ20230601)r   r   r   r   r   r   r  r   r   r  r  z$https://x.com/i/spaces/1DXGydznBYWKMZ1DXGydznBYWKMr.   u1   America and Israel’s “special relationship”zCandace OwensZRealCandaceOifZ20240817i`fr/   )r   r   r   r   r   r   r  r   r   r  r  r  r  is_live)Z
notstartedZendedZrunningZtimedoutc                 C   s2   |ddddddddddddddddddd
dS )NTF)r   ZisMetatagsQueryr#  r$  r%  ZwithReplaysr'  r&  )
Z dont_mention_me_view_api_enabledr*  r+  r,  r.  Zspaces_2022_h2_clippingZ!spaces_2022_h2_spaces_communitiesr/  r0  r3  r4  r:   )rF   space_idr:   r:   r;   r   &  s*    z$TwitterSpacesIE._build_graphql_queryc                    s   |}d|d }|s*tddd|d  t fdd}|d	k}g }d
di}|dkrpjddd n|s dsjddd n dr8td d   d ddthfdd}|od|k}	|rj	| d |	rdnd|	rdnd||ddng }|	r8|D ]$}
|

ddd |sd|
d < qd!t|d"pLd#}|sl|d$krljd%dd | d&d'| t d(t d)|t fd*dt d+d,d-||d.
S )/Nz%HPEisOmj1epUNLCWTYhUWw/AudioSpaceByIdZ
audioSpacezTwitter Space not foundTr   metadatac                      s   j  d   S )Nr  )SPACE_STATUSre  r:   r  rF   r:   r;   r<   G  r=   z/TwitterSpacesIE._real_extract.<locals>.<lambda>r  r   ri   r  zTwitter Space not started yetZis_space_available_for_replayz*Twitter Space ended and replay is disabledr  r  r  )r  r   Fr   zaudio-spacer  r.   r   r/   )Zentry_protocolZlivert   r1   r3   Zaac)r2   Zacodecr  r  r   )participantsZspeakers.Zdisplay_namez
nobody yetr  z,Twitter Space ended but not downloadable yetr   zTwitter Space participated by )creator_resultsr   rq   rQ  )r  r   rq   rR  c                      s   t  d ddS )NZscheduled_startr@   Zscale)r   r:   )r  r:   r;   r<   p  r=   rS  r@   r  )
r   r   r   r   r   r  r  r   rW   Zhttp_headers)r   r   r   r   r~  r6   r   r   r   Z_extract_m3u8_formatsr`   r   r   )rF   r-   r  Z
space_datar  r  rW   rt   r  Zis_audio_spacefmtr  r:   r  r;   r   @  s    

   

     
zTwitterSpacesIE._real_extractN)r   r   r   r   r   r   r   r   r  r   r   r:   r:   r:   r;   rq    s   
Irq  c                   @   s    e Zd ZdZdZdZdd ZdS )TwitterShortenerIEztwitter:shortenerz1https?://t\.co/(?P<id>[^?#]+)|tco:(?P<eid>[^?#]+)zhttps://t.co/c                 C   sf   |  |}|dd\}}|r,|}| j| }| j||ddidj}d}||r\||d}| |S )Neidr   r7  Zcurl)rt   z;https://twitter.com/safety/unsafe_link_warning?unsafe_link=r8  )rz  rD   	_BASE_URLZ_request_webpager-   
startswithrN  r   )rF   r-   rL   r  Z	shortcodenew_urlZ _TwitterShortenerIE__UNSAFE_LINKr:   r:   r;   r   |  s    


z TwitterShortenerIE._real_extractN)r   r   r   r   r   r  r   r:   r:   r:   r;   r  w  s   r  )'r   r   rA  rB   urllib.parserO   commonr   Z	periscoper   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  rp  rq  r  r:   r:   r:   r;   <module>   s6   P  8~         9M %