o
    i!                     @   s   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 ddlmZmZ G dd	 d	eZG d
d deZG dd deZdS )    N   )StreaksBaseIE   )HEADRequest)InAdvancePagedList
clean_html
js_to_jsonparse_iso8601parse_qsstr_or_none)requiretraverse_objc                   @   s"   e Zd ZdZdZdZdddZdS )	LocipoBaseIEzhttps://web-api.locipo.jphttps://locipo.jpz([\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}Tc                 C   s0   | j | j d| |d| dd| d|dS )N/zDownloading z	 API JSONzUnable to download fatal)_download_json	_API_BASE)selfpathitem_idnoter    r   K/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/locipo.py	_call_api   s   

zLocipoBaseIE._call_apiN)T)__name__
__module____qualname__r   	_BASE_URL_UUID_REr   r   r   r   r   r      s
    r   c                   @   s  e Zd Zdej ddej dgZdi 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ddd d!d"d#d$d%d&d'id(d)i dd*ddd	d+dd,dd-dddddedd.dd/dd0dd1dd2ddd d3d"d#d$d4d&d'id(d5d6d7d8d9d:d;i dd<ddd	d=dd>dd?dddddedd@ddAddBddCddDddd dEd"d#d$dFd&d'idGdHidIgZdJdK ZdLS )MLocipoIEz$https?://locipo\.jp/creative/(?P<id>)z2https?://locipo\.jp/embed/?\?(?:[^#]+&)?id=(?P<id>z?https://locipo.jp/creative/fb5ffeaa-398d-45ce-bb49-0e221b5f94f1idz$fb5ffeaa-398d-45ce-bb49-0e221b5f94f1extmp4titleuB   リアルカレカノ#4 ～伊達さゆりと勉強しよっ？～descriptionz$md5:70a40c202f3fb7946b61e55fa015094c
display_id 5a2947fe596441f5bab88a61b0432d0dlive_statusnot_livemodified_datezre:\d{8}modified_timestamprelease_timestampifrelease_date20240330seriesu   リアルカレカノ	series_id1142tagszcount:4	thumbnailzre:https?://.+\.(?:jpg|png)	timestampiWvhupload_date20250904uploaderu   東海テレビuploader_idlocipo-prod)url	info_dictz@https://locipo.jp/embed/?id=71a334a0-2b25-406f-9d96-88f341f571c2z$71a334a0-2b25-406f-9d96-88f341f571c2u?   #1 オーディション／ゲスト伊藤美来、豊田萌絵z$md5:5bbcf532474700439cf56ceb6a15630e 0ab32634b884499a84adb25de844c551i gh20250704u6   声優ラジオのウラカブリ～Locipo出張所～1454zcount:6iּhu   テレビ愛知zihttps://locipo.jp/creative/bff9950d-229b-4fe9-911a-7fa71a232f35?list=69a5b15c-901f-4828-a336-30c0de7612d3z$69a5b15c-901f-4828-a336-30c0de7612d3u7   見て・乗って・語りたい。 東海の鉄道沼r#   r&      r<   r=   playlist_mincountzihttps://locipo.jp/creative/a0751a7f-c7dd-4a10-a7f1-e12720bdf16c?list=006cff3f-ba74-42f0-b4fd-241486ebda2bz$a0751a7f-c7dd-4a10-a7f1-e12720bdf16cu   #839 人間真空パックz$md5:9fe190333b6975c5001c8c9cbe20d276 c2b4c9f4a6d648bd8e3c320e384b9d56ih20250503u'   でんじろう先生のはぴエネ！202zcount:3i%Shu   中京テレビ
noplaylistT)r<   r=   paramsc           	      C   s:  |  |}tt|ddthf}| ||r"| | j d| tS | d| |d}t|dtht	dhf}| 
||}| jd|d	|td
}t|ddtht	dhf}i | jd|d|ddt|dthfdthtfdthfdthdd hdtjhtfddthtfdt|ddthtfdthfdfd|iS )Nlistz
/playlist/z
creatives/	Creativesmedia_idzStreaks media IDzwindow\.__NUXT__\.config\s*=config)transform_sourcepublicstreaksVodPlaybackApiKeyzapi keyr;   r   )OriginzX-Streaks-Api-Key)headersnamer'   publication_started_atkeywordc                 S   s
   |  dS )N,)split)xr   r   r   <lambda>   s   
 z(LocipoIE._real_extract.<locals>.<lambda>.company)r&   r'   r.   r4   r9   r1   r#   )r1   r2   )	_match_idr   r
   str_yes_playlist
url_resultr   LocipoPlaylistIEr   r   _download_webpage_search_jsonr   _extract_from_streaks_apir   filterr	   stripr   )	r   r<   video_idplaylist_id	creativesrM   webpagerN   api_keyr   r   r   _real_extracto   sD   



zLocipoIE._real_extractN)	r   r   r   r   r    
_VALID_URLint_TESTSrk   r   r   r   r   r!      s   	
	
	
Lr!   c                   @   sj   e Zd Zdej ddgZ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S )r`   z.https?://locipo\.jp/(?P<type>playlist)/(?P<id>r"   z0https?://locipo\.jp/(?P<type>series)/(?P<id>\d+)z?https://locipo.jp/playlist/35d3dd2b-531d-4824-8575-b1c527d29538z$35d3dd2b-531d-4824-8575-b1c527d29538u   レシピ集rA      rC   z?https://locipo.jp/playlist/fef7c4fb-741f-4d6a-a3a6-754f354302a21363u6   CBCアナウンサー公式【みてちょてれび】z$md5:50a1b23e63112d5c06c882835c8c1fb1)r#   r&   r'   &   zhttps://locipo.jp/series/503503u   FishingLover東海u]   東海地区の釣り場でフィッシングの魅力を余すところなくご紹介！！   d   c              	   c   s|    | j | j d| d| d|d|d  dd| j|| j dd}t|dd	d
thfD ]}| | j d| tV  q,d S )Nr   
/creativeszDownloading page r   F)premiumlivelimitoffset)queryitems.r#   z
/creative/)r   r   
_PAGE_SIZEr   r]   r_   r   r!   )r   r   rg   pagerh   rf   r   r   r   _fetch_page   s   	zLocipoPlaylistIE._fetch_pagec                 C   s   |  |dd\}}| jt||dd }r#|  |jdd\}}|dkr)dnd}| | d| d	|| }tt	| j
||tt|d
 | j | j}| j||fi t|dd|dthtfdthtfdtfS )Ntyper#   Fr   playlist	playlistsr1   r   ru   totalr{   .rT   r'   )r&   r'   )_match_valid_urlgroup_request_webpager   r<   r   
capitalizer   	functoolspartialr~   mathceilrm   r|   playlist_resultr   r   rd   any)r   r<   playlist_typerg   urlhr   rh   entriesr   r   r   rk      s*   


zLocipoPlaylistIE._real_extractN)
r   r   r   r   r    rl   rn   r|   r~   rk   r   r   r   r   r`      s8    	
r`   )r   r   streaksr   
networkingr   utilsr   r   r   r	   r
   r   utils.traversalr   r   r   r!   r`   r   r   r   r   <module>   s     t