
    ukir5                         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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encode_data_urifilter_dictint_or_nonejwt_decode_hs256url_or_noneurlencode_postdataurljoin)traverse_objc                      e Zd 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diddi ddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,dd-d
d.d/d0d1d2dd3d	ddidd4i dd5ddd2dd3d	d d6dd7dd8dd9d-d:d*d;d(d<d$d=d.d>d,dd0d?d&d@d"dAddidBgdCdDdEdFdGgZdHZdIgZd:d
d
d
d
dJdJdKZ	dLZ
dMZdNZdNZedO        ZedP        ZedQ        ZdR ZdS ZdT ZdU ZyN)V	TenPlayIE10playzMhttps?://(?:www\.)?10(?:play)?\.com\.au/(?:[^/?#]+/)+(?P<id>tpv\d{6}[a-z]{5})zjhttps://10.com.au/australian-survivor/web-extras/season-10-brains-v-brawn-ii/myless-journey/tpv250414jdmtf7440980000013868mp4zMyles's JourneyzKRelive Myles's epic Brains V Brawn II journey to reach the game's final two
Channel 102199827728001      zre:https://.+/.+\.jpgzAustralian Survivorz	Season 10
   ig20250414)idexttitle	alt_titledescriptionuploaderuploader_id	age_limitduration	thumbnailseriesseasonseason_number	timestampupload_dateskip_downloadm3u8)url	info_dictparamszKhttps://10.com.au/neighbours/episodes/season-42/episode-9107/tpv240902nzqypr   9000000000091177r   r   zNeighbours - S42 Ep. 9107r   z
Thu 05 Sepr   z$md5:37a1f4271be34b9ee2b533426a5fbaefr#   il  episodezEpisode 9107episode_numberi#  r&   z	Season 42r'   *   r%   
Neighboursr$   r"   r(   i$Pfr)   20240905r    r!   zKhttps://10.com.au/tiny-chef-show/episodes/season-1/episode-2/tpv240228pofvt9000000000084116i  zThe Tiny Chef Show - S1 Ep. 2zS1 Ep. 2 - Popcorn/bananaz$md5:d4758b52b5375dfaa67a78261dcb5763r   zThe Tiny Chef Showr   r   i/h20250522zSeason 1z	Episode 2z3Failed to download m3u8 information: HTTP Error 502zvideo unavailable)r,   r-   r.   expected_warningsskipzohttps://10play.com.au/how-to-stay-married/web-extras/season-1/terrys-talks-ep-1-embracing-change/tpv190915ylupcTr,   only_matchingFAU   )GPGMMAzMA15+RX
token_dataz3(?m)-(?:300|150|75|55)0000-(\d+(?:-[\da-f]+)?)\.ts$Nc                     g }| j                         D ]5  }|j                  d      r|j                          %|j                  |       7 dj	                  |      S )Nz#https://redirector.googlevideo.com/
)
splitlines
startswithpopappendjoin)m3u8_docoutlines      S/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/yt_dlp/extractor/tenplay.py_filter_ads_from_m3u8zTenPlayIE._filter_ads_from_m3u8u   sT    '') 	DDE	JJt		 yy~    c                      t         j                  j                  t         j                  j                        j                  d      } t        j                  | j                               j                         S )Nz%Y%m%d%H%M%S)
dtdatetimenowtimezoneutcstrftimebase64	b64encodeencodedecode)tss    rN   !_generate_xnetwork_ten_auth_tokenz+TenPlayIE._generate_xnetwork_ten_auth_token   sG    [[__R[[__-66~F		,3355rP   c                 N    t        |       d   t        j                         z
  dk  S )Nexpi,  )r   time)tokens    rN   _is_jwt_expiredzTenPlayIE._is_jwt_expired   s"    &u-		;cAArP   c                    	 | j                  dd dddit        j                  | j                  | j                  d      j                               }|d	   | _        |d
   | _        | j                  j                  | j                  | j                  | j                  | j                  g       y # t        $ r}t        |j                  t              r|j                  j                  dk(  rtd x| _        | _        | j                  j                  | j                  | j                  d d g       | j                  d        | j                   | j#                           Y d }~y  d }~ww xY w)Nz#https://10.com.au/api/token/refreshzRefreshing access tokenContent-Typeapplication/json)accessTokenrefreshTokenheadersdata  z=Refresh token has been invalidated; retrying with credentialsrf   rg   )_download_jsonjsondumps_access_token_refresh_tokenrZ   r   
isinstancecauser   statuscachestore_NETRC_MACHINE_TOKEN_CACHE_KEYreport_warning_perform_login_get_login_info)selfrefresh_dataes      rN   _refresh_access_tokenzTenPlayIE._refresh_access_token   s?   	..5t=V"$6

