
    VGhF                         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 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 G d de      Zy)    N   )InfoExtractor   )Request)ExtractorErrorOnDemandPagedListUserNotLivedetermine_extfilter_dictint_or_none
orderedSetparse_iso8601url_or_noneurlencode_postdataurljoin)traverse_objc                   .    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szActionz0https://login.sooplive.co.kr/app/LoginAction.phpz
Logging indatazMYour account has been suspended due to a violation of our terms and policies.z:https://member.sooplive.co.kr/app/user_delete_progress.phpz8https://login.sooplive.co.kr/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.z5https://member.sooplive.co.kr/app/pop_login_block.phpz5https://login.sooplive.co.kr/afreeca/second_login.phpz3https://member.sooplive.co.kr/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           c/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/yt_dlp/extractor/afreecatv.py_perform_loginzAfreecaTVBaseIE._perform_login   s    "&

 &&>1*= ' ?
 `LJ BGHFTUFP `P
  X\\(34Q;KK(DEE #DLL>@      Nc           
      P    | j                  t        d| |||ddi      |dd      S )Nzhttps://api.m.sooplive.co.kr/
legacy_sslT)r$   headersquery
extensionszDownloading API JSONzUnable to download API JSON)r-   r   )r0   endpoint
display_idr$   r=   r>   s         r8   	_call_apizAfreecaTVBaseIE._call_api?   sB    ""7+H:6we$d+$- /9"$A	C 	Cr:   c                 &    t        |       sy | ddgS )Njpg)urlextr   )	thumb_urls    r8   _fixup_thumbzAfreecaTVBaseIE._fixup_thumbF   s    9% "%011r:   )NNN)__name__
__module____qualname___NETRC_MACHINEr9   rB   staticmethodrI    r:   r8   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.co.krzdhttps?://vod\.(?:sooplive\.co\.kr|afreecatv\.com)/(?:PLAYER/STATION|player)/(?P<id>\d+)/?(?:$|[?#&])z*https://vod.sooplive.co.kr/player/9675336320230108_9FF5BEE1_244432674_1mp4
rlantnghksu   페이즈으iX*  z<re:https?://videoimg\.(?:sooplive\.co\.kr|afreecatv\.com)/.+20230108ie̺cu   젠지 페이즈)	idrF   uploader_iduploaderduration	thumbnailupload_date	timestamptitleskip_downloadT)rE   	info_dictparamsz1http://vod.sooplive.co.kr/PLAYER/STATION/20515605!20170411_BE689A0E_190960999_1_2_hu   혼자사는여자집zCre:https?://(?:video|st)img\.(?:sooplive\.co\.kr|afreecatv\.com)/.+u   ♥이슬이dasl812120170411i	X   )	rW   rF   r^   r[   rY   rX   r\   r]   rZ   z*https://vod.sooplive.co.kr/player/9726769020180327_27901457_202289533_1u   [생]빨개요♥ (part 1)u
   [SA]서아bjdyrksu20180327i  )rW   rF   r^   r[   rY   rX   r\   rZ   The VOD does not exist)rE   r`   ra   skipz*https://vod.sooplive.co.kr/player/70395877rE   only_matchingz+https://vod.sooplive.co.kr/player/104647403z*https://vod.sooplive.co.kr/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        d      hfd| j                  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        d      hfd*t        d+t        j                   d,-      .      hfd/              t        |d0t        hf      d1k(  r8|s| j#                  d2d34       | j%                  d5| j'                  d3              |s&t        |d6t        hf      r| j#                  d7d34       t)        |      dk(  ri |d8   d|j                  d      iS t        |d9d:;      |d<<    | j*                  ||fd=d
i|S )>Nzstation/video/a/viewReferer
   )nTitleNo	nApiLevel)r=   r$   r$   codeiri   Tr+   izThis VOD is privater^   writer_nickbj_idtotal_file_duration  scalethumb)r^   rY   rX   rZ   
thumbnailsfilesc                     t        |d         S )NfilerG   _vs     r8   <lambda>z+AfreecaTVIE._real_extract.<locals>.<lambda>   s    +ai:P r:   r   startr}   m3u8rT   hlszDownloading part z m3u8 information)m3u8_idnotehttp)rE   	format_idfile_info_keyr   Untitledz (part ))rW   r^   formatsrZ   
file_start 	   hours	delimitertimezone)rZ   r]   adult_statusnotLoginz5Only users older than 19 are able to watch this videor2   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   ).r]   F)get_allr]   multi_video)	_match_idrB   r   r   intr   strr   rI   	enumerater
   _extract_m3u8_formatsappendr.   r   dt	timedeltaraise_login_requiredreport_warning_login_hintlenplaylist_result)r0   rE   video_idr$   
error_codecommon_infoentriesfile_numfile_elementfile_urlr   s              r8   _real_extractzAfreecaTVIE._real_extract   s   >>#&~~"Hy#6F#$%   
  "$#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44hu,XJ6GH 5 J
 $!' 
 NN 		"&&7ShZq
;S'OOG4B
C78*TUV"		
 |!+k.E-F G".WYWcWcjkWl1m0n!o. 	 		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Wr:   N)rJ   rK   rL   r/   IE_DESC
_VALID_URL_TESTSr   rO   r:   r8   rQ   rQ   O   s    GGxJ;1'&X%#'

 T
$ C5,_&%%#

 T
& <11_$%%	
 T
 )!& < = <u>F@DXr:   rQ   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.co.kr catch storyzOhttps?://vod\.(?:sooplive\.co\.kr|afreecatv\.com)/player/(?P<id>\d+)/catchstoryz3https://vod.sooplive.co.kr/player/103247/catchstoryrW   103247r   rE   r`   playlist_countc                     | j                  |      }| j                  d|d|id|d      }| j                  | j                  |      |      S )Nzcatchstory/a/viewrn   r   )aStoryListIdx	nStoryIdx)r=   r>   )r   rB   r   _entries)r0   rE   r   r$   s       r8   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catchrO   r~   s     r8   r   z0AfreecaTVCatchStoryIE._entries.<locals>.<lambda>   s    <G!; r:   
