
    V|h)                         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  SSKJrJrJrJr  SSKJr   " S S	\	5      r " S
 S\	5      rg)    N   )InfoExtractor   )	HTTPError)ExtractorErrorint_or_nonejwt_decode_hs256try_call)traverse_objc                       \ rS rSrSrSSSSS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S./rS/r0 rSrSr	S r
S rS rS rS rS rg!)"	SonyLIVIE   a  (?x)
                     (?:
                        sonyliv:|
                        https?://(?:www\.)?sonyliv\.com/(?:s(?:how|port)s/[^/]+|movies|clip|trailer|music-videos)/[^/?#&]+-
                    )
                    (?P<id>\d+)
                  zehttps://www.sonyliv.com/shows/bachelors-delight-1700000113/achaari-cheese-toast-1000022678?watch=truezAchaari Cheese Toast
1000022678mp420200411z$md5:3957fa31d9309bf336ceb3f37ad5b7cbi^   r   zBachelors Delighti  )titleidextupload_datedescription	timestampdurationseason_numberseriesepisode_numberrelease_yearskip_downloadT)url	info_dictparamsz<https://www.sonyliv.com/movies/tahalka-1000050121?watch=true)r   only_matchingz1https://www.sonyliv.com/clip/jigarbaaz-1000098925zHhttps://www.sonyliv.com/trailer/sandwiched-forever-1000100286?watch=truezhttps://www.sonyliv.com/sports/india-tour-of-australia-2020-21-1700000286/cricket-hls-day-3-1st-test-aus-vs-ind-19-dec-2020-1000100959?watch=truezHhttps://www.sonyliv.com/music-videos/yeh-un-dinon-ki-baat-hai-1000018779INz|Use "--username <mobile_number>" to login using OTP or "--username token --password <auth_token>" to login using auth token.sonylivc                    [        [        R                  " 5       S-  5      n[        S5      n[        U5       Hq  u  p4[        US[        R                  " 5       -  -   S-  5      S-  n[
        R                  " US-  5      nUS:X  a  [        U5      X#'   M]  US:X  d  Me  SU-  S-  S X#'   Ms     S	R                  U5      S