#'#5#5$($7$7$  68 / L  *-8*>:

,,d.C.CdFYFY[_[m[mEno  	!''9-!''..C2G;??#d&8

  !4!4d6K6KdTX\Z##$cd###T%9%9%;<	s   AB. .	E$7B"EEE$c                    | j                   sA| j                  j                  | j                  | j                  d d g      \  | _         | _        | j                   r| j
                  r| j                  d       y 	 | j                  dd dd| j                         ddt        j                  ||d      j                         	      }|d   d   | _         |d   d   | _        | j                  j#                  | j                  | j                  | j                   | j
                  g       y # t        $ rF}t        |j                  t              r&|j                  j                   d
k(  rt        dd       d }~ww xY w)N)defaultzUsing cached refresh tokenzhttps://10.com.au/api/user/authz
Logging inre   zhttps://10.com.au/)rd   zX-Network-Ten-AuthReferer)emailpasswordrh   rk   zInvalid username/passwordT)expectedjwtrg   rf   )rp   rt   loadrv   rw   ro   write_debugrl   r]   rm   rn   rZ   r   rq   rr   r   rs   ru   )r{   usernamer   	auth_datar}   s        rN   ry   zTenPlayIE._perform_login   s]   ""6:jjoo##T%:%:T4L 7F 7R3D!34#5#59:	++14$6*.*P*P*R3 

% ($  68 , 	I (.~>&u-m<

,,d.C.CdFYFY[_[m[mEno  	!''9-!''..C2G$%@4PP	s   9AD' '	E60AE11E6c                 H   | j                   r+| j                  | j                         r| j                          dD ]G  }	 | j                  d| d|dddit	        d| j                   rd| j                    nd d	      
      c S  y # t
        $ r}|st        |j                  t              rq|j                  j                  dk(  rX| j                   r&| j                  d       | j                          Y d }~| j                         d   s| j                  dd        d }~ww xY w)N)FTz)https://10.com.au/api/v1/videos/playback//zDownloading video JSONplatformsamsungzv1/fw;v1/drmzBearer )zTP-AcceptFeatureAuthorization)notequeryri     z$Access token has expired; refreshingr   z#Login required to access this videor   )method)ro   rb   r~   _download_json_handler	   r   rq   rr   r   rs   	to_screenrz   raise_login_required)r{   
content_idis_retryr}   s       rN   _call_playback_apizTenPlayIE._call_playback_api   s   $"6"6t7I7I"J&&(% 	H11?
|1Mz1*i9P',:KOK]K]743E3E2F)Gcg)  2  	 " Jqww	$Bqww~~Y\G\))'MN224 !113A6112W`j1ks   AB	D!A"D5'DD!c                 v   | j                  |      }	 | j                  d| |      }| j                  |      \  }}|d   d   }|d   d   }|j                  d      }	|	st        d	      | j                  d
| d| d|dt        d|	i            }
| j                  |
d   |d      \  }}d}|D ]F  }| j!                  |d   |d      }| j#                  |      }||d<   |j%                  d      dk(  sEd}H |srt'        j(                  | j*                  |      rjt'        j,                  | j*                  d|      }t'        j,                  dd|      }|j/                  dt1        |j3                         d      |dddd dd!       ||t5        |j%                  d"            r
d#d|d"   igind d$d%d&t7        |d't8        hfd(t:        hfd)t8        hfd*t8        hfd+t8        hfd,| j<                  j$                  hfd-t8        hfd.t:        hfd/t:        hfd0t:        hfd1t4        hfd2      S # t        $ r}t        |j                  t
              ri|j                  j                  dk(  rPd|j                  j                  j                         j                         v r| j                  | j                          d }~ww xY w)3Nz https://10.com.au/api/v1/videos/r   zError 54113)	countriesdaicontentSourceIdvideoIdz
x-dai-authzFailed to get DAI auth tokenz6https://pubads.g.doubleclick.net/ondemand/hls/content/z/vid/z/streamszDownloading DAI JSONz
auth-token)r   rj   stream_manifestr   Fr,   zDownloading m3u8 information)r   hls_media_playlist_dataheighti8  Tz-5000000-\1.tsz-(?:300|150|75|55)0000\.key"z-5000000.key"zupgrade-attempt-1080pzapplication/x-mpegurli  m3u8_native)	format_idr,   r   widthr   r   protocol__needs_testing
captionUrlenr   r   )r   formats	subtitlesr    r!   altIdr#   subtitler   r   classificationtvShowr&   r0   	publishedimageUrl)r   r#   r   r   r   r"   r%   r'   r1   r(   r$   )	_match_idrl   r   rq   rr   r   rs   responsereadr[   raise_geo_restricted_GEO_COUNTRIESr   
get_headerr   #_extract_m3u8_formats_and_subtitles_download_webpagerO   getresearch_SEGMENT_BITRATE_REsubrI   r   rZ   r   r   strr
   	_AUS_AGES)r{   r,   r   rj   r}   
video_dataurlhcontent_source_idvideo_id
auth_tokendai_datar   _already_have_1080pfmtrK   s                   rN   _real_extractzTenPlayIE._real_extract   s   ^^C(
	&&)I*'VXbcD  22:>
D&u-.?@e$Y/__\2
 !?@@&&DEVDWW\]e\ffno3#\:$>? ' A ==&'U<
 # 	*C--E
J-K . MH11(;H-5C)*wwx D(%)"	* "h299T=U=UW_3`vvd668I8THvv=?OQYZHNN4&x'8:QR+3)#'	 	 BMdhhWcNdBe$%l);!< =>ko$*
 4&'+7$se,%u- -u5.1C1C0DE#cU+"*[M!:#,{m"<)K=9(;-8" 
 	
