#!/usr/bin/env python3 """ Example usage of YouTube Video Analysis Tools This script demonstrates how to use the YouTube video analysis tools that have been added to the agent. """ import json import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from tools import analyze_youtube_video, get_youtube_video_info def demo_video_info(): """Demonstrate getting video information.""" print("🎬 Getting Video Information") print("-" * 40) # Example with a well-known short video video_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ" try: result = get_youtube_video_info(video_url) info = json.loads(result) if info.get("status") == "success": print(f"✅ Title: {info.get('title')}") print(f"⏱️ Duration: {info.get('duration')}") print(f"👤 Uploader: {info.get('uploader')}") print(f"👁️ Views: {info.get('view_count'):,}") print(f"📏 Resolution: {info.get('resolution')}") else: print(f"❌ Error: {info.get('error')}") except Exception as e: print(f"❌ Exception: {e}") print("\n") def demo_frame_analysis(): """Demonstrate frame analysis (this would take longer).""" print("🎞️ Frame Analysis Example") print("-" * 40) print("Note: This would download and analyze video frames.") print("For demonstration, we'll show how to call it:") print() example_code = """ # Example usage: result = analyze_youtube_video( "https://www.youtube.com/watch?v=dQw4w9WgXcQ", max_frames=3, interval_seconds=60.0 ) analysis = json.loads(result) if analysis.get('status') == 'success': print(f"Video: {analysis['video_info']['title']}") print(f"Frames analyzed: {analysis['frames_extracted']}") for frame in analysis['frame_analyses']: timestamp = frame['timestamp_formatted'] description = frame['description'] print(f" {timestamp}: {description}") """ print(example_code) def demo_agent_integration(): """Show how these tools integrate with the agent.""" print("🤖 Agent Integration") print("-" * 40) example_queries = [ "Get information about this YouTube video: https://www.youtube.com/watch?v=dQw4w9WgXcQ", "Analyze this video and describe what happens in it: [YouTube URL]", "Extract 5 frames from this tutorial video every 30 seconds: [YouTube URL]", "What is the duration and title of this video: [YouTube URL]", "Describe the visual content of this educational video: [YouTube URL]", ] print("Example queries the agent can now handle:") print() for i, query in enumerate(example_queries, 1): print(f"{i}. {query}") print("\n" + "=" * 50) print("The agent now has YouTube video analysis capabilities!") print("Users can ask questions about YouTube videos and get:") print("• Video metadata (title, duration, uploader)") print("• Frame-by-frame visual analysis") print("• Content summaries and descriptions") print("• Timestamp-based scene analysis") if __name__ == "__main__": print("YouTube Video Analysis Tools - Demo") print("=" * 50) # Demo 1: Video info demo_video_info() # Demo 2: Frame analysis explanation demo_frame_analysis() # Demo 3: Agent integration demo_agent_integration()