U
    g                     @   sH   d dl Zd dlZddlmZ ddlmZmZm	Z	m
Z
 G dd deZdS )    N   )InfoExtractor   )
clean_htmldatetime_from_strunified_timestampurljoinc                   @   st   e Zd ZdZdddgZddededed	d
d
dddd
ddd
ddd
ddd
dgZdd Zdd Z	dd Z
dS )JoqrAgIEuM   超!A&G+ 文化放送 (f.k.a. AGQR) Nippon Cultural Broadcasting, Inc. (JOQR)zFhttps?://www\.uniqueradio\.jp/agplayer5/(?:player|inc-player-hls)\.phpz#https?://(?:www\.)?joqr\.co\.jp/ag/zIhttps?://(?:www\.)?joqr\.co\.jp/qr/ag(?:daily|regular)program/?(?:$|[#?])z/https://www.uniqueradio.jp/agplayer5/player.phplive   超!A&G+is_live)idtitlechanneldescriptionlive_statusrelease_timestampT)Zskip_downloadZignore_no_formats_error)urlZ	info_dictparams7https://www.uniqueradio.jp/agplayer5/inc-player-hls.php)r   Zonly_matchingz)https://www.joqr.co.jp/ag/article/103760/z(http://www.joqr.co.jp/qr/agdailyprogram/z*http://www.joqr.co.jp/qr/agregularprogram/c              
   C   s,   t tj| jd| d|ddddp*d S )Nzvar\s+z'\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1metadatavalue )groupdefault)r   urllibparseunquote_plus_search_regex)selfvariablehtml r"   ;/tmp/pip-unpacked-wheel-q5ljy6pj/yt_dlp/extractor/joqrag.py_extract_metadata.   s    
   
zJoqrAgIE._extract_metadatac                    sB    fdd}|d}|sd S |r2|t d k r6|S |dS d S )Nc              	      sx   t | tjdd }|d} jd jd| d| dd| d	pLd
dd d}|rtt|d d| dS d S )N	   )hoursz%Y%m%duR   <h3[^>]+\bclass="dailyProgram-itemHeaderTime"[^>]*>[\s\d:]+–\s*(\d{1,2}:\d{1,2})z/https://www.joqr.co.jp/qr/agdailyprogram/?date=zDownloading program list of Fz#Failed to download program list of )notefatalerrnoter   z
start time)r   z%Y/%m/%d z +09:00)r   dt	timedeltastrftimer   _download_webpager   )Zdate_strZdt_date
start_timer   video_idr"   r#   extract_start_time_from4   s$    
   zBJoqrAgIE._extract_start_timestamp.<locals>.extract_start_time_fromtodaynowZ	yesterday)r   	timestamp)r   r2   r   r3   Zstart_timestampr"   r1   r#   _extract_start_timestamp3   s    z!JoqrAgIE._extract_start_timestampc           
   	   C   s   d}| j d|ddd}| d|}|r.|dkrtg }d}| |d	}d
}|rd|dtj|d 7 }| j|dd n>| d| j d|dddd}	| 	t
d|	|}d}| |d}||d| d||||dS )Nr
   z https://www.uniqueradio.jp/aandgzDownloading metadatazFailed to download metadata)r'   r)   ZProgram_nameu   放送休止Zis_upcomingFz!This stream is not currently livez and will start at z%Y-%m-%d %H:%M:%ST)expectedz<source\s[^>]*\bsrc="([^"]+)"r   zDownloading player datazFailed to download player datazm3u8 urlzhttps://www.uniqueradio.jp/r   r   ZProgram_text)r   r   r   r   formatsr   r   )r.   r$   r7   r+   datetimefromtimestampr-   Zraise_no_formatsr   Z_extract_m3u8_formatsr   )
r   r   r2   r   r   r9   r   r   msgZ	m3u8_pathr"   r"   r#   _real_extractK   sT         
zJoqrAgIE._real_extractN)__name__
__module____qualname__ZIE_DESCZ
_VALID_URLstrintZ_TESTSr$   r7   r=   r"   r"   r"   r#   r	      sB   	r	   )r:   r+   urllib.parser   commonr   utilsr   r   r   r   r	   r"   r"   r"   r#   <module>   s   