
    Ği)                         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dS )    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dS ) 	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 ]t\  }}t          |dt	          j                    z  z   dz            dz  }t          j        |dz            }|dk    rt          |          ||<   a|dk    rd|z  dz  d||<   ud	                    |          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         ]C:\Users\betacode\Desktop\descargarYoutube\venv\Lib\site-packages\yt_dlp/extractor/sonyliv.py_get_device_idzSonyLIVIE._get_device_idC   s    	d"##344aLL 	( 	(DAqQfmoo--344q8A
1r6""ACxx1vv!ca%!)''!wwqzzC#c$)++*<&=&=">">>>    c                 T   |                                  | j        d<   d| j        d<   |                                dk    r2t          fd          r | j        d<   |                                  d S t          |          dk    s|                                st          d| j                   |                                  | 	                    d	d d
| j        t          j        |ddt          j                                                            d          dddd                                                    }|d         dk    rt          |d         d          | 	                    dd d| j        t          j        d|d|                     d          ddt          j                                                            d          dd                                                    }|d         dk    rt          |d         d          |d         d         | j        d<   d S )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<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   sB   %)%8%8%:%:k"(:n%>>w&&84V4V4V4V+W+W&-5DM/*F]]b  (8(8(:(:  !Qt?O!Q!QRRR..L}dm$* ($,[__..778OPP/%)N N C C vxx / 
 
 L)T11 !1)!<tLLLL--MDJ$, ())%00#'[__..778OPP%)	P 	P 	E 	E vxx .   <(D00 !1)!<tLLLL)8)Em)To&&&r?   c                    	 |                      d| d| || j                  d         S # t          $ r>}t          |j        t
                    rz|j        j        dk    rj|                     |j        j        	                                
                                |          d         dk    r|                     | j        d            t          |j        t
                    r|j        j        d	k    rz|                     |j        j        	                                
                                |          d         }|d
k    r|                     | 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   s   	&&KKKTKK$- ' 1 11<> >  
	 
	 
	!'9-- I!'.C2G2GDL\L\G$))++2244hM@ M@@IMKNvMw Mw))$*:4)HHH!'9-- .!'.C2G2G**G$))++2244h@ @@IK222--8K-LLL$W---
	s   (+ E4D9E//E4c                 D    |                      ddd           | j        d<   d S )Nz1.4zALL/GETTOKENsecurity_token)r   r^   )r7   s    r=   _initialize_pre_loginzSonyLIVIE._initialize_pre_login   s&    *...PT*U*U&'''r?   c                    |                      |          }|                     dd|z   |          }|                     d          s*|                    d          r|                     |           |d         }ddt          j                    j        t          j                    dz  fz  i}| 	                    ||d	|d
          }|
                    |                     |                    dd                              dd          |dd|d
                     |D ]+}|                    di                               |           ,|                     dd|z   |          d         d         d         }|d         }	i }
|                    dg           D ]Y}|                    d          }|s|
                    |                    dd          g                               d|i           Z||	||                    d          |                    d           p|                    d!          t!          |                    d"          d          t!          |                    d#                    t!          |                    d$                    |                    d%          t!          |                    d&                    t!          |                    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   s   >>#&&..-8(D D~~899 	&gkk->X>X 	&OOH%%%:&#W
0@$)++PTBT/U%U
 ++hvwe , M Mt11VW--55hHHeUG5 2 J J 	K 	K 	K  	= 	=ALL,,33G<<<<>><(*H6 66BDDEGGQS(	;;z2.. 	 	Cggm,,G   )?!G!GLLSSwU      [11#<<(9::^hllK]>^>^$X\\.%A%A4HH#HLL$<$<==(h)?)?@@ll7++)(,,*G*GHH'V(<(<=="
 
 	
r?   N)__name__
__module____qualname__
_VALID_URL_TESTSr~   r^   rc   _NETRC_MACHINEr>   rp   r   r   r    r?   r=   r   r      s6       J w+%A#) 
 
 T
 & N  C  Z  c  Z =!FD VNH QKN
? 
? 
?(U (U (UT  "V V V*
 *
 *
 *
 *
r?   r   c                   F    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dS )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         d|d|          d         |d<   t          |                      | 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          pd}d}t          j        d          D ]}	t          |                      | j         d| |d| d|	 d|t	          |          t	          |dz             d|d          ddddd  f          }
|
s nA|
D ]8}t	          |d                   }|                     d!| t          |          V  9|d"z  }d S )#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^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^eRfRf 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~:::G(' %8 %; %;;F%H ! t22~DD7DDg%w$? ?  3     lA|=^=^_a a w''G 	 	FF4L))IWse(DEEQDF%OA..  '(;(;~ZZyZZIdII(IIISZ #F!&2+..#2%/	c c )< ) ) %lA|EfEfgi i   E' V VG"74=11H//*?X*?*?HUUUUUU#%	 	r?   c                 >   |                      |          }|                     d| j        d         g          d         }|| j        vr-t          d| dd                    | 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<Ma<P;QRRSTU
T...hzhh$))TXTeJfJfhhj j j ##DMM':$F$FT[#\\\r?   N)	r   r   r   r   r   r   r   r   r   r   r?   r=   r   r      s        ]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      s9                ! ! ! ! ! ! - - - - - -            + * * * * *c
 c
 c
 c
 c
 c
 c
 c
L@] @] @] @] @]m @] @] @] @] @]r?   