From 4613d2380e85731ed168e6d3482cf35b10a5edc4 Mon Sep 17 00:00:00 2001 From: lalithdabilpuram01 Date: Tue, 14 Apr 2026 12:52:10 -0400 Subject: [PATCH] Migrate YouTube channel loader to pytubefix --- lib/crewai-tools/pyproject.toml | 2 +- .../rag/loaders/youtube_channel_loader.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/crewai-tools/pyproject.toml b/lib/crewai-tools/pyproject.toml index bc7bfd6a33..56bd808b43 100644 --- a/lib/crewai-tools/pyproject.toml +++ b/lib/crewai-tools/pyproject.toml @@ -8,7 +8,7 @@ authors = [ ] requires-python = ">=3.10, <3.14" dependencies = [ - "pytube~=15.0.0", + "pytubefix>=8.4.0", "requests>=2.33.0,<3", "crewai==1.14.2a3", "tiktoken~=0.8.0", diff --git a/lib/crewai-tools/src/crewai_tools/rag/loaders/youtube_channel_loader.py b/lib/crewai-tools/src/crewai_tools/rag/loaders/youtube_channel_loader.py index ac6b79a6fa..5808af7456 100644 --- a/lib/crewai-tools/src/crewai_tools/rag/loaders/youtube_channel_loader.py +++ b/lib/crewai-tools/src/crewai_tools/rag/loaders/youtube_channel_loader.py @@ -24,10 +24,10 @@ def load(self, source: SourceContent, **kwargs: Any) -> LoaderResult: # type: i ValueError: If the URL is not a valid YouTube channel URL """ try: - from pytube import Channel # type: ignore[import-untyped] + from pytubefix import Channel # type: ignore[import-untyped] except ImportError as e: raise ImportError( - "YouTube channel support requires pytube. Install with: uv add pytube" + "YouTube channel support requires pytubefix. Install with: uv add pytubefix" ) from e channel_url = source.source @@ -55,7 +55,12 @@ def load(self, source: SourceContent, **kwargs: Any) -> LoaderResult: # type: i metadata["channel_id"] = channel.channel_id max_videos = kwargs.get("max_videos", 10) - video_urls = list(channel.video_urls)[:max_videos] + + # --- FIX: Safely parse watch_urls from pytubefix video objects --- + raw_video_urls = list(channel.video_urls)[:max_videos] + video_urls = [v.watch_url if hasattr(v, 'watch_url') else str(v) for v in raw_video_urls] + # ----------------------------------------------------------------- + metadata["num_videos_loaded"] = len(video_urls) metadata["total_videos"] = len(list(channel.video_urls)) @@ -68,7 +73,7 @@ def load(self, source: SourceContent, **kwargs: Any) -> LoaderResult: # type: i ] try: - from pytube import YouTube + from pytubefix import YouTube from youtube_transcript_api import YouTubeTranscriptApi for i, video_url in enumerate(video_urls, 1):