[BUG] PytubeError when using YoutubeVideoSearchTool with a specific YouTube video URL
Description
Summary
When attempting to use YoutubeVideoSearchTool with a specific YouTube video URL, a PytubeError occurs. This error is raised by pytube while trying to access the video title. The error message suggests a missing videoDetails field in the YouTube response, which causes a KeyError. This issue may be related to recent changes in YouTube’s data structure or a limitation within pytube.
Steps to Reproduce
- I used the following code to initiate a
YoutubeVideoSearchToolinstance with a specified YouTube video URL:from crewai_tools import YoutubeVideoSearchTool youtube_video_url = "https://www.youtube.com/watch?v=FD-yp57VbmQ" youtube_video_search_tool = YoutubeVideoSearchTool(youtube_video_url=youtube_video_url) - When this code runs, it raises a
PytubeErrorwith aKeyError: 'videoDetails', which preventsYoutubeVideoSearchToolfrom working with this video.
Error Message
PytubeError: Exception while accessing title of https://youtube.com/watch?v=FD-yp57VbmQ. Please file a bug report at https://github.com/pytube/pytube
Traceback:
File "path_to_crewai_tools/youtube_video_search_tool.py", line XX, in __init__
self.add(youtube_video_url)
File "path_to_pytube/__main__.py", line 346, in title
self._title = self.vid_info['videoDetails']['title']
KeyError: 'videoDetails'
Environment
-
crewaiversion: 0.51.1 -
pytubeversion: 15.0.0 - Python version: 3.11.9
- Operating System: macOS Sequoia 15.1
Expected behavior
YoutubeVideoSearchTool should retrieve information from the specified YouTube video URL without errors.
Screenshots/Code snippets
None
Operating System
Other (specify in additional context)
Python Version
3.11
crewAI Version
0.51.1
crewAI Tools Version
0.8.3
Virtual Environment
Venv
Evidence
PytubeError: Exception while accessing title of https://youtube.com/watch?v=example. Please file a bug report at https://github.com/pytube/pytube Traceback: File "path_to_crewai_tools/youtube_video_search_tool.py", line XX, in init self.add(youtube_video_url) File "path_to_pytube/main.py", line 346, in title self._title = self.vid_info['videoDetails']['title'] KeyError: 'videoDetails'
Possible Solution
None
Additional context
None
This seems to be an issue stemming from PyTube. I presume this is a downstream issue from YouTube changing some of their code. We'll track and implement a patch. Here's a related issue on PyTube https://github.com/pytube/pytube/issues/2074
Has anyone found a work around for this?
Same problem here.
Also having this issue
This solution mentioned in https://github.com/pytube/pytube/issues/2074 worked for me
Step 1) Find where pytube is installed in your local
import pytube import os print(os.path.dirname(pytube.file))
Step 2) Go to this location where package related files are saved, open main.py and modify the code with below
`def vid_info(self): """Parse the raw vid info and return the parsed result.
:rtype: Dict[Any, Any]
"""
if self._vid_info:
return self._vid_info
innertube = InnerTube(client='WEB', use_oauth=self.use_oauth, allow_cache=self.allow_oauth_cache)
innertube_response = innertube.player(self.video_id)
self._vid_info = innertube_response
return self._vid_info`
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.