
    yf=                         d dl 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 ddlmZ  G d de      Z G d	 d
e      Z G d de      Z G d de      Zy)    N   )InfoExtractor   )	ExtractorErrorOnDemandPagedListUserNotLivedetermine_extfilter_dictint_or_noneunified_timestampurl_or_noneurlencode_postdata)traverse_objc                       e Zd ZdZ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.afreecatv.com/app/LoginAction.phpz
Logging indatazMYour account has been suspended due to a violation of our terms and policies.z9https://member.afreecatv.com/app/user_delete_progress.phpz7https://login.afreecatv.com/membership/changeMember.phpzHello! AfreecaTV 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.z4https://member.afreecatv.com/app/pop_login_block.phpz4https://login.afreecatv.com/afreeca/second_login.phpz2https://member.afreecatv.com/app/user_security.phpzCThe username does not exist or you have entered the wrong password.z4You have entered your username/password incorrectly.zHYou cannot use your Global AfreecaTV account to access Korean AfreecaTV.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.)iiiiir   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           </usr/lib/python3/dist-packages/yt_dlp/extractor/afreecatv.py_perform_loginzAfreecaTVBaseIE._perform_login   s    "&

 &&=t1*= ' ?
 `KI GFGETUFZ `P
  X\\(34Q;KK(DEE 26,,F      N)__name__
__module____qualname___NETRC_MACHINEr5    r6   r4   r   r      s     N$r6   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ddd	d
d
ddddddddddddddddg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&id0d1d2d&d3d4d5dd6d7d8d9d:d;d<d=	d%d&id'd>d&d3d?d&d3d@d&d3g	ZdA ZyB)CAfreecaTVIEr   zafreecatv.coma  (?x)
                    https?://
                        (?:
                            (?:(?:live|afbbs|www)\.)?afreeca(?:tv)?\.com(?::\d+)?
                            (?:
                                /app/(?:index|read_ucc_bbs)\.cgi|
                                /player/[Pp]layer\.(?:swf|html)
                            )\?.*?\bnTitleNo=|
                            vod\.afreecatv\.com/(PLAYER/STATION|player)/
                        )
                        (?P<id>\d+)
                    zhttp://live.afreecatv.com:8079/app/index.cgi?szType=read_ucc_bbs&szBjId=dailyapril&nStationNo=16711924&nBbsNo=18605867&nTitleNo=36164052&szSkin= f72c89fe7ecc14c1b5ce506c4996046e36164052mp4u.   데일리 에이프릴 요정들의 시상식!z.re:^https?://(?:video|st)img.afreecatv.com/.*$
dailyapril20160503)idexttitle	thumbnailuploaderuploader_idupload_datezVideo is gone)urlmd5	info_dictskipz|http://afbbs.afreecatv.com:8080/app/read_ucc_bbs.cgi?nStationNo=16711924&nTitleNo=36153164&szBjId=dailyapril&nBbsNo=1860586736153164u5   BJ유트루와 함께하는 '팅커벨 메이크업!')rC   rE   rF   rG   rH   r    d8b7c174568da61d774ef0203159bf97
36153164_120160502)rC   rD   rE   rI   )rK   rL    58f2ce7f6044e34439ab2d50612ab02b
36153164_2)rJ   rL   playlist_countplaylistrM   z0http://vod.afreecatv.com/PLAYER/STATION/20515605!20170411_BE689A0E_190960999_1_2_hu   혼자사는여자집u   ♥이슬이dasl812120170411i	X   )	rC   rD   rE   rF   rG   rH   rI   	timestampdurationskip_downloadT)rJ   rL   paramsz)https://vod.afreecatv.com/player/9726769020180327_27901457_202289533_1u   [생]빨개요♥ (part 1)u
   [SA]서아bjdyrksu20180327i  )rC   rD   rE   rF   rG   rH   rI   r[   The VOD does not exist)rJ   rL   r]   rM   zxhttp://www.afreecatv.com/player/Player.swf?szType=szBjId=djleegoon&nStationNo=11273158&nBbsNo=13161095&nTitleNo=36327652rJ   only_matchingz)https://vod.afreecatv.com/player/9675336320230108_9FF5BEE1_244432674_1
