YouTube Trend Data Aggregator Sub-Workflow - n8n Workflow

Use this powerful n8n workflow to automatically search YouTube for recent videos, filter by length, and extract sanitized metadata for trend analysis. A highly efficient component for larger n8n templates.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Content Marketers: Automating competitive analysis and identifying emerging content trends.
Data Analysts: Needing structured, cleaned YouTube data for ingestion into databases or analytics platforms.
AI Developers: Preparing clean, aggregated text data (descriptions, titles, tags) for large language models (LLMs).
n8n Automation Specialists: Users looking for advanced examples of flow control, data sanitization, and sub-workflow construction within n8n.

Overview

Spotting fast-moving trends on platforms like YouTube requires rapid, systematic data extraction. This specific n8n workflow is designed as a reusable sub-component to solve the challenge of efficiently gathering comprehensive statistics and textual data (like descriptions and tags) from newly uploaded videos relevant to a search query.

Triggered by a primary parent workflow, this n8n workflow executes a focused search, limiting results to videos published within the last 48 hours. Critically, it uses an If n8n node to filter out excessively short content (like Shorts or clips under 3.5 minutes), ensuring the collected data is relevant for long-form content trend analysis. The gathered information is sanitized using custom JavaScript code, stripping out URLs and emojis, making the final output perfectly clean for processing by LLMs or further analysis in other n8n templates. This optimization significantly reduces processing load and improves the quality of data ingested by the next steps in your master n8n workflow.

How it Works

This automation acts as a sub-routine, starting with the When Executed by Another Workflow n8n trigger. This specialized n8n trigger waits for execution signals and input parameters from a parent workflow, specifically receiving a search_term query.


  1. Search & Filter: The Youtube - Get Video n8n node executes a search using the provided term, limiting results to three recent videos (published within the last two days).

  2. Iterate: The Loop Over Items n8n node processes each video result individually.

  3. Detailed Lookup: The HTTP - Find Video Data n8n node performs a second API call using the video ID to retrieve complete statistics and content details, which are not available in the initial search results.

  4. Duration Check: The If - Longer Than 3 n8n node applies a crucial filter. It uses JavaScript logic to parse the ISO 8601 duration and only continues the workflow if the video is longer than 210 seconds (3 minutes 30 seconds).

  5. Data Structuring: The Field - Group Data n8n node structures key metrics like viewCount, likeCount, commentCount, description, and title into standardized fields.

  6. Sanitization and Aggregation: The Code - Save Data To Memory n8n node cleans the description data (removing links, emojis, and unnecessary formatting) and writes the entire item object to the workflow's static memory, aggregating all accepted video data into one large JSON string.

  7. Output Generation: Once the loop completes, the Code - Retrieve Data From Memory n8n node retrieves the aggregated string, and the Field - Response n8n node prepares this final output to be passed back to the originating parent n8n workflow.

Installation Guide

To deploy this powerful n8n workflow and start aggregating YouTube data, follow these steps:


  1. Import: Copy the provided JSON code and import it into your n8n instance via the 'Workflows' section by clicking 'New' and 'Import from JSON'.

  2. Credentials: This n8n workflow requires a YouTube OAuth2 API credential. You must set this up and associate it with both the Youtube - Get Video and the HTTP - Find Video Data n8n node.

  3. Setup: Ensure the 'When Executed by Another Workflow' n8n trigger is correctly linked to your main workflow, which must provide the search_term parameter in its input data structure.

  4. Activation: Once credentials are set, activate the n8n workflow. It is designed to be executed by a parent n8n workflow, not run manually.

Node Details

When Executed by Another Workflow (n8n trigger): Initiates the sub-workflow when called by a parent flow, receiving search parameters.
Youtube - Get Video (n8n node): Searches the YouTube API using an input term (search_term). Crucially configured to only look at recent videos (last 48 hours) and retrieve a maximum of 3 results.
HTTP - Find Video Data (n8n node): Uses a raw HTTP request to the YouTube Data API to fetch detailed statistics and content duration, leveraging the same OAuth2 credential.
If - Longer Than 3 (n8n node): A condition n8n node that uses a custom JavaScript expression to filter videos, ensuring the duration is greater than 3.5 minutes (210 seconds).
Code - Save Data To Memory (n8n node): A custom code n8n node that sanitizes the video description (removing URLs, emojis, and line breaks) and aggregates the structured output data into the workflow's static memory for collection upon loop completion.
Field - Group Data (n8n node): A Set n8n node used to map complex API statistics fields (like items[0].statistics.viewCount) into clean, standardized variable names for easier use in subsequent n8n templates.

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by
Agent Circle
Agent Circle

Featured*