n8nCreativeVideoAI score · PendingAI-assisted edit · no obvious prompt-injection riskn8n.io

AI YouTube Trend Finder by Niche

Input a niche keyword → AI generates search terms and calls YouTube API for videos from last 2 days → filter by duration and extract tags/stats → AI summarizes trends and hot topics

Some experienceStepsWorkflowPrompt
Who
YouTube creators and content marketers
You get
Get trending video insights for a niche from the past 2 days, including common themes, tag patterns, and engagement stats
You need
n8n

Constraints

Prerequisites: n8n instance; OpenAI API key; YouTube OAuth2 API credentials (youTubeOAuth2Api). The template includes a main workflow and a YouTube search chain that can be abstracted into a sub-workflow. The AI Agent uses window_buffer_memory for context. The sub-workflow filters videos longer than 3 minutes 30 seconds, cleans descriptions by removing links and emojis, and returns results separated by ### NEXT VIDEO FOUND: ###.

What they did

Template author leonardogrig built an n8n workflow that receives user queries via Chat Trigger, uses a GPT-powered AI Agent to understand the niche and generate search terms, calls an embedded YouTube search sub-workflow to fetch video data from the last 2 days, filters out content shorter than 3 minutes 30 seconds, cleans descriptions and emojis, and returns structured data for the AI Agent to generate a trend insight report.

How it went

Published on n8n.io, the template demonstrates a sample output: for the "digital marketing" niche, the AI identified "mental triggers" and "psychological marketing" as trending topics, with related videos exceeding 200K views (author_report). This site has not tested the actual runtime performance of this workflow.

Worth knowing

1. The sub-workflow referenced by youtube_search (workflowId=N9DveO781xbNf8qs) is an internal template reference; ensure it exists or build an equivalent when deploying. 2. The YouTube node uses OAuth2 credentials; the HTTP Request node relies on the GOOGLE_API_KEY environment variable. 3. The duration filter (>210 seconds) is hardcoded in the If node and must be manually edited to change. 4. Data cleaning (removing links, emojis, extra spaces) runs via Code node on global static data—be aware of concurrency overwrite risks in multi-instance deployments. 5. No ROI or long-term stability data is provided by the source.

n8n workflow template

Structure checked · Not run-tested

Use “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.

Setup and test checklist

Credentials to connect

  • get_videos1 node: connect YouTube OAuth2 credentials.

Configuration to replace

  • Source template is n8n public workflow #2606 (~15 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
  • Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.

Test input and expected output

  • Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
  • Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.

Template changes

  • Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
  • No business-logic edits; verify keys, quotas and privacy compliance before use.

Template retrieved: 2026-10-25

Steps

  1. Configure Chat Trigger

    Add a When chat message received node (chat_message_received) to the workflow. Keep default settings or adjust the webhook path as needed. This node receives the user's niche keyword; if none is provided, the AI Agent will ask for one.

  2. Configure AI Agent and Model

    Add an AI Agent node, connect OpenAI Chat Model (openai_llm) as the language model, and Window Buffer Memory (window_buffer_memory) as memory. In AI Agent Options → System Message, paste the prompt below. This prompt defines the Agent's behavior: validate niche, call youtube_search tool up to 3 times, parse returned data, and generate trend insights.

    Execution prompt · Source text。AI Agent node Options → System Message field

    =You help youtube creators find trending videos based on a specific niche.
    
    Verify if the user informed a niche before doing anything. If not, then ask him for one by giving him suggestions for him to select from.
    
    After you know what type of content the user might produce, use the "youtube_search" tool up to 3 times with different search terms based on the user's content type and niche.
    
    The tool will answer with a list of videos from the last 2 days that had the most amount of relevancy. It returns a list of json's covering each video's id, view count, like count, comment count, description, channel title, tags and channel id. Each video is separated by "### NEXT VIDEO FOUND: ###".
    
    You should then proceed to understand the data received then provide the user with insightful data of what could be trending from the past 2 days. Provide the user links to the trending videos which should be in this structure:
    
    https://www.youtube.com/watch?v={video_id}
    
    to reach the channel's link you should use:
    
    https://www.youtube.com/channel/{channel_id}
    
    Find patterns in the tags, titles and especially in the related content for the videos found.
    
    Your mission isn't to find the trending videos. It's to provide the user with valuable information of what is trending in that niche in terms of content news. Remember to provide the user with the numbers of views, likes and comments while commenting about any video. So you should not talk about any particular video, focus rather in explaining the overall senario of all that was found.
    
    Example of response:
    
    "It seems like what is trending in digital marketing right now is talking about mental triggers, since 3 of the most trending videos in the last 2 days were about..."
  3. Configure YouTube Search Sub-workflow

    Add or reference the youtube_search tool workflow (Call n8n Workflow Tool). The sub-workflow chain must include: YouTube node (get_videos1) to search last 2 days → Loop Over Items to batch process → HTTP Request (find_video_data1) for video details → If node to filter duration >210 seconds (3 min 30 sec) → Edit Fields (group_data1) to extract id/viewCount/likeCount/commentCount/description/title/channelTitle/tags/channelId → Code (save_data_to_memory1) to clean and concatenate with ### NEXT VIDEO FOUND: ### → Code (retrieve_data_from_memory1) to read global static data → Edit Fields (response1) to return results. Note: the YouTube node requires youTubeOAuth2Api credentials; the HTTP Request node uses $env.GOOGLE_API_KEY to call YouTube Data API v3.

  4. Run and Verify

    Activate the workflow and input a niche in the Chat Trigger (e.g., "digital marketing"). Observe whether the AI Agent generates up to 3 search term sets, calls youtube_search, and returns a trend summary with video links and engagement stats. If the sub-workflow returns no data, check YouTube API quota, credential validity, and whether search terms are too narrow.

Prompt you can copy

Setup guidance · Editorial suggestion。Setup assistant starter prompt for understanding template structure and configuration order

This block is the prompt. Ads are never placed here.

You are a YouTube content trend analysis assistant. The user will provide a niche or content direction. Your tasks: 1) If no niche is provided, ask and suggest options; 2) Generate up to 3 different search term sets based on the niche; 3) Call the youtube_search tool to fetch related videos from the last 2 days; 4) Analyze returned tags, titles, descriptions, and engagement data (views, likes, comments); 5) Do not focus on individual videos—summarize overall trends, output common themes, tag patterns, trending channel links, and engagement statistics.

Paste the AI Agent systemMessage verbatim into the node System Message field; ensure the youtube_search sub-workflow is correctly referenced or rebuild an equivalent chain.

Source

AI YouTube trend finder based on niche · leonardogrig · n8n.io · 2024-12-05

Comments & feedback

Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.

Loading…

    Related