Classify YouTube videos & generate email summaries with GPT-4 and Gmail
# Classify YouTube Trends and Generate Email Summaries with GPT-4 and Gmail






Monitor YouTube channels, fetch stats, classify videos as viral (≥ 1000 likes) or normal, and auto‑generate LinkedIn/email summaries with GPT‑4. Deliver via Gmail or SMTP. Clear node names, examples, and auditable fields.
---
## 🎯 Overview
This template monitors YouTube channels via **RSS** or the **YouTube Data API**, retrieves video stats, classifies each video as **viral** (≥ 1000 likes) or **normal**, and produces concise LinkedIn/email summaries with **OpenAI (GPT‑4 family)**. It can send a compact weekly briefing via **Gmail (OAuth2)** or **SMTP**. Built for creators, marketing teams, and agencies who want automated trend alerts and ready‑to‑use content.
<a href="https://postimg.cc/cKsrVC7x" target="_blank"><img src="https://i.postimg.cc/cKsrVC7x/Screenshot-2025-10-16-085219.png" alt="Screenshot-2025-10-16-085219" /></a>
This screenshot shows the Gmail-ready weekly briefing generated by the **Generate Weekly Briefing (HTML)** node in my YouTube Trend Detector workflow, confirming the end-to-end pipeline: RSS/API → stats → like-based classification (≥ 1000 = viral) → LLM summaries → HTML email.
---
## 🧭 How It Works (Node Map)
1. **Manual Run** – ad‑hoc execution
2. **Set Channel IDs** – provide one or more YouTube `channelId` values
3. **Split Channels** – process channels one by one
4. **Fetch Latest Videos (RSS)** – pull recent uploads via channel RSS
5. **Filter: Published in Last 72h** – only recent items are kept
6. **Get Video Stats (YouTube API)** – request `snippet,statistics` for likes and details
7. **Classify by Likes (Code)** – sets `classification` to `viral` or `normal`
8. **Branch: Normal / Branch: Viral** – separate LLM prompts per relevance
9. **Write Post (Normal / Viral)** – generate LinkedIn‑style notes via OpenAI
10. **Aggregate Posts for Briefing** – merge all texts into one block
11. **Generate Weekly Briefing (HTML)** – produce a Gmail‑robust HTML email via GPT
12. **Send Weekly Briefing (Gmail/SMTP)** – deliver briefing (you set recipients)
---
## ⚙️ Quick Start (≈ 3 minutes)
1. **Import** the sanitized JSON into n8n (Menu → Import).
2. **Create credentials** (use exact names):
- `YouTube_API_Key` — Generic credential (field: `apiKey`)
- `OpenAi account` — OpenAI API Key
- `Gmail account` (OAuth2) **or** `SMTP_Default` (SMTP)
3. **Configure channels:** In **Set Channel IDs**, list your YouTube `channelId` values (e.g., `UC…`).
4. **Set recipients:** In **Send Weekly Briefing**, add your target email(s).
5. **Test:** Run **Execute Workflow** and review outputs from the LLM and send nodes.
---
## 🔑 Required Credentials
- **YouTube_API_Key** — YouTube Data API v3 key (field `apiKey`)
- **OpenAi account** — OpenAI API key for LLM nodes
- **Gmail account** (OAuth2, recommended) **or** **SMTP_Default** (server/port/TLS + app password if 2FA)
---
## 🧩 Key Parameters & Adjustments
- **Viral threshold:** In `Classify by Likes (Code)` → `const THRESHOLD = 1000;`
- **YouTube API parts:** Use `part=snippet,statistics` to obtain `likeCount`
- **Time window:** The filter keeps videos from the **last 72 hours**
---
## 🧪 Troubleshooting
- **Missing `likeCount` / `classification = "unknown"`** → ensure `part=statistics` and a valid API key credential.
- **Gmail OAuth `redirect_mismatch` / `access_denied`** → redirect must be `https://<your-n8n-host>/rest/oauth2-credential/callback` and test users added if restricted.
- **SMTP auth issues** → set correct server/port/TLS and use an app password when 2FA is enabled.
- **Empty LLM output** → verify OpenAI key/quota and inspect node logs.
---
## 🧾 Example Outputs
**1) Classification (single video)**
```json
{
"videoId": "abc123XYZ",
"title": "How to Ship an n8n Workflow with OpenAI",
"likeCount": 1587,
"classification": "viral",
"needsStatsFetch": false
}
```
**2) LinkedIn draft (viral)**
```
Did you know how much faster prompt workflows get with structured inputs?
• Setup: n8n + YouTube API + OpenAI for auto-briefs
• Tip: include `part=statistics` for reliable like counts
Useful for teams tracking trending how-to content.
What’s your best “viral” signal besides likes?
#n8n #YouTubeAPI #OpenAI #Automation #Growth
```
**3) Plain‑text email preview**
```
Subject: Weekly AI Briefing — YouTube Trend Highlights
Hi team,
Highlights from our tracked channels:
• Viral: “How to Ship an n8n Workflow with OpenAI” (1.6k likes)
• Normal: “RSS vs API: What’s Best for Monitoring?”
Generated via n8n + GPT‑4.
```
---
## ✅ Submission Checklist (meets the guidelines)
- **Title clarity:** Mentions **GPT‑4** and **Gmail**
- **Language:** Entire document in **English**
- **Node naming:** Descriptive, non‑generic labels
- **HTML → Markdown:** No HTML in this description; badges are **Markdown images**
- **Examples:** Included (JSON, LinkedIn draft, email)
- **Security:** No secrets in JSON; uses credentials by name
---
## 📸 Suggested Screenshots (optional)
1. Full canvas overview (entire workflow)
2. LLM output (expanded) showing generated summary
3. Send‑node result with messageId/status
4. Optional: aggregated briefing preview
---
## 📜 License & Support
**License:** MIT
**Support/Contact:** [email protected]