Ever wonder how your competitors consistently rank on the first page of YouTube search?
It's not just about the thumbnail or the title. It's about the hidden metadata—specifically, the tags they use. YouTube hides these tags from the standard user interface, but they are still embedded in the page source and accessible via API.
In this tutorial, I'll show you how to build a Python script that extracts the hidden tags from any YouTube video, analyzes the most frequently used tags across a competitor's channel, and helps you optimize your own video SEO.
What We're Building
We'll build a Python tool that:
- Takes a competitor's YouTube channel URL.
- Fetches their most recent videos.
- Extracts the hidden tags for each video.
- Counts the frequency of each tag to reveal their SEO strategy.
The Problem with Official APIs
You could use the official YouTube Data API v3. But there's a catch:
- It requires OAuth setup.
- The quota limits are extremely strict (fetching video details costs a lot of quota).
- Getting approved for a production app is a nightmare.
Instead, we'll use the SociaVault API, which provides a simple REST endpoint to get YouTube video details without worrying about quotas, proxies, or API keys.
Prerequisites
- Python 3.8+
-
requestslibrary (pip install requests) -
pandaslibrary (pip install pandas) - A SociaVault API key (Get 1,000 free credits at sociavault.com)
Step 1: Fetching Channel Videos
First, we need to get the latest videos from a competitor's channel.
import requests
import pandas as pd
from collections import Counter
API_KEY = 'your_sociavault_api_key'
BASE_URL = 'https://api.sociavault.com/v1/youtube'
headers = {
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'
}
def get_channel_videos(channel_username, max_results=20):
print(f"Fetching videos for {channel_username}...")
response = requests.get(
f"{BASE_URL}/channel/videos",
headers=headers,
params={'username': channel_username, 'limit': max_results}
)
if response.status_code == 200:
return response.json().get('data', [])
else:
print(f"Error: {response.text}")
return []
Step 2: Extracting Hidden Tags
Now that we have the video IDs, we can fetch the detailed metadata for each video, which includes the hidden tags.
def get_video_tags(video_id):
response = requests.get(
f"{BASE_URL}/video/info",
headers=headers,
params={'video_id': video_id}
)
if response.status_code == 200:
data = response.json().get('data', {})
# SociaVault returns tags as a list of strings
return data.get('tags', [])
return []
Step 3: Analyzing the Tag Strategy
Let's tie it all together. We'll fetch the videos, extract the tags, and use Python's Counter to find the most common tags.
def analyze_competitor_tags(channel_username):
videos = get_channel_videos(channel_username)
if not videos:
return
all_tags = []
video_data = []
for video in videos:
video_id = video['id']
title = video['title']
views = video['view_count']
print(f"Analyzing: {title[:30]}...")
tags = get_video_tags(video_id)
all_tags.extend(tags)
video_data.append({
'Title': title,
'Views': views,
'Tag Count': len(tags),
'Tags': ", ".join(tags[:5]) + "..." if tags else "None"
})
# Calculate most common tags
tag_counts = Counter(all_tags)
top_tags = tag_counts.most_common(15)
# Print Results
print("\n" + "="*50)
print(f"TAG ANALYSIS FOR: {channel_username}")
print("="*50)
print("\nTop 15 Most Used Tags:")
for tag, count in top_tags:
print(f"- {tag}: used in {count} videos")
# Save to CSV for further analysis
df = pd.DataFrame(video_data)
df.to_csv(f"{channel_username}_tag_analysis.csv", index=False)
print(f"\nDetailed video data saved to {channel_username}_tag_analysis.csv")
# Run the analyzer
if __name__ == "__main__":
analyze_competitor_tags("mkbhd") # Replace with your competitor
The Output
When you run this script, you'll get a clear view of exactly what keywords your competitor is targeting:
Fetching videos for mkbhd...
Analyzing: Apple Vision Pro Review...
Analyzing: Samsung Galaxy S24 Ultra...
Analyzing: The Truth About AI Pins...
==================================================
TAG ANALYSIS FOR: mkbhd
==================================================
Top 15 Most Used Tags:
- tech: used in 20 videos
- mkbhd: used in 20 videos
- review: used in 18 videos
- smartphone: used in 15 videos
- apple: used in 12 videos
- android: used in 10 videos
- marques brownlee: used in 10 videos
- 4k: used in 8 videos
- camera test: used in 7 videos
- unboxing: used in 6 videos
Why This Matters for SEO
By analyzing a competitor's tags, you can:
- Find "Seed" Keywords: Discover broad topics you might have missed.
- Identify Long-Tail Keywords: See the specific, multi-word phrases they use to capture niche search traffic.
- Understand Their Branding: Notice how often they use their own name vs. generic terms.
Scaling Up
If you want to turn this into a SaaS product (like a TubeBuddy or VidIQ alternative), you can easily scale this script using SociaVault.
SociaVault handles all the proxy rotation, YouTube layout changes, and rate limits. You just make a simple REST API call and get clean JSON back.
Get your free API key at SociaVault.com and start building your YouTube SEO tool today.
Top comments (0)