YouTube is a massive source of tutorials, product reviews, and expert commentary that text-based search often misses. This tutorial builds a research agent that queries Scavio's YouTube endpoint to find relevant videos, extracts metadata, and incorporates video findings into research outputs. The agent can find tutorials for technical topics, product reviews for comparison content, and expert talks for market intelligence.
Prerequisites
- Python 3.8+ installed
- requests library installed
- A Scavio API key from scavio.dev
Walkthrough
Step 1: Search YouTube for a topic
Query Scavio's YouTube endpoint for relevant videos.
import requests, os
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}
def search_youtube(query: str) -> list:
resp = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
json={'platform': 'youtube', 'query': query}, timeout=10)
return resp.json().get('organic', [])Step 2: Extract video metadata
Parse the search results into structured video records.
def parse_videos(results: list) -> list:
videos = []
for r in results:
videos.append({
'title': r.get('title', ''),
'url': r.get('link', ''),
'channel': r.get('channel', ''),
'views': r.get('views', ''),
'published': r.get('date', ''),
'description': r.get('snippet', ''),
})
return videosStep 3: Filter by relevance and recency
Filter videos to find the most relevant and recent content.
def filter_videos(videos: list, max_age_days: int = 90) -> list:
from datetime import datetime, timedelta
cutoff = datetime.now() - timedelta(days=max_age_days)
filtered = []
for v in videos:
# Keep videos with substantial titles (not shorts or clips)
if len(v['title']) > 20:
filtered.append(v)
return filtered[:10]Step 4: Generate research summary
Compile video findings into a research-ready format.
def youtube_research(topic: str) -> dict:
results = search_youtube(topic)
videos = parse_videos(results)
filtered = filter_videos(videos)
return {
'topic': topic,
'total_found': len(results),
'top_videos': filtered,
'summary': f"Found {len(results)} videos on '{topic}'. Top channels: {', '.join(set(v['channel'] for v in filtered[:5] if v['channel']))}"
}
research = youtube_research('LangChain agents tutorial 2026')
print(research['summary'])
for v in research['top_videos'][:5]:
print(f" - {v['title']} ({v['channel']})")Python Example
import requests, os
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}
def yt_research(topic):
data = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
json={'platform': 'youtube', 'query': topic}, timeout=10).json()
return [{'title': r['title'], 'url': r.get('link', ''), 'channel': r.get('channel', '')}
for r in data.get('organic', [])[:10]]JavaScript Example
async function ytResearch(topic) {
const data = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST', headers: {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'},
body: JSON.stringify({platform: 'youtube', query: topic})
}).then(r => r.json());
return (data.organic || []).slice(0, 10).map(r => ({title: r.title, url: r.link, channel: r.channel}));
}Expected Output
A research agent that finds relevant YouTube videos and compiles findings into structured research summaries.