AI Automation – YOUTUBE Video Ideas from COMMENTS

In this tutorial, you will learn how to make a magic workflow using n8n. It will automatically give you cool YouTube video ideas by reading the comments on your channel!

Node 1:

Add “Schedule Trigger” node

Node 2:

Add “Youtube” node with following options selected:

  • Resource: Playlist Item
  • Operation: Get Many
  • Playlist Name or ID: (Select your playlist)

Don’t forget to add your Credentials and watch the video I showed you!

Node 3:

Add “Code” node and name it “video-ids” with following code:

return $input.all().map(item => ({ videoId: item.json.snippet.resourceId.videoId, videoTitle: item.json.snippet.title }));

Node 4:

Add “HTTP Request” node with following settings:

  • Method: Get
  • URL: https://www.googleapis.com/youtube/v3/commentThreads
  • Authentication: Predefined Credentials Type
  • Credential Type: Youtube OAuth2 API
  • YouTube OAuth2 API: (Select your credentials which you created for Node 2)

Toggle on “Send Query Parameters” with following settings:

  • Specify Query Parameters: Using Fields Below
  • Name: videoId
  • Value: (drag and drop your video-id)
  • Name: part
  • Value: snippet
  • Name: maxResults
  • Value: Acceptable values are 1 to 100, inclusive. The default value is 20.

Node 5:

Add “Code” node with following code:


const commentItems = $input.all();

const videoItems = $('video-ids').all();

const results = [];


for (let i = 0; i < commentItems.length; i++) {

  const currentCommentItem = commentItems[i].json;
  
  const correspondingVideoItem = videoItems[i].json;
  const videoTitle = correspondingVideoItem.videoTitle;

  const commentThreads = currentCommentItem.items || [];

  for (const thread of commentThreads) {
    const topComment = thread.snippet.topLevelComment;
    const commentData = {
      videoTitle: videoTitle, 
      publishedAt: topComment.snippet.publishedAt,
      author: topComment.snippet.authorDisplayName,
      videoId: topComment.snippet.videoId,
      text: topComment.snippet.textDisplay,
      hasReplies: thread.snippet.totalReplyCount > 0,
    };
    results.push({ json: commentData });

    if (thread.replies && thread.replies.comments) {
      for (const reply of thread.replies.comments) {
        const replyData = {
          videoTitle: videoTitle,
          publishedAt: reply.snippet.publishedAt,
          author: reply.snippet.authorDisplayName,
          videoId: reply.snippet.videoId,
          text: reply.snippet.textDisplay,
          hasReplies: false,
        };
        results.push({ json: replyData });
      }
    }
  }
}

return results;

Node 6:

Add “Google Sheet” node and map all the columns as per the data of last node

Node 7:

Add “Code” node with the following code:

const items = $input.all();
let allCommentsText = "";

for (const item of items) {
  const videoTitle = item.json.videoTitle || 'N/A';
  const commentText = item.json.text || 'N/A';
  
  allCommentsText += `Video: "${videoTitle}"\nComment: "${commentText}"\n---\n`;
}

// Yeh check karega ke agar comments na hon to workflow ruk jaye
if (allCommentsText.length === 0) {
  return []; // Return empty array to stop workflow
}

return [{ json: { formattedComments: allCommentsText } }];

Node 8:

Add “AI Agent” node with the following prompt:

You are a YouTube content strategist for my channel "WebSensePro".

Analyse the following comments and identify the TOP 5 most requested video topics for next week.

Make each title SEO-optimized, and start with "How to".

{{ $json.formattedComments }}

Connect your choice of LLM for e.g “openAI” and toggle on “Require Specific Output Format” option with the following structure:

{
    "video1": "Video 1 Title",
    "video2": "Video 2 Title",
    "video3": "Video 3 Title",
    "video4": "Video 4 Title",
    "video5": "Video 5 Title"
}

Node 9:

Add “Gmail” email node with following email body to send:

Hi, <br><br>

I am your AI Agent and I suggest you should create following videos as per analysis of your audience comments which I did this week. <br><br>

Video 1: {{ $json.output.video1 }} <br>
Video 2: {{ $json.output.video2 }} <br>
Video 3: {{ $json.output.video3 }} <br>
Video 4: {{ $json.output.video4 }} <br>
Video 5: {{ $json.output.video5 }} <br> <br>

Thanks!
5/5 - (5 votes)

About

Leave a Comment

Your email address will not be published. Required fields are marked *