"""
Link scanner tools - Separate tools for video and text links
"""
from mcp.types import Tool
from src.handlers.media_handler import summarize_media_link
from src.handlers.text_handler import summarize_text_link
from src.utils.link_detector import detect_link_type, is_video_link, LinkType
async def scan_video_link(url: str) -> str:
"""
Scan and summarize a video link (YouTube, Instagram Reels, etc.)
Falls back to scan_text_link if video cannot be loaded.
Args:
url: Video URL to scan
Returns:
str: Transcribed text from video, or text content if video fails
"""
# Check if the URL is actually a video link
link_type = detect_link_type(url)
if not is_video_link(link_type):
return f"Error: The provided URL is not a video link. Detected type: {link_type.value}. Please use 'scan_text_link' for text content."
try:
result = await summarize_media_link(url)
# Check if the result indicates failure (no text information or error message)
if result.startswith("Error") or result.startswith("No text information"):
# Fallback to text link scanning
return await scan_text_link(url)
return result
except Exception as e:
# If video processing fails, fallback to text link scanning
return await scan_text_link(url)
async def scan_text_link(url: str) -> str:
"""
Scan and summarize a text link (blogs, articles, etc.)
Args:
url: Text URL to scan
Returns:
str: Extracted text content
"""
return await summarize_text_link(url)
def get_scan_video_link_tool() -> Tool:
"""
Get the scan_video_link tool definition
Returns:
Tool: Tool definition
"""
return Tool(
name="scan_video_link",
description="Scan a video link (YouTube, Instagram Reels, etc.) and provide a summary. For YouTube videos, extracts title, description, subtitles (first 7 seconds), and audio transcription. For other videos, extracts audio transcription (first 7 seconds) and summarizes using Llama3.",
inputSchema={
"type": "object",
"properties": {
"url": {
"type": "string",
"description": "Video URL to scan and summarize (YouTube, Instagram Reels, etc.)"
}
},
"required": ["url"]
}
)
def get_scan_text_link_tool() -> Tool:
"""
Get the scan_text_link tool definition
Returns:
Tool: Tool definition
"""
return Tool(
name="scan_text_link",
description="Scan a text link (blogs, articles, etc.) and provide a summary. Extracts text content from web pages.",
inputSchema={
"type": "object",
"properties": {
"url": {
"type": "string",
"description": "Text URL to scan and summarize (blogs, articles, etc.)"
}
},
"required": ["url"]
}
)