
    }jM                         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mZmZmZmZ ddlmZmZ d Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    N   )InfoExtractor   )Request)ExtractorErrorOnDemandPagedListUserNotLivedetermine_extfilter_dictint_or_none
orderedSetparse_iso8601str_or_noneurl_or_noneurlencode_postdataurljoin)requiretraverse_objc                 B    t        dd|ddt        d||| d            S )Nz.https://live.sooplive.com/api/private_auth.phpPOSTzhttps://vod.sooplive.com)RefererOriginvod)typestrm_idtitle_nourl)methodheadersdata)r   r   )m3u8_urlr   video_idreferer_urls       M/root/.hermes/venv/lib/python3.12/site-packages/yt_dlp/extractor/afreecatv.py_cloudfront_auth_requestr%      s;    8"0
   	!
      c                   .    e Zd ZdZd ZddZed        Zy)AfreecaTVBaseIE	afreecatvc                    dd||dddd}| j                  dd dt        |      	      }d
ddddddddddddd}t        |j                  d            }|dk7  r/|j                  |d      }t	        d| j
                   d| d      y )Nloginjsonfalse	oLoginRet )szWorkszTypeszUid
szPasswordisSaveIdszScriptVarszActionz.https://login.sooplive.com/app/LoginAction.phpz
Logging inr    zMYour account has been suspended due to a violation of our terms and policies.z8https://member.sooplive.com/app/user_delete_progress.phpz6https://login.sooplive.com/membership/changeMember.phpzHello! Soop here.
The username you have entered belongs to 
 an account that requires a legal guardian's consent. 
If you wish to use our services without restriction, 
please make sure to go through the necessary verification process.z3https://member.sooplive.com/app/pop_login_block.phpz3https://login.sooplive.com/afreeca/second_login.phpz1https://member.sooplive.com/app/user_security.phpzCThe username does not exist or you have entered the wrong password.z4You have entered your username/password incorrectly.z>You cannot use your Global Soop account to access Korean Soop.zSorry for the inconvenience. 
Your account has been blocked due to an unauthorized access. 
Please contact our Help Center for assistance.z:You have failed to log in. Please contact our Help Center.)iiiir   iiiRESULTr   zYou have failed to log in.zUnable to login: z said: Texpected)_download_jsonr   r   getr   IE_NAME)selfusernamepassword
login_formresponse_ERRORSresulterrors           r$   _perform_loginzAfreecaTVBaseIE._perform_login+   s    "&

 &&<d1*= ' ?
 `JH BEFDTUFP `P
  X\\(34Q;KK(DEE #DLL>@  r&   Nc           
      P    | j                  t        d| |||ddi      |dd      S )Nzhttps://api.m.sooplive.com/
legacy_sslT)r    r   query
extensionszDownloading API JSONzUnable to download API JSON)r@   r   )rC   endpoint
display_idr    r   rN   s         r$   	_call_apizAfreecaTVBaseIE._call_apiQ   sB    ""7)(4we$d+$- /9"$A	C 	Cr&   c                 &    t        |       sy | ddgS )Njpg)r   extr   )	thumb_urls    r$   _fixup_thumbzAfreecaTVBaseIE._fixup_thumbX   s    9% "%011r&   )NNN)__name__
__module____qualname___NETRC_MACHINErK   rR   staticmethodrX    r&   r$   r(   r(   (   s'     N$LC 2 2r&   r(   c                       e Zd ZdZdZdZ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i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(gZd+ Zy,)-AfreecaTVIEsoopzsooplive.comzNhttps?://vod\.sooplive\.com/(?:PLAYER/STATION|player)/(?P<id>\d+)/?(?:$|[?#&])z)https://vod.sooplive.com/player/19280532520260414_1B44E53B_293230967_1mp4
rlantnghksu   페이즈으iu*  z&re:https?://videoimg\.sooplive\.com/.+20260414iGizT1 Peyz [CC])	idrU   uploader_iduploaderduration	thumbnailupload_date	timestamptitleskip_downloadT)r   	info_dictparamsz0https://vod.sooplive.com/PLAYER/STATION/20515605BE689A0E_190960999_1_2_Au   혼자사는여자집zQre:https?://(?:video|st)img\.(?:sooplive\.co\.kr|sooplive\.com|afreecatv\.com)/.+u   ♥이슬이dasl812120170411iyX   )	rf   rU   rm   rj   rh   rg   rk   rl   ri   z)https://vod.sooplive.com/player/19161261320260403_A4534670_292914441_1u   하이z-re:https?://(?:video|st)img\.sooplive\.com/.+u	   세림잉serimm20260402ig  )rf   rU   rm   rj   rh   rg   rk   ri   zNeeds login to view)r   ro   rp   skipz(https://vod.sooplive.com/player/70395877r   only_matchingz)https://vod.sooplive.com/player/104647403z(https://vod.sooplive.com/player/81669846c                    | j                  |      }| j                  d|d|it        |dd            d   }d}d }t        |dt        hf      }|rt        |d	t        ht        d
      hf      }t        |dt        hf      }|dk(  rt        dd      |dk(  rt        dd      t        |dt        hfdt        hfd	t        hfdt        d      hfd| j                  hfd      }g }	t        t        |dd f      d      D ]  \  }
}|d   }t        |      dk(  ri|r4| j                  t        ||||      |dd        t        j                         }| j                  ||d!d"d#|
 d$%      }|r|D ]  }d&|d'<   ||||d(|d)<    n|d*d+g}|	j!                  i ||j#                  d,      xs | d-|
 |j#                  d      xs d. d/|
 d0|d1t        |d2t        d      hfd3t%        d4t'        j(                  d56      7      hfd8              t        |d9t        hf      d:k(  r8|	s| j+                  d;d<=       | j-                  d>| j/                  d<              |	s&t        |dt        hf      r| j+                  d?d<=       t1        |	      dk(  ri |	d   d|j#                  d      iS t        |	d@dAB      |dC<    | j2                  |	|fdDdi|S )ENzstation/video/a/viewr   
   )nTitleNo	nApiLevel)r   r    r    r   sub_upload_typebj_idz	stream IDcodeizThe VOD does not existTr>   izThis VOD is privaterm   writer_nicktotal_file_duration  scalethumb)rm   rh   rg   ri   
