YouTube Video Analyzer with AI

工作流概述

这是一个包含21个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "G3yjjk93c1bBM5tc",
  "meta": {
    "instanceId": "a4bfc93e975ca233ac45ed7c9227d84cf5a2329310525917adaf3312e10d5462",
    "templateCredsSetupCompleted": true
  },
  "name": "YouTube Video Analyzer with AI",
  "tags": [],
  "nodes": [
    {
      "id": "fbf55337-4b64-43f5-9fed-a08b4ab43a8c",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -80,
        -160
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "48f88f6d-9817-4984-beb0-e37fff747317",
      "name": "YouTube Video ID",
      "type": "n8n-nodes-base.code",
      "position": [
        360,
        -160
      ],
      "parameters": {
        "jsCode": "const extractYoutubeId = (url) => {
  // Regex pattern that matches both youtu.be and youtube.com URLs
  const pattern = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^\"&?\/\s]{11})/;
  const match = url.match(pattern);
  return match ? match[1] : null;
};

// Input URL from previous node
const youtubeUrl = items[0].json.youtubeUrl; // Adjust this based on your workflow

// Process the URL and return the video ID
return [{
  json: {
    videoId: extractYoutubeId(youtubeUrl)
  }
}];
"
      },
      "typeVersion": 2
    },
    {
      "id": "88b5df30-064a-4735-9753-96ca7c272642",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1520,
        140
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "CDX6QM4gLYanh0P4",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "1b7c052d-445e-476d-97be-24f7f625af69",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        1520,
        300
      ],
      "parameters": {
        "model": "deepseek/deepseek-r1:free",
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "id": "pb06rfB4xmxzVe3Q",
          "name": "OpenRouter"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "afc522d2-50ff-49a2-a192-a26c4ae7057d",
      "name": "DeepSeek Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
      "position": [
        1520,
        -40
      ],
      "parameters": {
        "model": "deepseek-reasoner",
        "options": {}
      },
      "credentials": {
        "deepSeekApi": {
          "id": "sxh1rfZxonXV83hS",
          "name": "DeepSeek account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "444ca87e-e9c6-4841-b868-f51474a36f8f",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1720,
        -40
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{
	\"type\": \"object\",
	\"properties\": {
		\"title\": {
			\"type\": \"string\"
		},
		\"text\": {
			\"type\": \"string\"
		}
	}
}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "f5e30fba-d13a-492e-b7d9-e6006436af87",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        540,
        -240
      ],
      "parameters": {
        "width": 220,
        "height": 260,
        "content": "Get a FREE API on youtube-transcript.io and insert the Authentication"
      },
      "typeVersion": 1
    },
    {
      "id": "16335cd6-2ad1-4d2a-a908-68e6908f2ecc",
      "name": "Send Email",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        1900,
        -220
      ],
      "webhookId": "12b73cc6-5aa0-44f4-8e5b-96aea0e59300",
      "parameters": {
        "text": "={{ $json.output.text }}",
        "options": {},
        "subject": "={{ $json.output.title }}",
        "emailFormat": "text"
      },
      "credentials": {
        "smtp": {
          "id": "hRjP3XbDiIQqvi7x",
          "name": "SMTP info@n3witalia.com"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "59170266-f914-4e7c-805c-0014ca2f77de",
      "name": "Generate transcript",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        600,
        -160
      ],
      "parameters": {
        "url": "=https://www.youtube-transcript.io/api/transcripts",
        "method": "POST",
        "options": {},
        "jsonBody": "={ 
  \"ids\": [\"{{ $json.videoId }}\"] 
} ",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "RfHIslxMFRjQZ043",
          "name": "Youtube Transcript Extractor API"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "d73aef68-ad5f-4cca-85fb-cb2cb4ac110a",
      "name": "Exist?",
      "type": "n8n-nodes-base.if",
      "position": [
        1060,
        -160
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "3aefe867-1533-41e5-b5e9-e0fb94eed082",
              "operator": {
                "type": "array",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.transcript }}",
              "rightValue": "null"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "133529a4-dd56-4454-8862-053f63c04687",
      "name": "Analyze LLM Chain",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1540,
        -220
      ],
      "parameters": {
        "text": "={{ $json.fulltext }}",
        "messages": {
          "messageValues": [
            {
              "message": "=Please analyze the given text and create a structured summary following these guidelines:

1. Insert what is requested in a json in the \"text\" variable and also generate a title that will be inserted in the \"title\" variable of the response json.
2. Under each header:
   - List only the most essential concepts and key points
   - Use bullet points for clarity
   - Keep explanations concise
   - Preserve technical accuracy
   - Highlight key terms in bold
3. Organize the information in this sequence:
   - Definition/Background
   - Main characteristics
   - Implementation details
   - Advantages/Disadvantages
4. Format requirements:
   - Use markdown formatting
   - Keep bullet points simple (no nesting)
   - Bold important terms 
   - Use tables for comparisons
   - Include relevant technical details

Please provide a clear, structured summarythat captures the core concepts while maintaining technical accuracy."
            }
          ]
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.5
    },
    {
      "id": "ec77b844-125b-40e3-bc49-0f4b89aed427",
      "name": "Set YouTube URL",
      "type": "n8n-nodes-base.set",
      "position": [
        120,
        -160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "3ee42e4c-3cee-4934-97e7-64c96b5691ed",
              "name": "youtubeUrl",
              "type": "string",
              "value": "=https://youtu.be/VIDEOID"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "10080965-e266-48ca-8a8c-934e76cfa127",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        -240
      ],
      "parameters": {
        "width": 220,
        "height": 260,
        "content": "Get the Youtube video ID from the URL"
      },
      "typeVersion": 1
    },
    {
      "id": "0ab1ae8d-dad8-4795-9f67-9252370ee8ce",
      "name": "Get transcript",
      "type": "n8n-nodes-base.set",
      "position": [
        840,
        -160
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d7dab19f-0275-4454-a270-420f20090d9b",
              "name": "transcript",
              "type": "array",
              "value": "={{ $json.tracks[0].transcript }}"
            },
            {
              "id": "ec7da104-7c1e-4a60-8e94-73cd9cbdc930",
              "name": "language",
              "type": "string",
              "value": "={{ $json.tracks[0].language }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "971ccc67-3fd2-4b13-86de-a7a11903e2ec",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        780,
        -240
      ],
      "parameters": {
        "width": 220,
        "height": 260,
        "content": "Get the Youtube video transcript"
      },
      "typeVersion": 1
    },
    {
      "id": "0ee50d32-14f7-4fad-95ab-0e5ae949c24c",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1020,
        -240
      ],
      "parameters": {
        "width": 200,
        "height": 260,
        "content": "Not all videos have text translations of the video"
      },
      "typeVersion": 1
    },
    {
      "id": "89a4e59a-58fa-4e3c-bb30-4a6a816e8e15",
      "name": "Get Fulltext",
      "type": "n8n-nodes-base.code",
      "position": [
        1320,
        -220
      ],
      "parameters": {
        "jsCode": "let fulltext = \"\";

for (const item of $input.all()[0].json.transcript) {
  fulltext += item.text + \" \";
}

fulltext = fulltext.trim();

return { fulltext };"
      },
      "typeVersion": 2
    },
    {
      "id": "87520f4d-4a05-4953-aadc-324625c8e769",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1260,
        -300
      ],
      "parameters": {
        "width": 220,
        "height": 240,
        "content": "Get the full video transcript in a single variable"
      },
      "typeVersion": 1
    },
    {
      "id": "bb3ffedf-e547-439d-a25a-0dcb2f58b86c",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1500,
        -300
      ],
      "parameters": {
        "width": 340,
        "height": 240,
        "content": "Generate detailed video analysis and create a title"
      },
      "typeVersion": 1
    },
    {
      "id": "c5e7337a-1ddb-4a82-854d-dfeb6e824172",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        -480
      ],
      "parameters": {
        "color": 3,
        "width": 660,
        "height": 200,
        "content": "## YouTube Video Analyzer

This workflow is designed to analyze YouTube videos by extracting their transcripts, summarizing the content using AI models, and sending the analysis via email.

This workflow is ideal for content creators, marketers, or anyone who needs to quickly analyze and summarize YouTube videos for research, content planning, or educational purposes."
      },
      "typeVersion": 1
    },
    {
      "id": "68fecd4f-12be-4a81-b5b9-c0419464e27e",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        -240
      ],
      "parameters": {
        "width": 200,
        "height": 260,
        "content": "Set Youtube video URL manually"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "8740fcfa-44cf-40bc-bf23-7c210378b49b",
  "connections": {
    "Exist?": {
      "main": [
        [
          {
            "node": "Get Fulltext",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Fulltext": {
      "main": [
        [
          {
            "node": "Analyze LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get transcript": {
      "main": [
        [
          {
            "node": "Exist?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set YouTube URL": {
      "main": [
        [
          {
            "node": "YouTube Video ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YouTube Video ID": {
      "main": [
        [
          {
            "node": "Generate transcript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze LLM Chain": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        []
      ]
    },
    "DeepSeek Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Analyze LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Generate transcript": {
      "main": [
        [
          {
            "node": "Get transcript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        []
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Analyze LLM Chain",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Set YouTube URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Manualtrigger
  • Code
  • @N8N/N8N Nodes Langchain.Lmchatopenai
  • @N8N/N8N Nodes Langchain.Lmchatopenrouter
  • @N8N/N8N Nodes Langchain.Lmchatdeepseek

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作