
    7|h                     J    d Z ddlZddlmZ ddlmZ ddlmZ  G d de      Zy)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                   `    e Zd ZU dZdZeed<   dZeed<   dededefd	Z		 ddede
e   defdZy
)YouTubeSearchToolz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                     ddl m}  |||      j                         }t        j                  |      }|d   D cg c]
  }d|d   z    }}t        |      S c c}w )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           g/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/tools/youtube/search.py_searchzYouTubeSearchTool._search   sc    04<<>zz'"IMh
@E%l(;;
 
 ?##
s   ANqueryrun_managerc                     |j                  d      }|d   }t        |      dkD  rt        |d         }nd}| j                  ||      S )zUse the tool.,r         )splitlenintr   )r   r   r   valuesr   r   s         r   _runzYouTubeSearchTool._run)   sI     S!v;?fQi.KK||FK00    )N)__name__
__module____qualname____doc__r	   r   __annotations__r
   r%   r   r   r   r'    r(   r   r   r      sh    $ D# 	A  $c $ $ $ <@11 781 
	1r(   r   )	r,   r   typingr   langchain_core.callbacksr   langchain_core.toolsr   r   r.   r(   r   <module>r2      s$   	   > )"1 "1r(   