thumbnailsfilesc                     t        |d         S )NfilerV   _vs     r$   <lambda>z+AfreecaTVIE._real_extract.<locals>.<lambda>   s    +ai:P r&   r   startr   m3u8zRequesting CloudFront cookiesz Failed to get CloudFront cookiesrc   hlszDownloading part z m3u8 information)m3u8_idnotesoopvodprotocol)r!   r   r"   _last_refresh_cookie_refresh_paramshttp)r   	format_idfile_info_keyr   Untitledz (part ))rf   rm   formatsri   
file_start 	   hours	delimitertimezone)ri   rl   adult_statusnotLoginz5Only users older than 19 are able to watch this videorE   r   zIn accordance with local laws and regulations, underage users are restricted from watching adult content. Only content suitable for all ages will be downloaded. z This VOD is for subscribers only).rl   F)get_allrl   multi_video)	_match_idrR   r   r   strr   intr   r   rX   	enumerater
   _request_webpager%   time_extract_m3u8_formatsappendrA   r   dt	timedeltaraise_login_requiredreport_warning_login_hintlenplaylist_result)rC   r   r"   r    initial_refresh_timer   needs_private_auth
error_codecommon_infoentriesfile_numfile_elementfile_urlr   fmts                  r$   _real_extractzAfreecaTVIE._real_extract   s   >>#&~~"Hy#6F#$%   
   !)$1BSE0JK"4'C57;;O:P)QRG!$#8
 !9DII5  !6FF"4u%&.#cU+.41H0IJ"T%6%6$78*
  &/TG-P#QRZ['] $	"Hl#F+HX&&0%))07HcR "ACeg ,099;(44hu,XJ6GH 5 J && *3J(0'.(0-A	945 $!' 
 NN 		"&&7ShZq