a  	177I.177>>S3H!QWW%5%5%:%:%<%C%C%EE))D4G4G)H	s   H& &	J8/BJ33J8)__name__
__module____qualname__IE_NAME
_VALID_URLrv   _TESTS_GEO_BYPASSr   r   rw   r   rp   ro   staticmethodrO   r]   rb   r~   ry   r   r    rP   rN   r   r      s   GaJN |$'+j$*1+!#%
" #F+). ]
$
5
 0
 	

 A
 
 ~
 d
 k
 R
 l
 1
 
 
 :
  !
" ?#
& #F+-2 ]
$
5
 
 ?	

 
 4
 4
 A
 
 *
 Q
 a
 
 1
 :
  j!
" {#
& #F+ST#14 AKHFR KVNI $PNM  6 6 B Bp,p8,G
rP   r   c                   N    e Zd ZdZdZddddddd	d
dddddddgZddZd Zy)TenPlaySeasonIEz10play:seasonzbhttps?://(?:www\.)?10(?:play)?\.com\.au/(?P<show>[^/?#]+)/episodes/(?P<season>[^/?#]+)/?(?:$|[?#])z/https://10.com.au/masterchef/episodes/season-15z	Season 15zMTQ2NjMxOQ==)r   r   2   )r,   r-   playlist_mincountzNhttps://10.com.au/the-bold-and-the-beautiful-fast-tracked/episodes/season-2024zSeason 2024Mjc0OTIw   zRhttps://10play.com.au/the-bold-and-the-beautiful-fast-tracked/episodes/season-2024Tr9   Nc              #      K   g }t        j                  d      D ]N  }| j                  ||d|id|       }|d   }|j                  d |D               |D ]	  }|d     |d   rN y  y w)	Nr   z	skipIds[]zFetching episodes page )r   r   itemsc              3   &   K   | ]	  }|d      yw)r   Nr   ).0eps     rN   	<genexpr>z+TenPlaySeasonIE._entries.<locals>.<genexpr>9  s     >BtH>s   cardLinkhasMore)	itertoolscountrl   extend)r{   load_more_url
display_idskip_idspageepisodes_carouselepisodes_chunkr   s           rN   _entrieszTenPlaySeasonIE._entries1  s     OOA& 	D $ 3 3z+x1H.tf5 !4 !7 /w7NOO>~>>$ %n$%$Y/	s   A%A,(A,c                 j   | j                  |      j                  dd      \  }}| j                  d| d| | d|       }t        |dddd	 d
t        hfffd      xs i }|d   }| j                  | j                  t        ||d         |      |t        |dddt        hf      t        |            S )Nshowr&   zhttps://10.com.au/api/shows/z
/episodes/r   contentr   
componentsc                 .    |d   j                         dk(  S )Nr   episodes)lower)r   vs     rN   <lambda>z/TenPlaySeasonIE._real_extract.<locals>.<lambda>G  s    QwZ--/:= rP   .F)get_alltpIdloadMoreUrlr   )getter)	_match_valid_urlgrouprl   r   dictplaylist_from_matchesr   r   r   )r{   r,   r   r&   season_infor   playlist_ids          rN   r   zTenPlaySeasonIE._real_extract@  s    ,,S177If))*4&
6(CvQvhEWY )q,=tf)7 	 % #%	 	 (/))MM'#'8'GH+VkIq'C53QR3< * ! 	!rP   )N)r   r   r   r   r   r   r   r   r   rP   rN   r   r     s^    GvJ@  
   `"
 ! dF&!rP   r   )rX   rS   rR   r   rm   r   r`   commonr   networking.exceptionsr   utilsr   r   r	   r
   r   r   r   r   utils.traversalr   r   r   r   rP   rN   <module>r     sL        	  ! -	 	 	 +A
 A
H5!m 5!rP   