See llms.txt for all machine-readable content.

Back to Templates

Analyze YouTube niche trends with Apify and OpenAI

Quick overview

This workflow runs manually to find this week’s most popular YouTube videos for a niche using Apify, collects top comments from the highest-viewed videos, and uses OpenAI to produce a concise audience insight report with themes, questions, complaints, and video ideas.

How it works

  1. Runs when you execute the workflow manually in n8n.
  2. Sends a request to Apify’s sedgelabs/youtube-search-scraper actor to fetch up to 20 US YouTube videos uploaded this week for the specified niche query.
  3. Sorts the results by view count and keeps the top N videos based on your topVideos setting.
  4. Sends the selected video URLs to Apify’s sedgelabs/youtube-comments-scraper actor to retrieve up to maxComments top comments per video.
  5. Groups and trims the comments into a size-capped prompt and asks OpenAI to generate a plain-text report of themes, viewer questions, common complaints, and video ideas using only the provided comments.
  6. Outputs a final JSON report containing the niche, the top videos list, the number of comments analysed, and the OpenAI-generated summary.

Setup

  1. Create an Apify account, generate an API token, and add an n8n Header Auth credential that sends Authorization: Bearer <token> for the Apify HTTP requests.
  2. Add an OpenAI API key credential in n8n and select it on the OpenAI node.
  3. Update the Settings values (niche, topVideos, maxComments, and openaiModel) to match the topic and output size you want, then execute the workflow.

Requirements

  • An Apify account with an API token, and an OpenAI API key. A run costs at most about $0.33 on Apify, plus the OpenAI call.

Customization

  • Keep the niche phrase tight: a broad one can pull in brand or celebrity videos that only mention the topic.

Additional info

By Sedge Labs (sedgelabs.dev). Actors: YouTube Search Scraper (https://apify.com/sedgelabs/youtube-search-scraper) and YouTube Comments Scraper (https://apify.com/sedgelabs/youtube-comments-scraper). The workflow uses built-in n8n nodes only.