;S'OOG4B
C78*TUV"		
 |!+k.E-F G".WYWcWcjkWl1m0n!o. 	 	7$	L ~u56*D))KT^ * `,,0,<,<Z,H+IKL
 </@3%.HI%%&HQ[%\w<1!*1 
 $09KUZ#[K #t##GXW4W;WWr&   N)rY   rZ   r[   rB   IE_DESC
_VALID_URL_TESTSr   r^   r&   r$   r`   r`   a   s    GGbJ:1'&B%##

 T
$ B,,m&%%#

 T
& ;1I##%	
 T
 &!& : ; :u>F@YXr&   r`   c                   6    e Zd ZdZdZdZdddiddgZd	 Zd
 Zy)AfreecaTVCatchStoryIEzsoop:catchstoryzsooplive.com catch storyz9https?://vod\.sooplive\.com/player/(?P<id>\d+)/catchstoryz1https://vod.sooplive.com/player/103247/catchstoryrf   103247r   )r   ro   playlist_countc                     | j                  |      }| j                  d|d|id|d      }| j                  | j                  |      |      S )Nzcatchstory/a/viewr   r/   )aStoryListIdx	nStoryIdx)r   rN   )r   rR   r   _entries)rC   r   r"   r    s       r$   r   z#AfreecaTVCatchStoryIE._real_extract  sV    >>#&~~Is3C$&X>  @ ##DMM$$7BBr&   c              #      K   t        |dd dd dddt        hfdddt        hfddd	t        d
      hfdt        hfdt        hfdt        hfd| j                  hfdt        hfdf      E d {    y 7 w)Nr    c                     |d   dk(  S )N
story_typecatchr^   r   s     r$   r   z0AfreecaTVCatchStoryIE._entries.<locals>.<lambda>  s    <G!; r&   
catch_listc                     |d   d   d   S )Nr   r   r   r^   r   s     r$   r   z0AfreecaTVCatchStoryIE._entries.<locals>.<lambda>  s    qz!}V'< r&   r   r   r   r   ri   r   r   rm   r   	writer_idr   write_timestamp)rf   r   ri   rm   rh   rg   r   rl   )r   r   r   r   rX   )rC   r    s     r$   r   zAfreecaTVCatchStoryIE._entries  s     ;<?SE:F[M:$ak6M5NO!C5)*SE2 +cU3&):):(;</+?	?'  	 	s   A*A4,A2-A4N)	rY   rZ   r[   rB   r   r   r   r   r   r^   r&   r$   r   r     s:    G(GMJB(
  FCr&   r   c            	       f    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gZdZg dZg dZ	d Z
d Zy)AfreecaTVLiveIEz	soop:livezsooplive.com livestreamsz>https?://play\.sooplive\.com/(?P<id>[^/?#]+)(?:/(?P<bno>\d+))?z+https://play.sooplive.com/pyh3646/237852185	237852185rc   u,   【 우루과이 오늘은 무슨일이? 】u   박진우[JINU]pyh3646iaT)rf   rU   rm   rh   rg   rl   is_livezLivestream has ended)r   ro   rx   ry   z!https://play.sooplive.com/pyh3646z5https://live.sooplive.com/afreeca/player_live_api.php)gcp_cdngs_cdn_mobile_webgs_cdn_pc_weblg_cdn_pc_weblg_cdn_mobile_web	azure_cdnaws_cf)gs_cdngs_cdn_chromecastlg_cdn_chromecastgs_cdn_pc_appkt_cdnc                 ^    |j                  d      xs d}t        g t        |dt        ht         fdf       j
                        } j                  d|      }t        |d      D ]b  \  }}t         j                  t        |d      |d	| d
d| d
d|| dd      dt        hf      }		  j                  |	|ddd|iddi      c S  y # t        $ rT}
|t        |      k(  r  j                  |
j                  xs |
j                    d| dt        |       d       Y d }
~
d }
~
ww xY w)NRMDz'https://livestream-manager.sooplive.comCDNc                      |j                   vS )N)	_BAD_CDNS)r   r   rC   s     r$   r   z2AfreecaTVLiveIE._extract_formats.<locals>.<lambda>T  s    RVR`R`I` r&   cdnr   r   zbroad_stream_assign.htmlDownloading z stream infozUnable to download Fz-common-master-hls)return_type	broad_key)fatalrN   view_urlrc   r   aidr   zhttps://play.sooplive.com/)r   rN   r   z. Retrying... (attempt z of r   )rA   r   r   r   all_WORKING_CDNS_configuration_argr   r@   r   r   r   r   r   r   causemsg)rC   channel_infobroadcast_nor   stream_base_urldefault_cdn_idscdn_idsattemptcdn_idr!   es   `          r$   _extract_formatsz AfreecaTVLiveIE._extract_formatsO  s   &**51^5^ % &
,s<`(ab&
&
  ))%A(: 	^OGV#D$7$7)CDlvhl37J6(R^5_#)$0>1C!D$ %8 %  +/1H^11lE5PS&(DE 2 G G	^ " ^c'l*##ww'!%%((?ySQX\NZ[\^ ^^s   0C	D,A
D''D,c                    | j                  |      j                  dd      \  }}t        | j                  | j                  |t        d|i            dt        hf      xs i }|j                  d      xs |}|j                  d      xs |}|sE|j                  d      }|d	k(  rt        |
      |dk(  r| j                  dd       t        d      | j                  d      }|j                  d      dk(  r|t        dd      t        | j                  | j                  |ddt        t        |ddd|d                  dt        hf      xs i }|j                  d      }|sF|j                  d      }|d	k(  rt        dd      |dk(  r| j                  dd       t        d      | j                  |||      }	t        | j                  d |d!d"d#|id$%      t        h      xs i }
||j                  d&      xs |
j                  d'      |j                  d(      xs |
j                  d)      |t        |
j                  d*      d+t        j                   d,-      .      |	dd/|id0S )1Nrf   bnobidr7   CHANNELBJIDBNOr=   r   )r"   r:   z.This channel is streaming for subscribers onlyrE   r   z"Unable to extract broadcast numbervideopasswordBPWDYzKThis livestream is protected by a password, use the --video-password optionTr>   z#Downloading access token for streamz*Unable to download access token for streamcommonr   master)r  stream_typer   qualitypwdAIDzThis livestream has endedz'This livestream is for subscribers onlyzUnable to extract access tokenz2https://st.sooplive.com/api/get_station_status.phpzDownloading channel metadataz#Unable to download channel metadataszBjIdF)rN   r   TITLEstation_titleBJNICKstation_namebroad_startr   r   r   r   r   )rf   rm   rh   rg   rl   r   r   http_headers)_match_valid_urlgroupr   r@   _LIVE_API_URLr   dictrA   r	   r   r   	get_paramr   r  r   r   r   )rC   r   broadcaster_idr   r   rI   rE   
token_infor   r   station_infos              r$   r   zAfreecaTVLiveIE._real_extractk  s   '+'<'<S'A'G'Ge'T$#D$7$75GP^H_5` %8 %b! '$& 	 &))&1C^#''.>,!%%h/F{!>::2))DZ * Y !EFF>>/2F#s*x/? ]  "$"5"5.S8?QR]#'#_ S @ #6 # tf%' - +- 	 nnU#^^H-F{$%@4PP2))*S\f)g !ABB''lCH#D$7$7@,*,Q^,E %8 %; >BFD J HJ 	 !%%g.S,2B2B?2S$((2Vl6F6F~6V)&|'7'7'FRU`b`l`lst`uv&,	
 		