rlantnghksu   페이즈으iX*  z're:https?://videoimg\.afreecatv\.com/.+20230108iJcu   젠지 페이즈)	rC   rD   rH   rG   r[   rF   rI   rZ   rE   z)https://vod.afreecatv.com/player/70395877z*https://vod.afreecatv.com/player/104647403z)https://vod.afreecatv.com/player/81669846c                    | j                  |      }| j                  d|d|it        |dd            d   }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        j                  t        d      hfdt        hfd      }g }t        t        |dd f      d      D ]  \  }}|d   }	t        |	      dk(  r| j                  |	|ddd| d       }
n|	d!d"g}
|j                  i ||j                  d#      xs | d$| |j                  d      xs d% d&| d'|
d(t        |d)t        j                  t        d      hfd*t         hfd+              t        |d,t        hf      d-k(  r8|s| j#                  d.d/0       | j%                  d1| j'                  d/              |s&t        |d2t        hf      r| j#                  d3d/0       t)        |      dk(  ri |d4   d|j                  d      iS t        |d5d67      |d8<    | j*                  ||fd9d
i|S ):Nz0https://api.m.afreecatv.com/station/video/a/viewReferer
   )nTitleNo	nApiLevel)headersr!   r!   codeira   Tr'   izThis VOD is privaterE   writer_nickbj_idtotal_file_durationi  )scalethumb)rE   rG   rH   r[   rF   filesc                     t        |d         S )Nfile)r   )_vs     r4   <lambda>z+AfreecaTVIE._real_extract.<locals>.<lambda>   s    +ai:P r6   r   )startru   m3u8r@   hlszDownloading part z m3u8 information)m3u8_idnotehttp)rJ   	format_idfile_info_keyrv   Untitledz (part ))rC   rE   formatsr[   
file_start)r[   rZ   adult_statusnotLoginz5Only users older than 19 are able to watch this videor.   )methodzIn accordance with local laws and regulations, underage users are restricted from watching adult content. Only content suitable for all ages will be downloaded. sub_upload_typez This VOD is for subscribers onlyr   ).rZ   F)get_allrZ   multi_video)	_match_idr)   r   r   intr   str	functoolspartialr   r   	enumerater	   _extract_m3u8_formatsappendr*   r   raise_login_requiredreport_warning_login_hintlenplaylist_result)r,   rJ   video_idr!   
error_codecommon_infoentriesfile_numfile_elementfile_urlr   s              r4   _real_extractzAfreecaTVIE._real_extract   s   >>#&"">$+=$? , # 
  "$#8
 !9DII5  !6FF"4u%&.#cU+.1B1B;VZ1[0\]!K=1*
  &/TG-P#QRZ['] 	"Hl#F+HX&&044hu,XJ6GH 5 J
 $!' 
 NN 		"&&7ShZq
;S'OOG4B
C78*TUV"		
 |!+i.?.?SW.X-Y Z".1B0C!D. 	 		0 ~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Wr6   N)r7   r8   r9   r+   IE_DESC
_VALID_URL_TESTSr   r;   r6   r4   r=   r=   <   s   GGJ b1EI$'%
   NLI$'
 5"P)	
 6"P)	
"  7< B5,I&%%#

 T
& ;11I$%%	
 T
 )!$ J ;1'&C%#'

 T
