U
    3d                     @   s   d dl mZmZ d dlmZ d dlmZmZ d dlm	Z	 d dl
mZ eddgdZG d	d
 d
eZededddZededddZdS )    )ListOptional)	BaseModel)	APIRouterBody)JSONResponse)Utilsz/videozYoutube Video Comments Analyzer)prefixtagsc                   @   s&   e Zd ZU eed< dZee ed< dS )VideoAnalysisRequestvideoURLi  nbrCommentsN)__name__
__module____qualname__str__annotations__r   r   int r   r   @/var/www/html/YouTubeCommentsAnalyzer/src/app/api/v1/comments.pyr      s   
r   z	/comments)requestc              
      s  z| j }| j}|d ks| s2tdddddW S t|sPtdddddW S t|}|d szt|d ddddW S |d	 }tj||d
}|d st|d ddddW S |d	 }t|d| ||ddddW S  tk
r } ztt	|dddd W Y S d }~X Y nX d S )N(YouTube video URL parameter is required!errormessagestatus  status_codeInvalid YouTube URLr   r   datavideo_idnbr_comments https://www.youtube.com/watch?v=success)videoIDr   r#   commentsr      )
r   r   stripr   r   validate_youtube_urlextract_video_idget_youtube_comments	Exceptionr   )r   r   r   
extract_idr"   extract_commentsr'   exr   r   r   get_comments   sR    

r1   z/analysec              
      s<  z| j }| j}|d ks| s2tdddddW S t|sPtdddddW S t|}|d szt|d ddddW S |d	 }tj||d
}|d st|d ddddW S |d	 }tj|d}t	|}t
|}	t|d| |||	ddddW S  tk
r6 }
 ztt|
dddd W Y S d }
~
X Y nX d S )Nr   r   r   r   r   r   r   r   r    r!   )Zcomment_listr$   r%   )r&   r   r#   r'   Zreportr   r(   )r   r   r)   r   r   r*   r+   r,   Zget_comments_reportsZsummarize_reportsZdefine_summaryr-   r   )r   r   r   r.   r"   r/   r'   ZreportsZfinal_reportZ	summarizer0   r   r   r   analyseQ   sZ    



r2   N)typingr   r   pydanticr   fastapir   r   fastapi.responsesr   Zapp.utils.utilsr   routerr   postr1   r2   r   r   r   r   <module>   s   >