
    yf!#                         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 ddl	m
Z
mZmZmZmZmZmZmZmZ  G d d	e      Z G d
 de      Z G d de      Zy)    N   )InfoExtractor   )
compat_str)	HTTPError)	ExtractorErrorfloat_or_noneint_or_nonejwt_decode_hs256parse_age_limittraverse_objtry_calltry_getunified_strdatec                   <    e Zd ZdZdZdZdZdZdddZd	 Z	d
 Z
d Zy)
VootBaseIEvootFzkLog in with "-u <email_address> -p <password>", or use "-u token -p <auth_token>" to login with auth token.Nr   zhttps://www.voot.comzhttps://www.voot.com/)OriginRefererc                    | j                   r| j                  ry |j                         dk(  rAt        fd      r3t        _         t              d   t        _        | j                          y |j                         sB| j                  dd t        j                  d|dd      j                         i | j                  d	d
idd      }t        |dt        hf      s7t        |ddt        hf      dk(  r| j!                  dg       t#        dd      t        | j                  dd t        j                  dt%        t'        j(                               d|ddd      j                         i | j                  d	d
idd      ddt*        hf      }|st#        d d      |d!   t        _         |d"   t        _        y t#        | j,                  d      )#Ntokenc                      t               S )N)r   )passwords   7/usr/lib/python3/dist-packages/yt_dlp/extractor/voot.py<lambda>z+VootBaseIE._perform_login.<locals>.<lambda>!   s    <LX<V     expz.https://userauth.voot.com/usersV3/v3/checkUseremail)typer   ),:)
separatorsContent-Typeapplication/json;charset=utf-8zChecking usernamei  )dataheadersnoteexpected_statusisExiststatuscodei'  IN)	countrieszIncorrect usernameTexpectedz*https://userauth.voot.com/usersV3/v3/logintraditionalzPC/MAC)r   r   )r   deviceIddeviceBrandr%   z
Logging in  r%   	authTokenzIncorrect passwordaccessTokenexpirationTime)_TOKEN_EXPIRYlowerr   r   r   report_loginisdigit_download_jsonjsondumpsencode_API_HEADERSr   boolintraise_geo_restrictedr   struuiduuid4dict_LOGIN_HINT)selfusernamer   check_username
auth_tokens     `  r   _perform_loginzVootBaseIE._perform_login   s   ;;4<<>>w&84V+W (J!1(!;E!BJ !!#!00@$TZZ#%Y )N* +1&( =''="$D= ,S 1 BN  TF0CD6C50IJdR---?$%9DII%d&9&9<d) #DJJL 1#+!)$,	U )J* +1&( =''="$D= %c ': '; >D[SWRX<Y[J $%9DII *= 9J!+,<!=J !!1!1DAAr   c                 r    t        t        j                               | j                  k\  rt        dd      y )NzAccess token has expiredTr.   )rB   timer8   r   rI   s    r   _check_token_expiryzVootBaseIE._check_token_expiryI   s,    tyy{t||+ !;dKK ,r   c                 v    | j                   s| j                  | j                  d        | j                          y )N)method)r7   raise_login_requiredrH   rQ   rP   s    r   _real_initializezVootBaseIE._real_initializeM   s.    {{%%d&6&6t%D  "r   )__name__
__module____qualname___NETRC_MACHINE_GEO_BYPASSrH   r7   r8   r@   rM   rQ   rU    r   r   r   r      s8    NKKFG4AXYL*BXL#r   r   c                   b    e Zd ZdZdZ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gZd Zy)VootIEFa\  (?x)
                    (?:
                        voot:|
                        https?://(?:www\.)?voot\.com/?
                        (?:
                            movies?/[^/]+/|
                            (?:shows|kids)/(?:[^/]+/){4}
                        )
                     )
                    (?P<id>\d{3,})
                    zXhttps://www.voot.com/shows/ishq-ka-rang-safed/1/360558/is-this-the-end-of-kamini-/441353441353mp4zIs this the end of Kamini?z$md5:06291fbbbc4dcbe21235c40c262507c1iXW20160825zIshq Ka Rang Safedr   iT  zSeason 1   g     @)idexttitledescription	timestampupload_dateseriesseason_numberepisodeepisode_numberrelease_dateseason	age_limitdurationskip_downloadm3u8)url	info_dictparamszfhttps://www.voot.com/kids/characters/mighty-cat-masked-niyander-e-/400478/school-bag-disappears/440925T)rr   only_matchingz-https://www.voot.com/movies/pandavas-5/424627z,https://www.voot.com/movie/fight-club/621842c                    | j                  |      }| j                  d|d| ddd| j                  i      }	 | j                  d|dd	i | j                         | j                  d
d|| j                  d      d   }| j                  ||dd      }| j                  |       |t        |d       | j                  dt        |dddt        hfdt        hfdt        hfdt        hfdt        hfdt        hfdt        hfdt         hfdt"        hfdt$        hfd 
f      S # t
        $ rI}t        |j                  t              r)|j                  j                  dk(  r| j                           d }~ww xY w)!NzGhttps://psapi.voot.com/jio/voot/v1/voot-web/content/query/asset-detailszinclude:common)idsresponseTypeaccesstoken)queryr&   z8https://vootapi.media.jio.com/playback/v1/playbackrightszDownloading playback JSONs   {}r$   androidwebdesktop)r#   platformvootid	voottoken)r%   r&   rq   r3   r_   hls)m3u8_idc                 $    d|d   vxs |d   dk  S )Nz/_definst_/smil:vod/rr   heighti  r[   )_vs     r   r   z&VootIE._real_extract.<locals>.<lambda>   s    31U8CYq{VYGY r   )rb   formatshttp_headersresultr   	fullTitlefullSynopsisshowNamerm   rj   
uploadTimetelecastDate
ageNemonicro   )
rd   re   rh   ri   rj   rk   rf   rl   rn   ro   )	_match_idr<   r7   geo_verification_headersr@   r   
isinstancecauser   r*   rQ   _extract_m3u8_formats_remove_duplicate_formatsr   rD   r
   r   r   r	   )rI   rr   video_id
media_infom3u8_urler   s          r   _real_extractzVootIE._real_extract~   s   >>#&((UW_$XJ/JUbdhdodoTp ) r
	**JH+% B335B''B %E 3&!%B + 	 	H ,,XxPU,V&&w/ #GY\ --
 :!%u- .6%u-"*[M!:'#/#,{m"<*[M:!//1B C*_,=>'-96 ( 
 	
  	!''9-!''..C2G((*	s   AD! !	E3*AE..E3N)rV   rW   rX   _WORKING
_VALID_URL_TESTSr   r[   r   r   r]   r]   S   s    H
J j1A#%*3!& 
  #F+%( x ? >3F<+
r   r]   c                   H    e Zd 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)VootSeriesIEFz7https?://(?:www\.)?voot\.com/shows/[^/]+/(?P<id>\d{3,})z<https://www.voot.com/shows/chakravartin-ashoka-samrat/100002i  rb   100002)rr   playlist_mincountrs   z4https://www.voot.com/shows/ishq-ka-rang-safed/100003iU  100003zxhttps://psapi.voot.com/media/voot/v1/voot-web/content/generic/season-by-show?sort=season%3Aasc&id={}&responseType=commonzhttps://psapi.voot.com/media/voot/v1/voot-web/content/generic/series-wise-episode?sort=episode%3Aasc&id={}&responseType=common&page={:d}c              #   D  K   | j                  | j                  j                  |      |      }|j                  dg       D ]  }d}t	        |d t
              }| j                  | j                  j                  ||      |d|z        }|j                  dg       }|s]|dz  }|D ]>  }|j                  d      }	| j                  d|	z  t        j                         |		       @ | j                  | j                  j                  ||      |d|z        d   }|r y w)
N)r   r   r   c                     | d   S )Nrb   r[   )xs    r   r   z'VootSeriesIE._entries.<locals>.<lambda>   s
    !D' r   z!Downloading JSON metadata page %d)r   r'   rb   zvoot:%s)ier   )
r<   	_SHOW_APIformatgetr   r   _SEASON_API
url_resultr]   ie_key)
rI   show_id	show_jsonrm   page_num	season_idseason_jsonepisodes_jsonrj   r   s
             r   _entrieszVootSeriesIE._entries   sB    ''(=(=g(FQX'Y	mmHb1 	sFH(9:FI--d.>.>.E.EiQY.Z7@3VYa3a . cK (OOHb9MA, UG&{{40H//!H,8 * U UU !% 3 3D4D4D4K4KIW_4`=F9\_g9g !4 !iiq!s  	ss   BD A>D D c                 h    | j                  |      }| j                  | j                  |      |      S )N)playlist_id)r   playlist_resultr   )rI   rr   r   s      r   r   zVootSeriesIE._real_extract   s/    ..%##DMM'$:#PPr   N)
rV   rW   rX   r   r   r   r   r   r   r   r[   r   r   r   r      s\    HKJM (
 F (
F KI ]Ks&Qr   r   )r=   rO   rE   rw   r   compatr   networking.exceptionsr   utilsr   r	   r
   r   r   r   r   r   r   r   r]   r   r[   r   r   <module>r      sP       !  -
 
 
;# ;#|V
Z V
r(Q: (Qr   