crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] PytubeError when using YoutubeVideoSearchTool with a specific YouTube video URL

Open naoki1213mj opened this issue 1 year ago • 5 comments

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

  1. I used the following code to initiate a YoutubeVideoSearchTool instance 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)
    
  2. When this code runs, it raises a PytubeError with a KeyError: 'videoDetails', which prevents YoutubeVideoSearchTool from 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

  • crewai version: 0.51.1
  • pytube version: 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

naoki1213mj avatar Nov 11 '24 14:11 naoki1213mj

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

tonykipkemboi avatar Nov 22 '24 13:11 tonykipkemboi

Has anyone found a work around for this?

impactcolor avatar Dec 21 '24 03:12 impactcolor

Same problem here.

carvalhorafael avatar Dec 22 '24 01:12 carvalhorafael

Also having this issue

jaharvey8 avatar Jan 04 '25 06:01 jaharvey8

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`

ArunSubramanian456 avatar Jan 04 '25 16:01 ArunSubramanian456

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.

github-actions[bot] avatar Feb 04 '25 12:02 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Feb 10 '25 12:02 github-actions[bot]