r&   N)rY   rZ   r[   rB   r   r   r   r  r   r   r  r   r^   r&   r$   r   r   %  sz    G(GRJ<C)$#
 ' = 3F( LMMI^89
r&   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dddddd	ddddddd	gZdZd Zd Zy)AfreecaTVUserIEz	soop:userzUhttps?://(?:www\.)?sooplive\.com/station/(?P<id>[^/?#]+)/vod/?(?P<slug_type>[^/?#]+)?z5https://www.sooplive.com/station/devil0108/vod/reviewplaylist	devil0108zdevil0108 - review)_typerf   rm   i,  )r   ro   playlist_mincountz.https://www.sooplive.com/station/devil0108/vodzdevil0108 - allz4https://www.sooplive.com/station/parang1995/vod/clip
parang1995zparang1995 - clipz4https://www.sooplive.com/station/phonics1/vod/normalphonics1zphonics1 - normal<   c           	   #      K   |dz  }| j                  d| d| ||| j                  ddd| d|       }|d	   D ]>  }| j                  d
|d    dt        t	        |d         |j                  d             @ y w)Nr   zhttps://chapi.sooplive.com/api/z/vods/reg_date)pageper_pageorderbyr   z video page )rN   r   r    z https://vod.sooplive.com/player/r   /
title_name)r@   	_PER_PAGE
url_resultr`   r   rA   )rC   user_id	user_typer-  infoitems         r$   _fetch_pagezAfreecaTVUserIE._fetch_page  s     	""%DWIVT]S^#_ah26DNN_i)j*6ykdV(T # V L 	TD//24
3C2DAF[j)9:DHH\<RT T	Ts   A<A>c                     | j                  |      j                  dd      \  }}|xs d}t        t        j                  | j
                  ||      | j                        }| j                  ||| d|       S )Nrf   	slug_typer   z - )r  r  r   	functoolspartialr8  r2  r   )rC   r   r4  r5  r   s        r$   r   zAfreecaTVUserIE._real_extract  sw    !2237==dKP&	#I$5$5d6F6FQZ$[]a]k]kl##GW	YK6PQQr&   N)	rY   rZ   r[   rB   r   r   r2  r8  r   r^   r&   r$   r#  r#    s    GiJF)

 ! @&

 ! F(

 ! F(

 !1 FB ITRr&   r#  )datetimer   r;  r   r  r   
networkingr   utilsr   r   r	   r
   r   r   r   r   r   r   r   r   utils.traversalr   r   r%   r(   r`   r   r   r#  r^   r&   r$   <module>rA     sz       !      4 62m 62r]X/ ]X@!O !H
o 
D4Ro 4Rr&   