
    dh                     J    S r SSKrSSKJr  SSKJr  SSKJr   " S S\5      rg)ae  
Adapted from https://github.com/venuv/langchain_yt_tools

CustomYTSearchTool searches YouTube videos related to a person
and returns a specified number of video URLs.
Input to this tool should be a comma separated list,
 - the first part contains a person name
 - and the second(optional) a number that is the
    maximum number of video results to return
    N)Optional)CallbackManagerForToolRun)BaseToolc                   n    \ rS rSr% SrSr\\S'   Sr\\S'   S\S\	S	\4S
 jr
 SS\S\\   S	\4S jjrSrg)YouTubeSearchTool   zTool that queries YouTube.youtube_searchnamea  search for youtube videos associated with a person. the input to this tool should be a comma separated list, the first part contains a person name and the second a number that is the maximum number of video results to return aka num_results. the second part is optionaldescriptionpersonnum_resultsreturnc                     SSK Jn  U" X5      R                  5       n[        R                  " U5      nUS    Vs/ sH  nSUS   -   PM     nn[        U5      $ s  snf )Nr   )YoutubeSearchvideoszhttps://www.youtube.com
url_suffix)r	   r   to_jsonjsonloadsstr)selfr   r   r   resultsdatavideourl_suffix_lists           `/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/tools/youtube/search.py_searchYouTubeSearchTool._search   sc    04<<>zz'"IMh
IW%l(;; 	 
 ?##
s   ANqueryrun_managerc                     UR                  S5      nUS   n[        U5      S:  a  [        US   5      nOSnU R                  XE5      $ )zUse the tool.,r         )splitlenintr   )r   r   r    valuesr   r   s         r   _runYouTubeSearchTool._run)   sG     S!v;?fQi.KK||F00     )N)__name__
__module____qualname____firstlineno____doc__r
   r   __annotations__r   r'   r   r   r   r)   __static_attributes__r,   r+   r   r   r      sm    $ D# 	A  $c $ $ $ <@11 781 
	1 1r+   r   )	r1   r   typingr   langchain_core.callbacksr   langchain_core.toolsr   r   r,   r+   r   <module>r7      s$   	   > )"1 "1r+   