catch_listc                     |d   d   d   S )Nr{   r   r}   rO   r~   s     r8   r   z0AfreecaTVCatchStoryIE._entries.<locals>.<lambda>   s    qz!}V'< r:   r{   r   r   r}   rZ   rv   rw   r^   rs   	writer_idry   write_timestamp)rW   rE   rZ   r^   rY   rX   rz   r]   )r   r   r   r   rI   )r0   r$   s     r8   r   zAfreecaTVCatchStoryIE._entries   s     ;<?SE:F[M:$ak6M5NO!C5)*SE2 +cU3&):):(;</+?	?'  	 	s   A*A4,A2-A4N)	rJ   rK   rL   r/   r   r   r   r   r   rO   r:   r8   r   r      s:    G*GcJD(
  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.co.kr livestreamszThttps?://play\.(?:sooplive\.co\.kr|afreecatv\.com)/(?P<id>[^/?#]+)(?:/(?P<bno>\d+))?z-https://play.sooplive.co.kr/pyh3646/237852185	237852185rT   u,   【 우루과이 오늘은 무슨일이? 】u   박진우[JINU]pyh3646iaT)rW   rF   r^   rY   rX   r]   is_livezLivestream has ended)rE   r`   rj   rk   z#https://play.sooplive.co.kr/pyh3646z7https://live.sooplive.co.kr/afreeca/player_live_api.php)gcp_cdngs_cdn_pc_appgs_cdn_mobile_webgs_cdn_pc_web)gs_cdngs_cdn_chromecast	azure_cdnaws_cf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.co.krCDNc                      |j                   vS )N)	_BAD_CDNS)r   r   r0   s     r8   r   z2AfreecaTVLiveIE._extract_formats.<locals>.<lambda>*  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)fatalr>   view_urlrT   r   aidrn   zhttps://play.sooplive.co.kr/)r   r>   r=   z. Retrying... (attempt z of r   )r.   r   r   r   all_WORKING_CDNS_configuration_argr   r-   r   r   r   r   r   r   causemsg)r0   channel_infobroadcast_nor   stream_base_urldefault_cdn_idscdn_idsattemptcdn_idm3u8_urles   `          r8   _extract_formatsz AfreecaTVLiveIE._extract_formats%  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&(FG 2 I I	^ " ^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 )1NrW   bnobidr#   CHANNELBJIDBNOr*   r   )r   r'   z.This channel is streaming for subscribers onlyr2   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_typetypequalitypwdAIDzThis livestream has endedz'This livestream is for subscribers onlyzUnable to extract access tokenz4https://st.sooplive.co.kr/api/get_station_status.phpzDownloading channel metadataz#Unable to download channel metadataszBjIdF)r>   r   TITLEstation_titleBJNICKstation_namebroad_startr   r   r   r   rn   )rW   r^   rY   rX   r]   r   r   http_headers)_match_valid_urlgroupr   r-   _LIVE_API_URLr   dictr.   r	   r   r   	get_paramr   r   r   r   r   )r0   rE   broadcaster_idr   r   r6   r2   
token_infor   r   station_infos              r8   r   zAfreecaTVLiveIE._real_extractA  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BL*,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)rJ   rK   rL   r/   r   r   r   r  r   r   r   r   rO   r:   r8   r   r      sz    G*GhJ>C)$#
 ' ? 5F( N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:userz^https?://ch\.(?:sooplive\.co\.kr|afreecatv\.com)/(?P<id>[^/?#]+)/vods/?(?P<slug_type>[^/?#]+)?z.https://ch.sooplive.co.kr/ryuryu24/vods/reviewplaylistryuryu24zryuryu24 - review)_typerW   r^      r   z3https://ch.sooplive.co.kr/parang1995/vods/highlight
parang1995zparang1995 - highlighti  z'https://ch.sooplive.co.kr/ryuryu24/vodszryuryu24 - all   z3https://ch.sooplive.co.kr/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://chapi.sooplive.co.kr/api/z/vods/reg_date)pageper_pageorderbyr   z video page )r>   r   r$   z"https://vod.sooplive.co.kr/player/title_no/)r-   	_PER_PAGE
url_resultrQ   )r0   user_id	user_typer  infoitems         r8   _fetch_pagezAfreecaTVUserIE._fetch_page  s     	""%FwivV_U`#acj26DNN_i)j*6ykdV(T # V L 	iD//4T*5E4FaH+W[\fWgi i	is   A#A%c                     | j                  |      j                  dd      \  }}|xs d}t        t        j                  | j
                  ||      | j                        }| j                  ||| d|       S )NrW   	slug_typer   z - )r  r  r   	functoolspartialr$  r  r   )r0   rE   r   r!  r   s        r8   r   zAfreecaTVUserIE._real_extract  sw    !2237==dKP&	#I$5$5d6F6FQZ$[]a]k]kl##GW	YK6PQQr:   N)	rJ   rK   rL   r/   r   r   r  r$  r   rO   r:   r8   r  r  }  s    GrJ?(

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

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

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

 1 FB IiRr:   r  )datetimer   r'  r   r   
networkingr   utilsr   r   r	   r
   r   r   r   r   r   r   r   utils.traversalr   r   rQ   r   r   r  rO   r:   r8   <module>r-     sr      !      +62m 62rHX/ HXV!O !H|
o |
~3Ro 3Rr:   