o
    i                     @   sL   d dl Z d dlZddlmZmZ ddlmZ ddlmZ G dd deZ	dS )	    N   )YoutubeTabBaseInfoExtractorYoutubeTabIE)	YoutubeIE   )traverse_objc                   @   sP   e Zd ZdZdZdZdZddddddgZdd	 Zd
d Z	dd Z
dd ZdS )YoutubeNotificationsIEzyoutube:notifz<YouTube notifications; ":ytnotif" keyword (requires cookies)z:ytnotif(?:ication)?s?Tz:ytnotif)urlonly_matchingz:ytnotificationsc                 c   s\    t |ddtdp
g }d |d< |D ]}| |d}|r |V  |d}|r+||d< qd S )N)	actionsr   openPopupActionpopupmultiPageMenuRenderersectionsr   (multiPageMenuNotificationSectionRendereritems)r   r   appendContinuationItemsActioncontinuationItemsexpected_typer   notificationRenderercontinuationItemRenderer)r   list_extract_notification_rendererget)selfresponsecontinuation_listnotification_listitementrycontinuation r"   [/home/ubuntu/.local/lib/python3.10/site-packages/yt_dlp/extractor/youtube/_notifications.py_extract_notification_menu   s&   
z1YoutubeNotificationsIE._extract_notification_menuc                 C   s  t |dtd}d| }d }|s=t |dtd}| t |dtd}| jdt |dtddd d	}|r3|s5d S d
| d| }t |dtd}| |d}|rR|dd}| jt|pYd d|dd d	}	| j	dt
drs| | |dnd }
d||r{tnt
 ||	|||| |d|
d
S )N)navigationEndpointwatchEndpointvideoIdr   z https://www.youtube.com/watch?v=)r%   browseEndpointbrowseIdz
/post/(.+)canonicalBaseUrlzpost id)defaultz https://www.youtube.com/channel/z/community?lb=)	contextualMenumenuRendererr   r   menuServiceItemRenderertextrunsr   r/   shortMessage   ­ z[^:]+: (.+)zvideo titleapproximate_date)ie_keysentTimeTextr	   videoThumbnail)
_typer	   r5   video_idtitle
channel_idchanneluploader
thumbnails	timestamp)r   strdictucid_or_none_search_regex	_get_textreplacereescape_configuration_argr   _parse_time_textr   r5   _extract_thumbnails)r   notificationr9   r	   r;   	browse_eppost_idr<   notification_titler:   r?   r"   r"   r#   r   %   sV   

z5YoutubeNotificationsIE._extract_notification_rendererc                 c   s    d g}d }t dD ]5}t|dtd}| jd| |r d|ini |dd| j|| |dd	}| ||E d H  |d
 s@ d S qd S )Nr   )r   continuationEndpointgetNotificationMenuEndpointctokenr   zpage rQ   z"notification/get_notification_menur   )ytcfgvisitor_data)item_idqueryrR   epcheck_get_keysheadersr   )	itertoolscountr   r@   _extract_responsegenerate_api_headers_extract_visitor_datar$   )r   rR   r   r   pagerQ   r"   r"   r#   _notification_menu_entriesP   s"   z1YoutubeNotificationsIE._notification_menu_entriesc                 C   s8   d}| j s| d|ni }| | | | |||S )Nnotificationsweb)skip_webpage_download_ytcfg_report_playlist_authcheckplaylist_resultr_   )r   r	   
display_idrR   r"   r"   r#   _real_extract^   s   
z$YoutubeNotificationsIE._real_extractN)__name__
__module____qualname__IE_NAMEIE_DESC
_VALID_URL_LOGIN_REQUIRED_TESTSr$   r   r_   rg   r"   r"   r"   r#   r   	   s     +r   )
rY   rF   _tabr   r   _videor   utilsr   r   r"   r"   r"   r#   <module>   s    