
    Ğir5                         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dS )    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dNS )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 }|                                  D ]A}|                    d          r|                                 ,|                    |           Bd                    |          S )Nz#https://redirector.googlevideo.com/
)
splitlines
startswithpopappendjoin)m3u8_docoutlines      ]C:\Users\betacode\Desktop\descargarYoutube\venv\Lib\site-packages\yt_dlp/extractor/tenplay.py_filter_ads_from_m3u8zTenPlayIE._filter_ads_from_m3u8u   sl    '')) 	 	DDEE 			JJtyy~~    c                      t           j                            t           j        j                                      d          } t          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   sL    [__R[_--66~FF		,,33555rP   c                 \    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                    	 |                      dd dddit          j        | j        | j        d                                                    }n# t          $ r}t          |j        t                    r}|j        j
        dk    rmd x| _        | _        | j                            | j        | j        d d g           |                     d            | j        |                                   Y d }~d S  d }~ww xY w|d	         | _        |d
         | _        | j                            | j        | j        | j        | j        g           d S )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   sm   	..5t=V"$6
#'#5$($7$ $   688 /  LL  	 	 	!'9-- !'.C2G2G;??#d&8
  !4d6KdTX\ZZZ##$cddd##T%9%9%;%;<<	 *-8*>:
,d.CdFY[_[mEnooooos   AA 
C7BC21C22C7c                    | j         s6| j                            | j        | j        d d g          \  | _         | _        | j         r| j        r|                     d           d S 	 |                     dd dd|                                 ddt          j
        ||d                                          	          }nN# t          $ rA}t          |j        t                    r!|j        j        d
k    rt          dd           d }~ww xY w|d         d         | _         |d         d         | _        | j                            | j        | j        | j         | j        g           d S )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   " 	R6:joo#T%:T4L 7F 7R 7R3D!3 	4#5 	9:::F	++14$6*.*P*P*R*R3  
% ($ $   688 , 	 	II  	 	 	!'9-- Q!'.C2G2G$%@4PPPP	
 (.~>&u-m<
,d.CdFY[_[mEnooooos   $AB< <
D<DDc                 J   | j         r.|                     | j                   r|                                  dD ]}	 |                     d| d|dddit	          d| j         r
d| j          nd d	          
          c S # t
          $ r}|st          |j        t                    rv|j        j	        dk    rf| j         r.| 
                    d           |                                  Y d }~|                                 d         s|                     dd            d }~ww xY wd S )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"6t7I"J"J 	)&&(((% 	 	H11M
MMMz1*i9P',:KOK])g)G43E)G)G)Gcg) )   2      "    lJqw	$B$B lqw~Y\G\G\) l'MNNN22444 !1133A6 l112W`j1kkk	 	s   A A>>
D AD)2DD c                    |                      |          }	 |                     d| |          }n# t          $ r}}t          |j        t
                    r]|j        j        dk    rMd|j        j                                        	                                v r| 
                    | j                    d }~ww xY w|                     |          \  }}|d         d         }|d         d         }|                    d          }	|	st          d	          |                     d
| d| d|dt          d|	i                    }
|                     |
d         |d          \  }}d}|D ]U}|                     |d         |d          }|                     |          }||d<   |                    d          dk    rd}V|s|rt'          j        | j        |          rot'          j        | j        d|          }t'          j        dd|          }|                    dt1          |                                d          |dddd dd!           ||t5          |                    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 )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((
	&&'V*'V'VXbccDD 	 	 	17I..I347>S3H3H!QW%5%:%:%<%<%C%C%E%EEE))D4G)HHH	  22:>>
D&u-.?@e$Y/__\22
 	A !?@@@&&oEVoo]eooo3#\:$>?? ' A A ==&'U< <
 # 	* 	*C--E
J-K . M MH11(;;H-5C)*wwx  D((%)" " 	h 	29T=UW_3`3` 	vd68I8TTHv=?OQYZZHNN4&x'8'8:QRR+3)#'	 	 	 	 	 BMdhhWcNdNdBeBeo$%l);!< =>>ko$*
 
 4&'+7$se,%u- -u5.1C0DE#cU+"*[M!:#,{m"<)K=9(;-8" "  
 	
s   1 
B8A8B33B8)__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      sR       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 \6 B B \Bp p p,p p p8  ,G
 G
 G
 G
 G
rP   r   c                   P    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dS )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 ]a}|                     ||d|id|           }|d         }|                    d |D                        |D ]}|d         V  |d         s d S bd S )	Nr   z	skipIds[]zFetching episodes page )r   r   itemsc              3   &   K   | ]}|d          V  dS )r   Nr   ).0eps     rN   	<genexpr>z+TenPlaySeasonIE._entries.<locals>.<genexpr>9  s&      >>BtH>>>>>>rP   cardLinkhasMore)	itertoolscountrl   extend)r{   load_more_url
display_idskip_idspageepisodes_carouselepisodes_chunkr   s           rN   _entrieszTenPlaySeasonIE._entries1  s      OA&& 	 	D $ 3 3z+x1H5t55 !4 !7 !7 /w7NOO>>~>>>>>>$ % %n$$$$$Y/ 	 	rP   c                    |                      |                              dd          \  }}|                     d| d| | d|           }t          |dddd	 d
t          hfffd          pi }|d         }|                     |                     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                                          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177IIf))C4CC6CCEWEWvEWEWY Y )q,==tf)7 	   % #%	 	 (/))MM'#'8'GHH+VVkIq'C53QR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     sD             				  ! ! ! ! ! ! - - - - - -	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 + * * * * *A
 A
 A
 A
 A
 A
 A
 A
H5! 5! 5! 5! 5!m 5! 5! 5! 5! 5!rP   