-   [        [        [        R                  " 5       S-  5      5      -   $ )N   xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx   r   xy       -)	inttimelist	enumeraterandommathfloorstrjoin)selfeticns         R/home/james-whalen/.local/lib/python3.13/site-packages/yt_dlp/extractor/sonyliv.py_get_device_idSonyLIVIE._get_device_idC   s    		d"#34aLDAQfmmo--34q8A

1r6"ACx1vca%!)A ! wwqzC#c$))+*<&=">>>    c                   ^ U R                  5       U R                  S'   SU R                  S'   UR                  5       S:X  a4  [        U4S j5      (       a   TU R                  S'   U R	                  5         g [        U5      S:w  d  UR                  5       (       d  [        SU R                   35      eU R	                  5         U R                  S	S S
U R                  [        R                  " USS[        R                  R                  5       R                  S5      SSSS.5      R!                  5       S9nUS   S:X  a  [        US   SS9eU R                  SS SU R                  [        R                  " SUSU R#                  S5      SS[        R                  R                  5       R                  S5      SS.5      R!                  5       S9nUS   S:X  a  [        US   SS9eUS   S   U R                  S'   g )N	device_idzapplication/jsonzcontent-typetokenc                     > [        T 5      $ )N)r	   )passwords   r>   <lambda>*SonyLIVIE._perform_login.<locals>.<lambda>S   s    <LX<VrA   authorization
   zInvalid username/password; z>https://apiv2.sonyliv.com/AGL/1.6/A/ENG/WEB/IN/HR/CREATEOTP-V2zSending OTPMSMINDr#   z%Y-%m-%dT%H:%M:%S.%MZ   REGISTERORSIGNINT)mobileNumberchannelPartnerIDcountryr   otpSize	loginTypeisMobileMandatory)noteheadersdata
resultCodeKOmessage)expectedz?https://apiv2.sonyliv.com/AGL/2.0/A/ENG/WEB/IN/HR/CONFIRMOTP-V2zVerifying OTPOTP)rO   rN   rP   otpdmaIdageConfirmationr   rS   	resultObjaccessToken)r?   _HEADERSlowerr
   report_loginlenisdigitr   _LOGIN_HINT_download_jsonjsondumpsdtdatetimenowstrftimeencode_get_tfa_info)r8   usernamerF   otp_request_jsonotp_verify_jsons     `  r>   _perform_loginSonyLIVIE._perform_loginO   s   %)%8%8%:k"(:n%>>w&84V+W+W-5DMM/*]b (8(8(:(: #>t?O?O>P!QRR..L}dmm$** ($,[[__.778OP/%)N C vx / 
 L)T1 !1)!<tLL--MDJJ$, ())%0#'[[__.778OP%)	P 	E vx .  <(D0 !1)!<tLL)8)Em)To&rA   c                     U R                  SU SU 3X0R                  S9S   $ ! [         GaJ  n[        UR                  [
        5      (       a}  UR                  R                  S:X  ac  U R                  UR                  R                  R                  5       R                  5       U5      S   S:X  a  U R                  U R                  S S9  [        UR                  [
        5      (       a  UR                  R                  S	:X  ao  U R                  UR                  R                  R                  5       R                  5       U5      S   nUS
:X  a  U R                  U R                  S9  [        U5      ee S nAff = f)Nzhttps://apiv2.sonyliv.com/AGL/z/A/ENG/WEB/rU   r_   i  rY   z&Please subscribe to watch this content)methodi  zGeoblocked Country)	countries)rg   ra   r   
isinstancecauser   status_parse_jsonresponsereaddecoderaise_login_requiredrf   raise_geo_restricted_GEO_COUNTRIES)r8   versionpathvideo_idr9   rY   s         r>   	_call_apiSonyLIVIE._call_apiy   sV   	&&0	TFK-- ' 11<> >  
	!''9--!''..C2GDL\L\GG$$))+224hM@@IMKNvMw))$*:*:4)H!''9--!''..C2G**GG$$))+224h@@IK22--8K8K-L$W--
	s   "% E:EE55E:c                 D    U R                  SSS 5      U R                  S'   g )Nz1.4zALL/GETTOKENsecurity_token)r   ra   )r8   s    r>   _initialize_pre_loginSonyLIVIE._initialize_pre_login   s    *...PT*U&'rA   c                    U R                  U5      nU R                  SSU-   U5      nU R                  S5      (       d'  UR                  S5      (       a  U R	                  U5        US   nSS[
        R                  " 5       R                  [        R                  " 5       S-  4-  0nU R                  XBS	US
S9nUR                  U R                  UR                  SS5      R                  SS5      USSUS
S95        U H$  nUR                  S0 5      R                  U5        M&     U R                  SSU-   U5      S   S   S   nUS   n	0 n
UR                  S/ 5       HP  nUR                  S5      nU(       d  M  U
R                  UR                  SS5      / 5      R                  SU05        MR     UU	UUR                  S5      UR                  S 5      =(       d    UR                  S!5      [!        UR                  S"5      S5      [!        UR                  S#5      5      [!        UR                  S$5      5      UR                  S%5      [!        UR                  S&5      5      [!        UR                  S'5      5      U
S(.$ ))Nz1.5zIN/CONTENT/VIDEOURL/VOD/allow_unplayable_formatsisEncryptedvideoURLzx-playback-session-idz%s-%dr&   dashF)mpd_idrU   fatalz.mpdz.m3u8z/DASH/z/HLS/r   hls)m3u8_idrU   r   http_headersz1.6z
IN/DETAIL/
containersr   metadataepisodeTitlesubtitlesubtitleUrlsubtitleLanguageNameENGr   	posterURLlongDescriptionshortDescriptioncreationDater   seasonr   episodeNumberyear)r   r   formats	thumbnailr   r   r   r   r   r   r   	subtitles)	_match_idr   	get_paramget
report_drmuuiduuid4hexr0   _extract_mpd_formatsextend_extract_m3u8_formatsreplace
setdefaultupdateappendr   )r8   r   r   contentdash_urlrU   r   fr   r   r   subsub_urls                r>   _real_extractSonyLIVIE._real_extract   s`   >>#&..-8(D~~899gkk->X>XOOH%:&#W

0@0@$))+PTBT/U%U
 ++vwe , Mt11VW-55hHeUG5 2 J 	K ALL,33G<  >><(*H66BDDEGGQS(	;;z2.Cggm,G  )?!GLSSwU 	 /  [1#<<(9:^hllK]>^$X\\.%A4H#HLL$<=(h)?@ll7+)(,,*GH'V(<="
 	
rA    N)__name__
__module____qualname____firstlineno__
_VALID_URL_TESTSr   ra   rf   _NETRC_MACHINEr?   rs   r   r   r   __static_attributes__r   rA   r>   r   r      s    J w+%A#) 
 T
& N C Z c Z=!FD VNH QKN
?(UT"V*
rA   r   c                   L    \ rS rSrSrSSSS0S.SS	SS
0S./rSrSrS rS r	Sr
g)SonyLIVSeriesIE   zIhttps?://(?:www\.)?sonyliv\.com/shows/[^/?#&]+-(?P<id>\d{10})/?(?:$|[?#])z0https://www.sonyliv.com/shows/adaalat-1700000091i  r   
1700000091)r   playlist_mincountr    z1https://www.sonyliv.com/shows/beyhadh-1700000007/if  
1700000007zhttps://apiv2.sonyliv.com/AGL)ascdescc              #     #    SSS.nU R                  U R                   S3USUS9S   US'   [        U R                  U R                   S	U 3US
USSSS.S9SSSSS 45      nUS:X  a  [        U5      nU H  n[	        US   5      n[        USS[        145      =(       d    SnSn[
        R                  " S5       H  n	[        U R                  U R                   SU 3USU SU	 S3U[	        U5      [	        US-   5      SUS.S9SSSSS  45      n
U
(       d    M  U
 H-  n[	        US   5      nU R                  S!U 3[        U5      v   M/     US"-  nM     M     g 7f)#Nz!application/json, text/plain, */*zhttps://www.sonyliv.com)AcceptRefererz/1.4/A/ENG/WEB/ALL/GETTOKENzDownloading security tokenrv   r_   r   z/1.9/R/ENG/WEB/IN/DL/DETAIL/zDownloading series JSONfalse049)	kids_safefromto)rU   queryr   r   c                     [        US   5      $ Nr   r   _vs     r>   rG   *SonyLIVSeriesIE._entries.<locals>.<lambda>   s    +VWX\V]J^rA   r   r   r   r   r   r   z(/1.4/R/ENG/WEB/IN/CONTENT/DETAIL/BUNDLE/zDownloading z page z JSONc   r   )r   r   orderBy	sortOrderc                     [        US   5      $ r   r   r   s     r>   rG   r      s    R]^_`d^eRfrA   zsonyliv:d   )	rg   	_API_BASEr   reversedr6   	itertoolscount
url_resultr   )r8   show_id
sort_orderrU   seasonsr   	season_idrT   cursorpage_numepisodesepisoder   s                r>   _entriesSonyLIVSeriesIE._entries   s    90
 %)$7$7~~9:G(' %8 %;;F%H ! t22~~:7)Dg%w$?  3   lA|=^_a w'GFF4L)IWse(DEQDF%OOA.'(;(;~~&&NykZdV6(5ISZ #F!&2+.#2%/	c )< ) %lA|Efgi  'G"74=1H//HXJ*?HUU  ( # /	 s   EEc                    U R                  U5      nU R                  SU R                  S   /5      S   nX0R                  ;  a*  [        SU SSR	                  U R                  5       35      eU R                  U R                  X#5      US9$ )Nr   r   zInvalid sort order "z". Allowed values are: z, )playlist_id)r   _configuration_arg_SORT_ORDERS
ValueErrorr7   playlist_resultr   )r8   r   r   r   s       r>   r   SonyLIVSeriesIE._real_extract   s    ..%,,\D<M<Ma<P;QRSTU
...&zl2I$))TXTeTeJfIghj j ##DMM'$FT[#\\rA   r   N)r   r   r   r   r   r   r   r   r   r   r   r   rA   r>   r   r      sS    ]JA ,
 C ,
F 0I"L$L]rA   r   )rk   rj   r   rh   r4   r3   r0   r   commonr   networking.exceptionsr   utilsr   r   r	   r
   utils.traversalr   r   r   r   rA   r>   <module>r      sN           ! -  +c
 c
L@]m @]rA   