
    =Ґi                     R    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e      Z	y)	    N   )YoutubeTabBaseInfoExtractorYoutubeTabIE)	YoutubeIE   )traverse_objc                   H    e Zd ZdZdZdZdZddddddgZd Zd	 Z	d
 Z
d Zy)YoutubeNotificationsIEzyoutube:notifz<YouTube notifications; ":ytnotif" keyword (requires cookies)z:ytnotif(?:ication)?s?Tz:ytnotif)urlonly_matchingz:ytnotificationsc              #      K   t        |ddt              xs g }d |d<   |D ]A  }| j                  |j                  d            }|r| |j                  d      }|s=||d<   C y w)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continuations          `/var/www/descvideos/venv/lib/python3.12/site-packages/yt_dlp/extractor/youtube/_notifications.py_extract_notification_menuz1YoutubeNotificationsIE._extract_notification_menu   s     ( TP	  & $&	 	
  $!% 	4D77AW8XYE88$>?L'3!!$	4s   AA&A&c                    t        |dt              }d| }d }|set        |dt              }| j                  t        |dt                    }| j	                  dt        |dt              dd 	      }|r|sy d
| d| }t        |dt              }| j                  |d      }|r|j                  dd      }| j	                  t        j                  |xs d       d|dd 	      }	| j                  dt              r!| j                  | j                  |d            nd }
d||rt        nt        j                         ||	|||| j                  |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   r2   shortMessage   ­ z[^:]+: (.+)zvideo titleapproximate_date)ie_keysentTimeTextr   videoThumbnail)
_typer   r8   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   r8   _extract_thumbnails)r   notificationr<   r   r>   	browse_eppost_idr?   notification_titler=   rB   s              r%   r   z5YoutubeNotificationsIE._extract_notification_renderer%   s   L\_a0
;
$FVZ\I**<	:]`+abJ((|I7IY\]4 ) )G W4ZLwiXC~ "^^L.I!3!;!;FB!G""		'-R()57I4 # ) //0B</X **4>>,+WX 	 $,y,FFH $22<AQR"
 	
    c              #   4  K   d g}d }t        j                  d      D ]u  }t        |dt              }| j	                  d| |rd|ini |dd| j                  || j                  |            	      }| j                  ||      E d {    |d
   ru y  y 7 w)Nr   )r   continuationEndpointgetNotificationMenuEndpointctokenr   zpage rV   z"notification/get_notification_menur   )ytcfgvisitor_data)item_idqueryrW   epcheck_get_keysheadersr   )	itertoolscountr   rC   _extract_responsegenerate_api_headers_extract_visitor_datar&   )r   rW   r    r   pagerV   s         r%   _notification_menu_entriesz1YoutubeNotificationsIE._notification_menu_entriesP   s     !FOOA& 		D!!#gwz|F--vFx.@PRZ_7	11DLfLfgoLp1q . sH 66xARSSS$Q'		 Ts   BBB	BBc                     d}| j                   s| j                  d|      ni }| j                  |       | j                  | j	                  |      ||      S )Nnotificationsweb)skip_webpage_download_ytcfg_report_playlist_authcheckplaylist_resultrd   )r   r   
display_idrW   s       r%   _real_extractz$YoutubeNotificationsIE._real_extract^   sS    $
?C?P?P$$UJ7VX''.##D$C$CE$JJXbccrR   N)__name__
__module____qualname__IE_NAMEIE_DESC
_VALID_URL_LOGIN_REQUIRED_TESTSr&   r   rd   rm    rR   r%   r
   r
   	   sK    GLG*JO "F4)
VdrR   r
   )
r^   rI   _tabr   r   _videor   utilsr   r
   rv   rR   r%   <module>rz      s%     	 ;  !Yd8 YdrR   