N
n8n Store
Workflow Market
Youtube Comment Scraper

Youtube Comment Scraper

by amitswba0 views

Description

Categories

🤖 AI & Machine Learning📢 Marketing

Nodes Used

n8n-nodes-base.ifn8n-nodes-base.setn8n-nodes-base.coden8n-nodes-base.coden8n-nodes-base.gmailn8n-nodes-base.limitn8n-nodes-base.youTuben8n-nodes-base.stickyNoten8n-nodes-base.stickyNoten8n-nodes-base.stickyNote
PriceGratuit
Views0
Last Updated11/28/2025
workflow.json
{
  "id": "ItynUguvK0Dx6mw4",
  "meta": {
    "instanceId": "260491e02302632e6a217f5c83135ad573c31ec4f93b05d79785a77df9c4a7e5",
    "templateCredsSetupCompleted": true
  },
  "name": "Youtube Comment Scraper",
  "tags": [],
  "nodes": [
    {
      "id": "workflow-overview-note",
      "name": "Workflow Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -300,
        -250
      ],
      "parameters": {
        "color": 2,
        "width": 350,
        "height": 400,
        "content": "# 📊 YouTube Comment Analyzer Workflow\n\n**Purpose:** Automate YouTube comment collection, sentiment analysis, and email reporting\n\n**Schedule:** Triggers every minute for new/updated rows\n\n**Required Setup:**\n1. Google Sheet with video IDs\n2. YouTube API credentials\n3. OpenAI API key\n4. Gmail account\n\n## Workflow Steps:\n1. **Trigger** - Monitor Google Sheet\n2. **Filter** - Process only 'Pending' videos\n3. **Fetch** - Get video details & comments\n4. **Analyze** - AI sentiment analysis\n5. **Report** - Send email summary\n6. **Update** - Mark as processed"
      },
      "typeVersion": 1
    },
    {
      "id": "trigger-section-note",
      "name": "Trigger Documentation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -50,
        -250
      ],
      "parameters": {
        "color": 3,
        "width": 300,
        "height": 220,
        "content": "## 🚀 Trigger Section\n\n**Google Sheets Trigger**\nMonitors the spreadsheet every minute for:\n- New video IDs added\n- Status changes to 'Pending'\n\n**Required Sheet Structure:**\n| ID | Video Title | YouTube Video ID | Status |\n\n⚠️ Set Status to 'Pending' to trigger analysis"
      },
      "typeVersion": 1
    },
    {
      "id": "youtube-data-note",
      "name": "YouTube API Section",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        770,
        -250
      ],
      "parameters": {
        "color": 1,
        "width": 280,
        "height": 200,
        "content": "## 📹 YouTube Data Collection\n\n**This section fetches:**\n- Video metadata (title, channel)\n- Top 100 comments\n- Comment statistics\n\n**API Limits:**\n- Max 100 comments per request\n- Ordered by relevance\n- Top-level comments only"
      },
      "typeVersion": 1
    },
    {
      "id": "ai-analysis-note",
      "name": "AI Analysis Documentation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1420,
        -280
      ],
      "parameters": {
        "color": 5,
        "width": 320,
        "height": 250,
        "content": "## 🤖 AI Analysis Section\n\n**GPT-4o analyzes comments for:**\n1. Sentiment breakdown (positive/negative/neutral)\n2. Main themes & topics\n3. Common viewer questions\n4. Key feedback points\n5. Actionable insights\n\n**Output Format:** Structured JSON with underscore keys\n\n💡 Customize the prompt in AI Agent node for different analysis needs"
      },
      "typeVersion": 1
    },
    {
      "id": "email-update-note",
      "name": "Email & Status Update",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2036,
        -250
      ],
      "parameters": {
        "color": 4,
        "width": 300,
        "height": 220,
        "content": "## 📧 Email & Update Section\n\n**Email Report includes:**\n- Video statistics\n- Sentiment analysis\n- Key insights\n- Formatted HTML\n\n**Final Step:**\nUpdates Google Sheet status to 'Mail Sent' to prevent duplicate processing\n\n⚠️ Update recipient email in Gmail node"
      },
      "typeVersion": 1
    },
    {
      "id": "data-prep-note",
      "name": "Data Processing Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1270,
        200
      ],
      "parameters": {
        "color": 6,
        "width": 250,
        "height": 180,
        "content": "⚠️ **Data Preparation**\n\nThis node:\n- Extracts comment texts\n- Calculates statistics\n- Performs basic sentiment analysis\n- Prepares data for AI\n\nLimited to 50 comments for AI analysis to manage token usage"
      },
      "typeVersion": 1
    },
    {
      "id": "b5d9ad95-9fcc-4c3d-bf90-42e897ab5eda",
      "name": "Limit",
      "type": "n8n-nodes-base.limit",
      "notes": "Limits processing to 1 item at a time to prevent API overload",
      "position": [
        440,
        0
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "d0f82101-07e6-4559-9b73-91b85dc77b40",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "notes": "Uses OpenAI GPT-4o to analyze comments and generate insights. Customize the prompt for different analysis needs.",
      "position": [
        1540,
        0
      ],
      "parameters": {
        "text": "=Analyze these comments from the video \"{{ $json.videoTitle }}\":\n\nTotal Comments: {{ $json.totalComments }}\nAverage Likes: {{ $json.avgLikes }}\n\nComments to analyze:\n{{ $json.commentTexts }}",
        "options": {
          "maxIterations": 100,
          "systemMessage": "You are a YouTube comment analyst. Analyze the provided comments and return a structured analysis with:\n1. Overall sentiment breakdown (positive/negative/neutral percentages)\n2. Top 3-5 main themes or topics discussed\n3. Common questions from viewers\n4. Key feedback points and suggestions\n5. Actionable insights for content improvement\n\nFormat your response in clear sections with headers in json key value format and use underscore in the key name. Always use following keys for output json: \n1. overall_sentiment_breakdown\n2. main_themes\n3. common_questions\n4. key_feedback_points\n5. actionable_insights"
        },
        "promptType": "define"
      },
      "typeVersion": 1.9
    },
    {
      "id": "e7a9b6ea-af4a-4970-ba0e-3e18608015f5",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1628,
        220
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {
          "responseFormat": "json_object"
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "O2czYITX17GGksaO",
          "name": "OpenAi account 4"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7c22599f-6fa8-4461-9b81-89a283a9dc84",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "notes": "Filters rows to process only videos with 'Pending' status",
      "position": [
        220,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "5f1eae10-5270-4e99-8627-597e3451c82c",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.Status }}",
              "rightValue": "Pending"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "152902fb-d715-4473-972f-4f75e5788b7a",
      "name": "Set Video Details",
      "type": "n8n-nodes-base.set",
      "notes": "Prepares video ID and sets max comments limit (100)",
      "position": [
        660,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "219795ef-daa4-4444-9865-c5d3856be63b",
              "name": "videoId",
              "type": "string",
              "value": "={{ $json['Youtube video id'] }}"
            },
            {
              "id": "cd4f519d-4c84-496c-8974-29ef69c890fc",
              "name": "maxComments ",
              "type": "number",
              "value": 100
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "67bb511b-478c-4fec-ba6a-816d81a8bad1",
      "name": "Get Youtube Video Details",
      "type": "n8n-nodes-base.youTube",
      "notes": "Fetches video metadata including title, channel name, and other details",
      "position": [
        880,
        0
      ],
      "parameters": {
        "options": {},
        "videoId": "={{ $json.videoId }}",
        "resource": "video",
        "operation": "get"
      },
      "credentials": {
        "youTubeOAuth2Api": {
          "id": "2Mya1dm7vKjkxzqb",
          "name": "YouTube account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "880379c3-791a-424f-a170-db214ee0bad0",
      "name": "Get Youtube Video Comments",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "Retrieves top 100 comments ordered by relevance using YouTube API",
      "position": [
        1100,
        0
      ],
      "parameters": {
        "url": "https://www.googleapis.com/youtube/v3/commentThreads",
        "options": {},
        "sendQuery": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "part",
              "value": "snippet"
            },
            {
              "name": "videoId",
              "value": "={{ $('Set Video Details').item.json.videoId }}"
            },
            {
              "name": "maxResults",
              "value": "100"
            },
            {
              "name": "order",
              "value": "relevance"
            }
          ]
        },
        "nodeCredentialType": "youTubeOAuth2Api"
      },
      "credentials": {
        "youTubeOAuth2Api": {
          "id": "2Mya1dm7vKjkxzqb",
          "name": "YouTube account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "4a7f24c6-5dea-400f-8f0b-351597cae840",
      "name": "Prepare Comments Data",
      "type": "n8n-nodes-base.code",
      "notes": "Processes raw comments: extracts text, calculates stats, performs basic sentiment analysis, limits to 50 comments for AI",
      "position": [
        1320,
        0
      ],
      "parameters": {
        "jsCode": "// Get comments from HTTP Request node\nconst comments = $input.first().json.items\n//const comments = response.items || [];\n\n// Get video title from the YouTube node (step 5)\n//const videoData = ;\nconst videoTitle = $('Get Youtube Video Details').first().json.snippet.title;\n\n// Extract comment data\nconst processedComments = comments.map(item => {\n  const comment = item.snippet.topLevelComment.snippet;\n  return {\n    text: comment.textDisplay,\n    author: comment.authorDisplayName,\n    likes: comment.likeCount || 0,\n    publishedAt: comment.publishedAt,\n    replyCount: item.snippet.totalReplyCount || 0\n  };\n});\n\n// Calculate statistics\nconst totalComments = processedComments.length;\nconst totalLikes = processedComments.reduce((sum, c) => sum + c.likes, 0);\nconst avgLikes = totalComments > 0 ? (totalLikes / totalComments).toFixed(2) : 0;\nconst totalReplies = processedComments.reduce((sum, c) => sum + c.replyCount, 0);\n\n// Get top comments by likes\nconst topComments = processedComments\n  .sort((a, b) => b.likes - a.likes)\n  .slice(0, 5);\n\n// Prepare comment texts for AI analysis\nconst commentTexts = processedComments\n  .slice(0, 50) // Limit to 50 comments for AI analysis\n  .map(c => c.text)\n  .join('\\n---\\n');\n\n// Basic sentiment analysis (count positive/negative keywords)\nconst positiveWords = ['love', 'great', 'awesome', 'amazing', 'excellent', 'good', 'fantastic', 'helpful', 'thanks'];\nconst negativeWords = ['hate', 'terrible', 'awful', 'bad', 'worst', 'horrible', 'useless', 'waste'];\n\nlet positiveCount = 0;\nlet negativeCount = 0;\n\nprocessedComments.forEach(comment => {\n  const lowerText = comment.text.toLowerCase();\n  positiveWords.forEach(word => {\n    if (lowerText.includes(word)) positiveCount++;\n  });\n  negativeWords.forEach(word => {\n    if (lowerText.includes(word)) negativeCount++;\n  });\n});\n\nreturn [{\n  json: {\n    videoTitle,\n    totalComments,\n    avgLikes,\n    totalReplies,\n    topComments,\n    commentTexts,\n    processedComments,\n    sentimentCounts: {\n      positive: positiveCount,\n      negative: negativeCount,\n      neutral: totalComments - positiveCount - negativeCount\n    }\n  }\n}];\n\n"
      },
      "typeVersion": 2
    },
    {
      "id": "06ddd27a-242e-4975-82e4-2795af0252a7",
      "name": "Prepare HTML for Email",
      "type": "n8n-nodes-base.code",
      "notes": "Converts AI analysis into formatted HTML email with statistics, insights, and professional styling",
      "position": [
        1916,
        0
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const output = JSON.parse($json.output)\n //return output; \n//return output.overall_sentiment_breakdown.Positive;\n\nlet common_question = \"\";\n  \noutput.common_questions.map(rec => {\n  return common_question += \"<li>\"+rec.trim().replace(new RegExp(\".*,$\"), \"\")+\"</li>\"\n})\n\nlet key_feedback_points_and_suggestions = \"\";\n\noutput.key_feedback_points.map(rec => {\n  return key_feedback_points_and_suggestions += \"<li>\"+rec.trim().replace(new RegExp(\".*,$\"), \"\")+\"</li>\"\n})\n\n\nlet actionable_insights_for_content_improvement = \"\"\n\noutput.actionable_insights.map(rec => {\n  return actionable_insights_for_content_improvement += \"<li>\"+rec.trim().replace(new RegExp(\".*,$\"), \"\")+\"</li>\"\n})\n\n\n// return {common_question};\n\n\n     \n\n//return output; \n// Generate the email HTML\nconst emailHTML = `\n<!DOCTYPE html>\n<html>\n<head>\n  <style>\n    body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }\n    .header { background: #f4f4f4; padding: 20px; border-radius: 5px; }\n    .section { margin: 20px 0; }\n    .stats { background: #e9ecef; padding: 15px; border-radius: 5px; }\n    .analysis { background: #f8f9fa; padding: 20px; border-radius: 5px; }\n    h2 { color: #2c3e50; }\n    h3 { color: #34495e; }\n    h4 { color: #7f8c8d; }\n    .footer { margin-top: 30px; padding-top: 20px; border-top: 1px solid #ddd; color: #666; font-size: 0.9em; }\n  </style>\n</head>\n<body>\n  <div class=\"header\">\n    <h2>YouTube Comments Analysis Report</h2>\n    <h3>Video: ${$(\"Prepare Comments Data\").item.json.videoTitle}</h3>\n  </div>\n\n  <div class=\"section stats\">\n    <h3> Quick Statistics</h3>\n    <ul>\n      <li><strong>Total Comments Analyzed:</strong> ${$('Prepare Comments Data').item.json.totalComments}</li>\n      <li><strong>Average Likes per Comment:</strong> ${$('Prepare Comments Data').item.json.avgLikes}</li>\n      <li><strong>Total Replies:</strong> ${$('Prepare Comments Data').item.json.totalReplies}</li>\n      <li><strong>Sentiment Summary:</strong> \n        Positive: ${output.overall_sentiment_breakdown.positive}, \n        Negative: ${output.overall_sentiment_breakdown.negative}, \n        Neutral: ${output.overall_sentiment_breakdown.neutral}\n      </li>\n    </ul>\n  </div>\n\n  <div class=\"section stats\">\n    <h3>Common Questions</h3>\n    <ul>\n      ${common_question}\n    </ul>\n  </div>\n\n    <div class=\"section stats\">\n    <h3>Key feedback points and suggestions</h3>\n    <ul>\n      ${key_feedback_points_and_suggestions}\n    </ul>\n  </div>\n\n\n  <div class=\"section stats\">\n    <h3>Actionable insights for content improvement</h3>\n    <ul>\n      ${actionable_insights_for_content_improvement}\n    </ul>\n  </div>\n\n\n\n\n  <div class=\"footer\">\n    <p><em>Report generated on ${new Date().toLocaleString()}</em></p>\n    \n  </div>\n</body>\n</html>`;\n\n\n// Return the formatted data\nreturn  {\n  json: {\n    emailHTML,\n    subject: `YouTube Analysis: ${$('Prepare Comments Data').item.json.videoTitle} - ${$('Prepare Comments Data').item.json.totalComments} comments analyzed`,\n    videoTitle: $('Prepare Comments Data').item.json.videoTitle\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "2c28a815-1e36-47ab-a96c-a3c040f60551",
      "name": "Gmail Account Configuration",
      "type": "n8n-nodes-base.gmail",
      "notes": "Sends formatted analysis report via Gmail. Update SENDER_EMAIL_ADDRESS with actual recipient",
      "position": [
        2136,
        0
      ],
      "webhookId": "90b8f9ad-4226-42a0-971b-7fa9f5f190bd",
      "parameters": {
        "sendTo": "SENDER_EMAIL_ADDRESS",
        "message": "={{ $json.emailHTML }}",
        "options": {},
        "subject": "={{ $json.subject }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "JYZ1uo6n4Jnfozjt",
          "name": "Gmail account 3"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "1303d6f5-d8a8-44ea-b062-ba25dbb43e6e",
      "name": "Update Status on Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "notes": "Updates video status to 'Mail Sent' to prevent duplicate processing",
      "position": [
        2356,
        0
      ],
      "parameters": {
        "columns": {
          "value": {
            "Id": "={{ $('Pick Video Ids from Google sheet').item.json.Id }}",
            "Status": "Mail Sent"
          },
          "schema": [
            {
              "id": "Id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Youtube video id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Youtube video id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "GOOGLE_DRIVE_URL",
          "cachedResultName": "Youtube_Video "
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1qe6Ovp_pfmwZA2k5c7LmmZx-OKqv3hnu8Dg80Pw4KoY",
          "cachedResultUrl": "GOOGLE_DRIVE_URL",
          "cachedResultName": "Youtube_Video"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "ApqY25iiOci0QMVA",
          "name": "Google Sheets account 4"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "f9028f08-170b-4d2f-8c6b-b1dbf470d3a3",
      "name": "Pick Video Ids from Google sheet",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "notes": "Triggers on new YouTube videos added to spreadsheet. Polls every minute for changes",
      "position": [
        0,
        0
      ],
      "parameters": {
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "GOOGLE_DRIVE_URL",
          "cachedResultName": "Youtube_Video "
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1qe6Ovp_pfmwZA2k5c7LmmZx-OKqv3hnu8Dg80Pw4KoY",
          "cachedResultUrl": "GOOGLE_DRIVE_URL",
          "cachedResultName": "Youtube_Video"
        }
      },
      "credentials": {
        "googleSheetsTriggerOAuth2Api": {
          "id": "qr4PWvkowXONSaw4",
          "name": "Google Sheets Trigger account 4"
        }
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "be4e97c1-bc7f-4a62-bd2a-f636c65fd256",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit": {
      "main": [
        [
          {
            "node": "Set Video Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Prepare HTML for Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set Video Details": {
      "main": [
        [
          {
            "node": "Get Youtube Video Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Comments Data": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare HTML for Email": {
      "main": [
        [
          {
            "node": "Gmail Account Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Youtube Video Details": {
      "main": [
        [
          {
            "node": "Get Youtube Video Comments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Youtube Video Comments": {
      "main": [
        [
          {
            "node": "Prepare Comments Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Account Configuration": {
      "main": [
        [
          {
            "node": "Update Status on Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Status on Google Sheet": {
      "main": [
        []
      ]
    },
    "Pick Video Ids from Google sheet": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

相关工作流