
    V|hC                         S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKr	SSK
Jr  SSKJrJr  SSKJrJr   " S S\5      r " S	 S
\5      r " S S\5      r " S S5      rg)    N   )InfoExtractor   )ExtractorErrorint_or_none)	get_firsttraverse_objc                       \ rS rSrSrSrSSSSSS	S
SSSS.	SS0SS.SSSSSS.SS0SS.SSSSSSSSSSS .	SS0SS./rS!rS" rS# r	S$ r
S%rg!)&GoPlayIE   zChttps?://(www\.)?goplay\.be/video/([^/?#]+/[^/?#]+/|)(?P<id>[^/#]+)goplayzhttps://www.goplay.be/video/de-slimste-mens-ter-wereld/de-slimste-mens-ter-wereld-s22/de-slimste-mens-ter-wereld-s22-aflevering-1z$2baa4560-87a0-421b-bffc-359914e3c387mp4z/De Slimste Mens ter Wereld - S22 - Aflevering 1zJre:In aflevering 1 nemen Daan Alferink, Tess Elst en Xander De Rycke .{66}zDe Slimste Mens ter WereldzWordt aangekondigd   r   z	Season 22)	idexttitledescriptionseriesepisodeseason_numberepisode_numberseasonskip_downloadTz1This video is only available for registered users)url	info_dictparamsskipz https://www.goplay.be/video/1917z$40cac41d-8d29-4ef5-aa11-75047b9f09071917zHre:Op het hoogtepunt van de Eerste Wereldoorlog krijgen twee jonge .{94})r   r   r   r   zNhttps://www.goplay.be/video/de-mol/de-mol-s11/de-mol-s11-aflevering-1#autoplayz$ecb79672-92b9-4cd9-a0d7-e2f0250681eezDe Mol - S11 - Aflevering 1zNre:Tien kandidaten beginnen aan hun verovering van Amerika en ontmoeten .{102}z	Episode 1zDe Mol   z	Season 11)	r   r   r   r   r   r   r   r   r   Nc                 h    U R                  5         [        U SSS9nUR                  XS9u  U l        ng )Nzeu-west-1_dViSsKM5Y6s1h851s8uplco5h6mqh1jac8m)iepool_id	client_id)usernamepassword)report_loginAwsIdpauthenticate	_id_token)selfr%   r&   aws_s        Q/home/james-whalen/.local/lib/python3.13/site-packages/yt_dlp/extractor/goplay.py_perform_loginGoPlayIE._perform_login@   s8    &;Gcd,,h,R    c                 D    U R                   (       d  U R                  SS9eg )Nr&   )method)r*   raise_login_requiredr+   s    r.   _real_initializeGoPlayIE._real_initializeE   s"    ~~++:+>> r1   c                 <  ^^ U R                  T5      nU R                  TU5      nU R                  X25      n[        UU4S j5      nUS   m[	        US[
        14S[
        R                  14S.5      n[	        US5      S:w  a  [	        USS	S[        145       H  n[	        US
U4S j[        45      nU(       d  M#  [	        US[        145      n	UR                  [	        US[
        145      [	        US[        145      U	U R                  SU	 S3UR                  S5      SS S9S.5          O   U R                  ST 3TSSU R                   30U R                  5       ES9n
SU
;   a  U R!                  U
S   S   TSSS9u  pOSU
;  a  [#        S5      eU
S   S   nU
S   S    nU R                  S!U S"U S#3TS$S%S&0S'9nU R%                  US(   T5      nU Vs/ s H  nS)US*   ;  d  M  UPM     nnU R'                  U5      u  pUR                  TUUS+.5        U$ s  snf ),Nc                 z   > U S;   =(       a/    US   [         R                  R                  T5      R                  :H  $ )N)videometapath)urllibparseurlparser<   )kvr   s     r.   <lambda>(GoPlayIE._real_extract.<locals>.<lambda>O   s2    //`AfIAVAVWZA[A`A`4``r1   uuidr   r   )r   r   )programsubtypemovie.	playlistsvideosc                    > US   T:H  $ )NvideoId )r-   rA   video_ids     r.   rB   rC   Y   s    QRS\Q]aiQir1   r   episodeTitleepisodeNumberz
^(.+)? - Sz - r   )default)r   r   r   r   z.https://api.goplay.be/web/v1/videos/long-form/AuthorizationzBearer )headersmanifestUrlshlsr   HLS)r   m3u8_idssaizexpecting Google SSAI streamcontentSourceIDvideoIDz-https://dai.google.com/ondemand/dash/content/z/vid/z/streamss   {"api-key":"null"}zcontent-typezapplication/json)datarR   stream_manifestz-ad-r   )r   formats	subtitles)	_match_id_download_webpage_search_nextjs_v13_datar   r	   strstripdictanyr   update_search_regexget_download_jsonr*   geo_verification_headers#_extract_m3u8_formats_and_subtitlesr   _extract_mpd_periods_merge_mpd_periods)r+   r   
display_idwebpagenextjs_datar;   r   season_dataepisode_datar   apir\   r]   ssai_content_source_idssai_video_iddaiperiodsprM   s    `                @r.   _real_extractGoPlayIE._real_extractI   s   ^^C(
((j9227G`c < u%)CII;7(
 	
 45@+K#{CRVQW9XY+K(Dikn9op# ,[8k]:S T  +L>C5:QR&2</T_S`Aa&b%2"00%m_C8)--:PRZdh 1 j	"    Z !!<XJG74>>*:!;//1 "  S !%!I!IN#E*H% "J "PGY S $%CDD%([1B%C"K	2M%%?@V?WW\]j\kkst4');< & >C
 //4E0FQG #*C'QV1T7-Bq'GC!%!8!8!AG"
 	
  Ds   H'H)r*   )__name__
__module____qualname____firstlineno__
_VALID_URL_NETRC_MACHINE_TESTSr*   r/   r6   rx   __static_attributes__rL   r1   r.   r   r      s    WJN S8Fh2+!

 #D)C  28f	
 #D)C
 `82l"!

 #D)C3(FT IS
?Ar1   r   c                       \ rS rSrSrSrg)InvalidLoginException   z"The login credentials are invalid rL   Nrz   r{   r|   r}   __doc__r   rL   r1   r.   r   r      s    -r1   r   c                       \ rS rSrSrSrg)AuthenticationException   z&Something went wrong while logging in rL   Nr   rL   r1   r.   r   r      s    1r1   r   c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rSrg)r(      zAWS Identity Provider c                 d   Xl         X l        SU R                  ;  a  [        S5      eX0l        U R                  R	                  S5      S   U l        SU R
                   S3U l        SU l        SU l        [        SS	5      U l
        U R                  U R                  5      U l        U R                  U R                  5      U l        U R                  U R                  S
U R                  -   S-   U R                  -   5      5      U l        U R!                  5       U l        U R%                  5       U l        g)a%  
:param InfoExtrator ie: The extractor that instantiated this class.
:param str pool_id:     The AWS user pool to connect to (format: <region>_<poolid>).
                        E.g.: eu-west-1_aLkOfYN3T
:param str client_id:   The client application ID (the ID of the application connecting)
r-   z4Invalid pool_id format. Should be <region>_<poolid>.r   zhttps://cognito-idp.z.amazonaws.com/   FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF2zCaldera Derived Keyutf-8000N)r"   r#   
ValueErrorr$   splitregionr   n_hexg_hex	bytearray	info_bits_AwsIdp__hex_to_longbig_ng_AwsIdp__hex_hashr@    _AwsIdp__generate_random_small_asmall_a_value_AwsIdp__calculate_alarge_a_value)r+   r"   r#   r$   s       r.   __init__AwsIdp.__init__   s     dll"STT"ll((-a0)$++oF
? 	
& 
"#8'B''

3
##DJJ/##DOOD4::4E4Kdjj4X$YZ!;;=!//1r1   c           	      8   U R                  U5      n[        R                  " U5      R                  5       nSSSS.nU R                  R                  U R                  SXESSS9nUR                  S	5      nUR                  S
5      S:w  a  [        US   5      eU R                  Xr5      n[        R                  " U5      R                  5       n	SSS.n
U R                  R                  U R                  SXSSS9nSU;   a  [        US   5      eUS   S   US   S   4$ )z+Authenticate with a username and password. z.AWSCognitoIdentityProviderService.InitiateAuthidentityzapplication/x-amz-json-1.1)X-Amz-TargetzAccept-EncodingContent-TypeNzAuthenticating usernamezInvalid username)rZ   rR   noteerrnoteChallengeParametersChallengeNamePASSWORD_VERIFIERmessagez8AWSCognitoIdentityProviderService.RespondToAuthChallenge)r   r   zAuthenticating passwordzInvalid passwordAuthenticationResultIdTokenRefreshToken)#_AwsIdp__get_authentication_requestjsondumpsencoder"   rh   r   rg   r   '_AwsIdp__get_challenge_response_requestr   )r+   r%   r&   auth_data_dict	auth_dataauth_headersauth_response_jsonchallenge_parameterschallenge_requestchallenge_datachallenge_headerss              r.   r)   AwsIdp.authenticate   sL    ::8DJJ~.557	L)8

 "WW33HHd*4F 4 H  2556KL!!/26II)*<Y*GHH !AABVa$56==?V8
 "WW33HHd*4F 4 H **'(:9(EFF56yA56~F
 	
r1   c                 Z    UU R                  U R                  5      S.SU R                  S.$ )zc

:param str username:    The username to use

:return: A full Authorization request.
:rtype: dict
)USERNAMESRP_AUSER_SRP_AUTH)AuthParametersAuthFlowClientId)_AwsIdp__long_to_hexr   r$   )r+   r%   s     r.   __get_authentication_request#AwsIdp.__get_authentication_request   s6     %++D,>,>? (
 	
r1   c                 8   US   nUS   nUS   nUS   nUS   nU R                  5       nU R                  UUU R                  U5      U5      n	[        R                  " U5      n
[        U R                  R                  S5      S   S5      [        US5      -   [        U
5      -   [        US5      -   n[        R                  " X[        R                  S	9n[        R                  " UR                  5       5      R                  S5      nUUUUS
.SU R                  S.$ )a  Create a Challenge Response Request object.

:param dict[str,str|imt] challenge_parameters:  The parameters for the challenge.
:param str password:                            The password.

:return: A valid and full request data object to use as a response for a challenge.
:rtype: dict
r   USER_ID_FOR_SRPSRP_BSALTSECRET_BLOCKr-   r   r   )	digestmod)r   	TIMESTAMPPASSWORD_CLAIM_SECRET_BLOCKPASSWORD_CLAIM_SIGNATUREr   )ChallengeResponsesr   r   )_AwsIdp__get_current_timestamp"_AwsIdp__get_hkdf_key_for_passwordr   base64standard_b64decoder   r#   r   hmacnewhashlibsha256standard_b64encodedigestdecoder$   )r+   r   r&   user_iduser_id_for_srpsrp_bsaltsecret_block	timestamphkdfsecret_block_bytesmsghmac_objsignature_strings                 r.    __get_challenge_response_request'AwsIdp.__get_challenge_response_request   s6    'z2./@A$W-#F++N;002	 //u%	
 $66|D dll((-a0':ow/0()* i)* 	
 88D@!44X__5FGNNwW $&/;,<	# 1	
 		
r1   c           
         U R                  U R                  U5      nUS:X  a  [        S5      eSR                  U R                  R                  S5      S   X5      nU R                  UR                  5       5      nU R                  U R                  U R                  U5      U-   5      5      n[        U R                  XR                  5      n	X0R                  U	-  -
  n
[        XR                  XX-  -   U R                  5      nU R!                  ["        R%                  U R                  U5      5      ["        R%                  U R                  U R'                  U5      5      5      5      $ )a)  Calculates the final hkdf based on computed S value, and computed U value and the key.

:param str username:        Username.
:param str password:        Password.
:param int server_b_value:  Server B value.
:param int salt:            Generated salt.

:return Computed HKDF value.
:rtype: object
r   zU cannot be zero.z{}{}:{}r-   r   )_AwsIdp__calculate_ur   r   formatr#   r   _AwsIdp__hash_sha256r   r   r   _AwsIdp__pad_hexpowr   r   r@   r   _AwsIdp__compute_hkdfr   fromhexr   )r+   r%   r&   server_b_valuer   u_valueusername_passwordusername_password_hashx_valueg_mod_pow_xn
int_value2s_values               r.   __get_hkdf_key_for_password"AwsIdp.__get_hkdf_key_for_password-  s(    $$T%7%7Ha<011%,,T\\-?-?-DQ-G\!%!3!34E4L4L4N!O$$T__T^^D5ILb5b%cd4667JJ7#ff|&;;
j"4"4w7H"H$**U""dnnW56dnnT-?-?-HIJ
 	
r1   c                    [         R                  " X![        R                  5      R	                  5       nU R
                  [        [        S5      S5      -   n[         R                  " X4[        R                  5      R	                  5       nUSS $ )zStandard hkdf algorithm

:param {Buffer} ikm Input key material.
:param {Buffer} salt Salt value.
:return {Buffer} Strong key material.
r   r   N   )r   r   r   r   r   r   r   chr)r+   ikmr   prkinfo_bits_update	hmac_hashs         r.   __compute_hkdfAwsIdp.__compute_hkdfH  sd     hht'..188:>>Ic!fg,FFHHSGNNCJJL	"~r1   c                     U R                  U R                  U5      U R                  U5      -   5      nU R                  U5      $ )zCalculate the client's value U which is the hash of A and B

:param int big_a:   Large A value.
:param int big_b:   Server B value.

:return Computed U value.
:rtype: int
)r   r   r   )r+   big_abig_b
u_hex_hashs       r.   __calculate_uAwsIdp.__calculate_uU  s:     __T^^E%:T^^E=R%RS
!!*--r1   c                 @    U R                  S5      nXR                  -  $ )zVHelper function to generate a random big integer

:return a random value.
:rtype: int
   )_AwsIdp__get_randomr   )r+   random_long_ints     r.   __generate_random_small_a AwsIdp.__generate_random_small_ab  s!     ++C0++r1   c                     [        U R                  U R                  U R                  5      nXR                  -  S:X  a  [	        S5      eU$ )zxCalculate the client's public value A = g^a%N with the generated random number a

:return Computed large A.
:rtype: int
r   zSafety check for A failed)r   r   r   r   r   )r+   r  s     r.   __calculate_aAwsIdp.__calculate_ak  s@     DFFD..

;JJ1$899r1   c                 
    U S $ )NxrL   )long_nums    r.   __long_to_hexAwsIdp.__long_to_hexx  s    1r1   c                     [        U S5      $ )Nr   )int
hex_strings    r.   __hex_to_longAwsIdp.__hex_to_long|  s    :r""r1   c                 R    [         R                  [        R                  U 5      5      $ N)r(   r   r   r   r  s    r.   
__hex_hashAwsIdp.__hex_hash  s    ##I$5$5j$ABBr1   c                 r    [         R                  " U 5      R                  5       nS[        U5      -
  S-  U-   $ )zAuthenticationHelper.hash@   r   )r   r   	hexdigestlen)bufr   s     r.   __hash_sha256AwsIdp.__hash_sha256  s4     $..0S[ C'&00r1   c                     [        U [        5      (       d  [        R                  U 5      nOU n[	        U5      S-  S:X  a  SU 3nU$ US   S;   a  SU 3nU$ )zConverts a Long integer (or hex string) to hex format padded with zeroes for hashing

:param int|str long_int:    Number or string to pad.

:return Padded hex string.
:rtype: str
r   r   r   r   89ABCDEFabcdefr   )
isinstancera   r(   r   r&  )long_inthash_strs     r.   	__pad_hexAwsIdp.__pad_hex  sh     (C((++H5HHx=1!8*~H  a[,,H:Hr1   c                     [         R                  " [        R                  " U 5      5      n[        R                  U5      $ r   )binasciihexlifyosurandomr(   r   )nbytes
random_hexs     r.   __get_randomAwsIdp.__get_random  s,    %%bjj&89
##J//r1   c                     / SQn / SQn[         R                  R                  [         R                  R                  5      nXR                  5           SXR                      SUR                   S3nUR                  U5      $ )z~Creates a timestamp with the correct English format.

:return: timestamp in format 'Sun Jan 27 19:00:04 UTC 2019'
:rtype: str
)NJanFebMarAprMayJunJulAugSepOctNovDec)MonTueWedThuFriSatSun z %H:%M:%S UTC %Y)	dtdatetimenowtimezoneutcweekdaymonthdaystrftime)monthsdaystime_nowformat_strings       r.   __get_current_timestampAwsIdp.__get_current_timestamp  sl     l@;;??2;;??3 0 0 234Af^^6L5MQx||n\lm  //r1   c                     SR                  U R                  U R                  R                  S5      S   U R                  5      $ )Nz4AWS IDP Client for:
Region: {}
PoolId: {}
AppId:  {}r-   r   )r   r   r#   r   r$   r5   s    r.   __str__AwsIdp.__str__  s8    HOOKK++C03T^^
 	
r1   )r   r$   r   r   r"   r   r@   r   r   r#   r   r   r   N)rz   r{   r|   r}   r   r   r)   r   r   r   r   r   r   r   staticmethodr   r   r   r   r   r  r   r_  r   rL   r1   r.   r(   r(      s    !.2`"
H
"+
Z
6.,   # # C C 1 1
  & 0 0 0 0 
r1   r(   )r   r2  rP  rO  r   r   r   r4  urllib.parser=   commonr   utilsr   r   utils.traversalr   r	   r   r   r   r(   rL   r1   r.   <module>rf     sY          	  ! / 5{} {B.N .2n 2_
 _
r1   