$ ; < ;MjFXDXr6   r=   c            	       P    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d Zy)AfreecaTVLiveIEzafreecatv:livezafreecatv.com livestreamszBhttps?://play\.afreeca(?:tv)?\.com/(?P<id>[^/]+)(?:/(?P<bno>\d+))?z,https://play.afreecatv.com/pyh3646/237852185	237852185r@   u,   【 우루과이 오늘은 무슨일이? 】u   박진우[JINU]pyh3646iaT)rC   rD   rE   rG   rH   rZ   is_livezLivestream has ended)rJ   rL   rM   rb   z"https://play.afreecatv.com/pyh3646z6https://live.afreecatv.com/afreeca/player_live_api.phpc                    | 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 |}|st        |      | j                  d	      }|j                  d
      dk(  r|t        dd      | j                  | j                  |ddt        t        |ddd|d                  d   d   }|j                  d      xs d}| j                  | d|d| dddd      }| j                  |d   |d d!d|id"|i#      }	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d"|id/S )0NrC   bnobidr    CHANNELBJIDBNO)r   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commonaidmaster)r   stream_typetypequalitypwdAIDRMDz(https://livestream-manager.afreecatv.comz/broad_stream_assign.htmlgs_cdn_pc_appz-common-master-hls)return_type	broad_keyzDownloading metadata for streamz&Unable to download metadata for stream)queryr}   errnoteview_urlr@   r{   rh   )r|   r   rl   z3https://st.afreecatv.com/api/get_station_status.phpzDownloading channel metadataz#Unable to download channel metadataszBjIdF)r   fatalTITLEstation_titleBJNICKstation_namebroad_start)rC   rE   rG   rH   rZ   r   r   http_headers)_match_valid_urlgroupr   r)   _LIVE_API_URLr   dictr*   r   	get_paramr   r
   r   r   )r,   rJ   broadcaster_idbroadcast_nochannel_infor.   r   stream_base_urlstream_infor   station_infos              r4   r   zAfreecaTVLiveIE._real_extract  s   '+'<'<S'A'G'Ge'T$#D$7$75GP^H_5` %8 %b! '$& 	 &))&1C^#''.>,~66>>/2F#s*x/? ]  !!.S8?QR]#'#_ S @ "   "# '**51_5_))_,==V*WYe*(>);<n
 2;c	 * e ,,
#\5%#,C(8 - : $D$7$7A<*,Q^,E %8 %; >BFD J HJ 	 !%%g.S,2B2B?2S$((2Vl6F6F~6V)*<+;+;M+JK&,	
 		
r6   N)	r7   r8   r9   r+   r   r   r   r   r   r;   r6   r4   r   r      sf    G)GVJ=C)$#
 ' > 4F( MM4
r6   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afreecatv:userzJhttps?://bj\.afreeca(?:tv)?\.com/(?P<id>[^/]+)/vods/?(?P<slug_type>[^/]+)?z-https://bj.afreecatv.com/ryuryu24/vods/reviewrU   ryuryu24zryuryu24 - review)_typerC   rE      )rJ   rL   rT   z2https://bj.afreecatv.com/parang1995/vods/highlight
parang1995zparang1995 - highlighti  z&https://bj.afreecatv.com/ryuryu24/vodszryuryu24 - all   z2https://bj.afreecatv.com/ryuryu24/vods/balloonclipzryuryu24 - balloonclipr   <   c           	   #      K   |dz  }| j                  d| d| ||| j                  ddd| d|       }|d	   D ]%  }| j                  d
|d    dt        |d          ' y w)Nr   z https://bjapi.afreecatv.com/api/z/vods/reg_date)pageper_pageorderbyzDownloading z video page )r   r}   r!   z!https://vod.afreecatv.com/player/title_no/)r)   	_PER_PAGE
url_resultr=   )r,   user_id	user_typer   infoitems         r4   _fetch_pagezAfreecaTVUserIE._fetch_pageu  s     	""%EgYfU^T_#`bi26DNN_i)j*6ykdV(T # V L 	hD//3D4D3EQGVZ[eVfh h	hs   A#A%c                     | j                  |      j                  dd      \  }}|xs d}t        t        j                  | j
                  ||      | j                        }| j                  ||| d|       S )NrC   	slug_typeallz - )r   r   r   r   r   r   r   r   )r,   rJ   r   r   r   s        r4   r   zAfreecaTVUserIE._real_extract~  sw    !2237==dKP&	#I$5$5d6F6FQZ$[]a]k]kl##GW	YK6PQQr6   N)	r7   r8   r9   r+   r   r   r   r   r   r;   r6   r4   r   r   O  s    G^J>(

  D-

  8%

  D-

 1 FB IhRr6   r   )r   r   r   utilsr   r   r   r	   r
   r   r   r   r   utils.traversalr   r   r=   r   r   r;   r6   r4   <module>r      sZ     !
 
 
 +'m 'TX/ XDN
o N
b3Rm 3Rr6   