U
    Mf+                     @   s@   d dl mZ ddlmZmZmZmZmZmZ G dd deZ	dS )   )InfoExtractor   )ExtractorErrorjoin_nonemptysmuggle_urlstr_or_nonestrip_or_nonetraverse_objc                	   @   s\   e Zd ZdZddddddddd	d
gdddddddgZdZdZdZdd Zdd Z	dS )TVerIEzrhttps?://(?:www\.)?tver\.jp/(?:(?P<type>lp|corner|series|episodes?|feature|tokyo2020/video)/)+(?P<id>[a-zA-Z0-9]+)z$videos are only available for 7 daysz#https://tver.jp/episodes/ep83nf3w4puk   家事ヤロウ!!! 売り場席巻のチーズSP＆財前直見×森泉親子の脱東京暮らし密着！z$md5:dc2c06b6acc23f1e7c730c513737719bu   家事ヤロウ!!!uX   売り場席巻のチーズSP＆財前直見×森泉親子の脱東京暮らし密着！u   テレビ朝日)titledescriptionseriesepisode	alt_titlechannelBrightcoveNew)skipurlZ	info_dictZadd_iezhttps://tver.jp/corner/f0103888T)r   Zonly_matchingzhttps://tver.jp/lp/f0033031zFhttp://players.brightcove.net/%s/default_default/index.html?videoId=%sNc              	   C   s8   | j dd ddddddd}t|d	| _t|d
| _d S )NzAhttps://platform-api.tver.jp/v2/api/platform_users/browser/createzCreating sessions   device_type=pczhttps://s.tver.jpzhttps://s.tver.jp/z!application/x-www-form-urlencoded)OriginRefererzContent-Type)notedataheaders)resultplatform_uid)r   platform_token)_download_jsonr	   _PLATFORM_UID_PLATFORM_TOKEN)selfZcreate_response r    9/tmp/pip-unpacked-wheel-zk9bgjdq/yt_dlp/extractor/tver.py_real_initialize%   s      zTVerIE._real_initializec                 C   s~  |  |dd\}}|dkrB| j||dd}| | d|d}| jd| d	|d
| j| jdddid}t|dpxi }| jd| d|dt	|
dpdidddd}|d d }t|dd
d}	|	std|	 sd|	 }	t|
d}
t	|
d }t||
d!d"pt	|
d}t	|
d#}t	|
d$}d%|||
t|||d!d"|t	|
d&t| j||	f d'd(gid)d*	S )+Nidtype>   episodesr   zResolving to new URL)r   )z-canonical"\s*href="(https?://tver\.jp/[^"]+)"z$&link=(https?://tver\.jp/[^?&]+)[?&]z	url regexz8https://platform-api.tver.jp/service/api/v1/callEpisode/zJ?require_data=mylist,later[epefy106ur],good[epefy106ur],resume[epefy106ur]F)r   r   zx-tver-platform-typeZweb)fatalqueryr   )r   r   contentz(https://statics.tver.jp/content/episode/z.jsonvversion5zhttps://tver.jpzhttps://tver.jp/)r   r   )r'   r   videoZ	accountID)r,   )Z
videoRefIDZvideoID)get_allz-Failed to extract reference ID for Brightcovezref:r   ZseriesTitle )delimZproductionProviderNameZbroadcastDateLabelZurl_transparentr   Zgeo_countriesZJPr   )	_typer   r   r   r   r   r   r   Zie_key)Z_match_valid_urlgroupZ_download_webpageZ	_match_idZ_search_regexr   r   r   r	   r   getr   isdigitr   r   r   BRIGHTCOVE_URL_TEMPLATE)r   r   Zvideo_idZ
video_typeZwebpageZepisode_infoZepisode_contentZ
video_infoZp_idZr_idr   r   r   ZproviderZonair_labelr    r    r!   _real_extract0   sz     
  	 
  
 zTVerIE._real_extract)
__name__
__module____qualname__Z
_VALID_URLZ_TESTSr4   r   r   r"   r5   r    r    r    r!   r
      s0   r
   N)
commonr   utilsr   r   r   r   r   r	   r
   r    r    r    r!   <module>   s    
