
    VGh)                         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Zddlm	Z	 ddl
mZ ddlmZmZmZmZ ddlmZ  G d d	e	      Z G d
 de	      Zy)    N   )InfoExtractor   )	HTTPError)ExtractorErrorint_or_nonejwt_decode_hs256try_call)traverse_objc                       e Zd ZdZ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gZdgZi ZdZdZd Z	d Z
d Zd Zd Zy) 	SonyLIVIEa  (?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                    t        t        j                         dz        }t        d      }t        |      D ]m  \  }}t        |dt	        j                         z  z   dz        dz  }t        j                  |dz        }|dk(  rt        |      ||<   [|dk(  sad|z  dz  d||<   o d	j                  |      d
z   t        t        t        j                         dz              z   S )N   xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx   r   xy       -)	inttimelist	enumeraterandommathfloorstrjoin)selfeticns         a/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/yt_dlp/extractor/sonyliv.py_get_device_idzSonyLIVIE._get_device_idC   s    		d"#34aL 	(DAqQfmmo--34q8A

1r6"ACx1v!ca%!)A!	( wwqzC#c$))+*<&=">>>    c                    | j                         | j                  d<   d| j                  d<   |j                         dk(  r.t        fd      r | j                  d<   | j	                          y t        |      dk7  s|j                         st        d| j                         | j	                          | j                  d	d d
| j                  t        j                  |ddt        j                  j                         j                  d      dddd      j!                               }|d   dk(  rt        |d   d      | j                  dd d| j                  t        j                  d|d| j#                  d      ddt        j                  j                         j                  d      dd      j!                               }|d   dk(  rt        |d   d      |d   d   | j                  d<   y )N	device_idzapplication/jsonzcontent-typetokenc                      t               S )N)r	   )passwords   r=   <lambda>z*SonyLIVIE._perform_login.<locals>.<lambda>S   s    <LX<V r?   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)rL   rK   rM   otpdmaIdageConfirmationr   rP   	resultObjaccessToken)r>   _HEADERSlowerr
   report_loginlenisdigitr   _LOGIN_HINT_download_jsonjsondumpsdtdatetimenowstrftimeencode_get_tfa_info)r7   usernamerD   otp_request_jsonotp_verify_jsons     `  r=   _perform_loginzSonyLIVIE._perform_loginO   s   %)%8%8%:k"(:n%>>w&84V+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&r?   c                    	 | j                  d| d| || j                        d   S # t        $ rB}t        |j                  t
              r~|j                  j                  dk(  re| j                  |j                  j                  j                         j                         |      d   dk(  r| j                  | j                  d        t        |j                  t
              r|j                  j                  d	k(  rq| j                  |j                  j                  j                         j                         |      d   }|d
k(  r| j                  | j                         t        |       d }~ww xY w)Nzhttps://apiv2.sonyliv.com/AGL/z/A/ENG/WEB/rR   r\   i  rV   z&Please subscribe to watch this content)methodi  zGeoblocked Country)	countries)rd   r^   r   
isinstancecauser   status_parse_jsonresponsereaddecoderaise_login_requiredrc   raise_geo_restricted_GEO_COUNTRIES)r7   versionpathvideo_idr8   rV   s         r=   	_call_apizSonyLIVIE._call_apiy   sR   	&&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   &) 
E5D=E00E5c                 D    | j                  ddd       | j                  d<   y )Nz1.4zALL/GETTOKENsecurity_token)r   r^   )r7   s    r=   _initialize_pre_loginzSonyLIVIE._initialize_pre_login   s    *...PT*U&'r?   c                    | j                  |      }| j                  dd|z   |      }| j                  d      s"|j                  d      r| j	                  |       |d   }ddt        j                         j                  t        j                         dz  fz  i}| j                  ||d	|d
      }|j                  | j                  |j                  dd      j                  dd      |dd|d
             |D ]#  }|j                  di       j                  |       % | j                  dd|z   |      d   d   d   }|d   }	i }
|j                  dg       D ]I  }|j                  d      }|s|
j                  |j                  dd      g       j                  d|i       K ||	||j                  d      |j                  d       xs |j                  d!      t!        |j                  d"      d      t!        |j                  d#            t!        |j                  d$            |j                  d%      t!        |j                  d&            t!        |j                  d'            |
d(S ))Nz1.5zIN/CONTENT/VIDEOURL/VOD/allow_unplayable_formatsisEncryptedvideoURLzx-playback-session-idz%s-%dr%   dashF)mpd_idrR   fatalz.mpdz.m3u8z/DASH/z/HLS/r   hls)m3u8_idrR   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hexr/   _extract_mpd_formatsextend_extract_m3u8_formatsreplace
setdefaultupdateappendr   )r7   r   r   contentdash_urlrR   r   fr   r   r   subsub_urls                r=   _real_extractzSonyLIVIE._real_extract   sf   >>#&..-8(D~~89gkk->XOOH%:&#W

0@0@$))+PTBT/U%U
 ++hvwe , 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(<="
 	
r?   N)__name__
__module____qualname__
_VALID_URL_TESTSr~   r^   rc   _NETRC_MACHINEr>   rp   r   r   r    r?   r=   r   r      s    J w+%A#) 
 T
& N C Z c Z=!FD VNH QKN
?(UT"V*
r?   r   c                   D    e Zd ZdZddddiddddd	idgZd
ZdZd Zd Zy)SonyLIVSeriesIEzIhttps?://(?: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              #     K   ddd}| j                  | j                   d|d|      d   |d<   t        | j                  | j                   d	| |d
|dddd      ddddd f      }|dk(  rt        |      }|D ]  }t	        |d         }t        |ddt        hf      xs d}d}t        j                  d      D ]  }	t        | j                  | j                   d| |d| d|	 d|t	        |      t	        |dz         d|d      ddddd  f      }
|
s |
D ],  }t	        |d         }| j                  d!| t        |       . |d"z  }  y w)#Nz!application/json, text/plain, */*zhttps://www.sonyliv.com)AcceptRefererz/1.4/A/ENG/WEB/ALL/GETTOKENzDownloading security tokenrr   r\   r   z/1.9/R/ENG/WEB/IN/DL/DETAIL/zDownloading series JSONfalse049)	kids_safefromto)rR   queryr   r   c                     t        |d         S Nr   r   _vs     r=   rE   z*SonyLIVSeriesIE._entries.<locals>.<lambda>   s    +VWX\V]J^ r?   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                     t        |d         S r   r   r   s     r=   rE   z*SonyLIVSeriesIE._entries.<locals>.<lambda>   s    R]^_`d^eRf r?   zsonyliv:d   )	rd   	_API_BASEr   reversedr5   	itertoolscount
url_resultr   )r7   show_id
sort_orderrR   seasonsr   	season_idrQ   cursorpage_numepisodesepisoder   s                r=   _entriesz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  ' VG"74=1H//HXJ*?HUUV #		s   EEc                     | j                  |      }| j                  d| j                  d   g      d   }|| j                  vr*t        d| ddj	                  | j                               | j                  | j                  ||      |      S )Nr   r   zInvalid sort order "z". Allowed values are: z, )playlist_id)r   _configuration_arg_SORT_ORDERS
ValueErrorr6   playlist_resultr   )r7   r   r   r   s       r=   r   zSonyLIVSeriesIE._real_extract   s    ..%,,\D<M<Ma<P;QRSTU
T...&zl2I$))TXTeTeJfIghj j ##DMM':$FT[#\\r?   N)	r   r   r   r   r   r   r   r   r   r   r?   r=   r   r      sS    ]JA ,
 C ,
F 0I"L$L]r?   r   )rh   rg   r   re   r3   r2   r/   r   commonr   networking.exceptionsr   utilsr   r   r	   r
   utils.traversalr   r   r   r   r?   r=   <module>r      sN           ! -  +c
 c
L@]m @]r?   