o
    i                     @   s   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
 ddlmZmZmZ G dd	 d	eZG d
d deZG dd deZG dd deZG dd deZdS )    N   )InfoExtractor   )	HTTPError)ExtractorError
clean_htmlextract_attributesparse_durationparse_qs)find_elementfind_elementstraverse_objc                   @   s|   e Zd 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eddddddddddedddddddgZdd  Z	d!S )"
VrSquareIEvrsquarez	VR SQUAREhttps://livr.jpz)https?://livr\.jp/contents/(?P<id>[\w-]+)z#https://livr.jp/contents/P470896661
P470896661mp4u~   そこ曲がったら、櫻坂？ ７年間お疲れ様！菅井友香の卒業を祝う会！前半 2022年11月6日放送分z$md5:523726dc835aa8014dfe1e2b38d36cd1g     @zcount:2z+re:https?://media\.livr\.jp/vod/img/.+\.jpg)idexttitledescriptiondurationtags	thumbnail)url	info_dictz#https://livr.jp/contents/P589523973
P589523973u%   薄闇に仰ぐ しだれ桜の妖艶z$md5:a042f517b2cbb4ed6746707afec4d306g     @z
Paid video)r   r   skipz#https://livr.jp/contents/P316939908
P316939908u[   2024年5月16日（木） 「今日は誰に恋をする？」公演 小栗有以 生誕祭z$md5:2110bdcf947f28bd7d06ec420e51b619g    @z Premium channel subscribers onlyz#https://livr.jp/contents/P126481458T)r   only_matchingc              
   C   s  |  |}| ||}| j| j d| |ddd}t|ddkr&| d z| | j d| |}W n tyS } zt|jt	rN|jj
d	krNtd
dd d }~ww || ddg|| d|| jt|dddtf|ddd| d|dt|tddhthftddhdthfdS )Nz/webApi/contentsStatus/zChecking contents statusF)fatalresult_code40407zUnable to access this videoz/webApi/play/url/i  z+VR SQUARE app-only videos are not supportedT)expectedog:titleztwitter:titler   urls.r   r   zog:image)r   r   r   formatsr   zlayout-product-data-time)clsz
search-tag)r   r   )	_match_id_download_webpage_download_json	_BASE_URLr   raise_login_requiredr   
isinstancecauser   status_html_search_meta_extract_m3u8_formatsanyr   r	   r   r   )selfr   video_idwebpager/   web_apie r8   M/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/vrsquare.py_real_extractB   sB   



zVrSquareIE._real_extractN)
__name__
__module____qualname__IE_NAMEIE_DESCr+   
_VALID_URLlist_TESTSr:   r8   r8   r8   r9   r      sT    		)r   c                   @   s$   e Zd ZdZdddZd	ddZdS )
VrSquarePlaylistBaseIEr   r8   c                 c   sb    t |g |tdddhdthdthtR D ]}| | j d|d tV  qd S )NvideoT)r'   html.zdata-urlz
/contents/)	r   r   r   strfilter
url_resultr+   removeprefixr   )r3   sourcekeysurl_pathr8   r8   r9   _fetch_vidsd   s(   z"VrSquarePlaylistBaseIE._fetch_vidsNc                 c   sn    t dD ].}| j| j | |d| d|i|pi d}| |dE d H  t|dthtfs4 d S qd S )Nr   zDownloading playlist JSON page p)query)contents_render_list.)has_nexthasNext)	itertoolscountr*   r+   rM   r   boolr2   )r3   path
display_idrO   pageajaxr8   r8   r9   _entriesl   s   zVrSquarePlaylistBaseIE._entries)r8   )N)r;   r<   r=   r+   rM   rZ   r8   r8   r8   r9   rC   a   s    
rC   c                   @   s0   e Zd ZdZdZddddddgZd	d
 ZdS )VrSquareChannelIEzvrsquare:channelz%https?://livr\.jp/channel/(?P<id>\w+)z"https://livr.jp/channel/H372648599
H372648599u   AKB48＋チャンネルr   r   i  r   r   playlist_mincountc                 C   s:   |  |}| ||}| | d| ||| d|S )Nz/ajax/channel/r$   )r(   r)   playlist_resultrZ   r0   r3   r   playlist_idr5   r8   r8   r9   r:      s   
zVrSquareChannelIE._real_extractNr;   r<   r=   r>   r@   rB   r:   r8   r8   r8   r9   r[   w   s    	r[   c                   @   s.   e Zd ZdZdZdddiddgZdd	 Zd
S )VrSquareSearchIEzvrsquare:searchz2https?://livr\.jp/web-search/?\?(?:[^#]+&)?w=[^#]+zDhttps://livr.jp/web-search?w=%23%E5%B0%8F%E6%A0%97%E6%9C%89%E4%BB%A5r   u   #小栗有以<   r^   c                 C   s*   t |d d }| | d|d|i|S )Nwr   z/ajax/web-search)r
   r`   rZ   )r3   r   search_queryr8   r8   r9   r:      s   zVrSquareSearchIE._real_extractNrc   r8   r8   r8   r9   rd      s    rd   c                   @   s@   e Zd ZdZdZddddddd	d
ddddgZdd ZdS )VrSquareSectionIEzvrsquare:sectionz3https?://livr\.jp/(?:category|headline)/(?P<id>\w+)z#https://livr.jp/category/C133936275
C133936275u#   そこ曲がったら、櫻坂？VRr]   i4  r^   z#https://livr.jp/headline/A296449604
A296449604u   AKB48 アフターVR   c                 C   s2   |  |}| ||}| | ||| d|S )Nr$   )r(   r)   r`   rM   r0   ra   r8   r8   r9   r:      s
   
zVrSquareSectionIE._real_extractNrc   r8   r8   r8   r9   rh      s"    rh   )rS   commonr   networking.exceptionsr   utilsr   r   r   r	   r
   utils.traversalr   r   r   r   rC   r[   rd   rh   r8   r8   r8   r9   <module>   s    N