U
    g                     @   sh   d dl mZ ddlmZmZmZmZmZ ddlm	Z	 G dd deZ
G dd de
ZG d	d
 d
e
ZdS )   )InfoExtractor   )ExtractorError
clean_htmlmerge_dictsparse_iso8601url_or_none)traverse_objc                   @   s   e Zd ZddiZdd ZdS )AsobiChannelBaseIEzX-MICROCMS-API-KEYZ$qRaKehul9AHU8KtL0dnq1OCLKnFec6yrbcz3c                 C   sT   t |dthfdthfdthfdddthfdthfdthfd	d
thfd	dthfdS )NidtitlebodycontentsZvideo_thumburlZpublishedAtZ	updatedAtchannelname)r   r   description	thumbnail	timestampmodified_timestampr   
channel_id)r	   strr   r   r   )selfmetadata r   A/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/asobichannel.py_extract_info   s    

z AsobiChannelBaseIE._extract_infoN)__name__
__module____qualname___MICROCMS_HEADERr   r   r   r   r   r
      s   r
   c                   @   s   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gZdZdd  Zd!d" Z	d#d$ Z
d%d& ZdS )'AsobiChannelIEZasobichannelASOBI CHANNELz:https?://asobichannel\.asobistore\.jp/watch/(?P<id>[\w-]+)z4https://asobichannel.asobistore.jp/watch/1ypp48qd32pZ 39df74e872afe032c4eb27b89144fc92Z1ypp48qd32pZmp4uP   アイドルマスター ミリオンライブ！ 765プロch 原っぱ通信 #1z$md5:b930bd2199c9b2fd75951ce4aaa7efd2zhttps://images.microcms-assets.io/assets/d2420de4b9194e11beb164f99edb1f95/a8e6f84119f54eb9ab4ce16729239905/%E3%82%B5%E3%83%A0%E3%83%8D%20(1).pngi'eZ20231012ij=;eZ20231027u   アイドルマスターZ
idolmaster)r   extr   r   r   r   upload_dater   modified_dater   r   )r   md5	info_dictz5https://asobichannel.asobistore.jp/watch/redigiwnjzqjZ 229fa8fb5c591c75ce8c37a497f113f6Zredigiwnjzqjue   【おまけ放送】アイドルマスター ミリオンライブ！ 765プロch 原っぱ通信 #1z$md5:7d9cd35fb54425a6967822bd564ea2d9zhttps://images.microcms-assets.io/assets/d2420de4b9194e11beb164f99edb1f95/20e5c1d6184242eebc2512a5dec59bf0/P1_%E5%8E%9F%E3%81%A3%E3%81%B1%E3%82%B5%E3%83%A0%E3%83%8D.pngiT2eZ20231020i(*eZ20231014)r   r#   r   r   r   r   r%   r   r$   r   r   Nc                 C   s$   | j dd dd}dd| i| _d S )Nz8https://asobichannel-api.asobistore.jp/api/v1/vspf/tokenzRetrieving API token)noteAuthorizationzBearer )_download_json_survapi_header)r   tokenr   r   r   _real_initializeE   s     zAsobiChannelIE._real_initializec                 C   s@   |d d }| j d| d|| jdd}d| |d d	 |iS )
Nr   video_idz0https://survapi.channel.or.jp/proxy/v1/contents/z/get_by_cuidzDownloading vod dataheadersr(   formatsZ
ex_contentZstreaming_url)r*   r+   _extract_m3u8_formats)r   r.   r   
content_idZvod_datar   r   r   _process_vodK   s    
   zAsobiChannelIE._process_vodc                 C   s   |d d }| j d| d|| jdd}t|ddthf}|d	krZ| jd
dd d}g }n2|dkrd}| j|d d d |dd}ntdt|ddthf||dS )Nr   r.   z(https://survapi.channel.or.jp/ex/events/z?embed=channelzDownloading event datar/   dataZPlayer_typeZposterzLive event has not yet startedT)expectedZis_upcomingZplayerZis_liveZChannelZCustom_live_url)Zlivez'Unsupported player type {player_type!r}Zperiodstart)Zrelease_timestamplive_statusr1   )r*   r+   r	   r   Zraise_no_formatsr2   r   r   )r   r.   r   r3   Z
event_dataZplayer_typer8   r1   r   r   r   _process_liveV   s0    
    zAsobiChannelIE._process_livec                 C   s   |  |}| jd| || jd}| |}t|dddthf}|dkrZt|| ||S |dkrtt|| ||S t	d|d S )	Nz)https://channel.microcms.io/api/v1/media/r0   r   
video_type    ZVODZLIVEzUnexpected video type )
	_match_idr*   r    r   r	   r   r   r4   r9   r   )r   r   r.   r   infor;   r   r   r   _real_extractn   s    
 
zAsobiChannelIE._real_extract)r   r   r   IE_NAMEIE_DESC
_VALID_URL_TESTSr+   r-   r4   r9   r?   r   r   r   r   r!      sN   "r!   c                   @   sD   e Zd 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 )AsobiChannelTagURLIEzasobichannel:tagr"   z=https?://asobichannel\.asobistore\.jp/tag/(?P<id>[a-z0-9-_]+)z1https://asobichannel.asobistore.jp/tag/bjhh-nbcjaz
bjhh-nbcjauM   アイドルマスター ミリオンライブ！ 765プロch 原っぱ通信)r   r      )r   r'   Zplaylist_mincountz2https://asobichannel.asobistore.jp/tag/hvm5qw3c6odZhvm5qw3c6odu   アイマスMOIW2023ラジオ   c                    sp    |}||}tj||ddddddthf}jd| d|jd	  fd
d}| ||S )NF)fatalpropsZ	pagePropsr5   r   zIhttps://channel.microcms.io/api/v1/media?limit=999&filters=(tag[contains])r:   c                  3   sB   t  ddd fD ]*} dd| d  t d| V  qd S )Nr   c                 S   s   |d S )Nr   r   )_vr   r   r   <lambda>       zEAsobiChannelTagURLIE._real_extract.<locals>.entries.<locals>.<lambda>r   z)https://asobichannel.asobistore.jp/watch/r   )_typer   ie_key)r	   r!   rO   r   )r   Zmediar   r   r   entries   s    z3AsobiChannelTagURLIE._real_extract.<locals>.entries)r=   Z_download_webpager	   Z_search_nextjs_datar   r*   r    Zplaylist_result)r   r   Ztag_idZwebpager   rQ   r   rP   r   r?      s     
  
 	z"AsobiChannelTagURLIE._real_extractN)r   r   r   r@   rA   rB   rC   r?   r   r   r   r   rD      s"   rD   N)commonr   utilsr   r   r   r   r   Zutils.traversalr	   r
   r!   rD   r   r   r   r   <module>   s
   d