子流程 - YouTube搜索
中级
这是一个AI领域的自动化工作流,包含 10 个节点。主要使用 If, Set, Code, YouTube, HttpRequest 等节点,结合人工智能技术实现智能自动化。 AI YouTube趋势探索器 - 基于Gemini/ChatGPT的n8n自动化工作流
前置要求
- •可能需要目标 API 的认证凭证
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "IktojxaOHrdHkURm",
"meta": {
"instanceId": "ed6d846a2fce1f660ede2e7da800724cca01dc3d0685524a3c917881b7cfcfe9",
"templateCredsSetupCompleted": true
},
"name": "子流程 - Youtube 搜索",
"tags": [
{
"id": "CEVEeZJa4qgPvdpK",
"name": "youtube",
"createdAt": "2025-05-27T02:29:43.874Z",
"updatedAt": "2025-05-27T02:29:43.874Z"
}
],
"nodes": [
{
"id": "5d4d8d36-8f39-4e3c-9527-9d5604e58adc",
"name": "当由另一个工作流执行时",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
-660,
280
],
"parameters": {
"inputSource": "passthrough"
},
"typeVersion": 1.1
},
{
"id": "09b1a19d-4fb3-4d78-a41b-90da9ab49409",
"name": "Youtube - 获取视频",
"type": "n8n-nodes-base.youTube",
"position": [
-440,
280
],
"parameters": {
"limit": 3,
"filters": {
"q": "={{ $json.query.search_term }}",
"regionCode": "US",
"publishedAfter": "={{ new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString() }}"
},
"options": {
"order": "relevance",
"safeSearch": "moderate"
},
"resource": "video"
},
"credentials": {
"youTubeOAuth2Api": {
"id": "KhD0GLQGWl8MtqCs",
"name": "YouTube - toan.ngo"
}
},
"typeVersion": 1
},
{
"id": "d166a037-d601-438d-b493-c443ab552b40",
"name": "遍历项目",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-220,
280
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "803e7b42-8dd4-48f6-a3c6-247d8235faa7",
"name": "HTTP - 查找视频数据",
"type": "n8n-nodes-base.httpRequest",
"position": [
0,
200
],
"parameters": {
"url": "https://www.googleapis.com/youtube/v3/videos?",
"options": {},
"sendQuery": true,
"authentication": "predefinedCredentialType",
"queryParameters": {
"parameters": [
{
"name": "id",
"value": "={{ $json.id.videoId }}"
},
{
"name": "part",
"value": "contentDetails,snippet,statistics"
}
]
},
"nodeCredentialType": "youTubeOAuth2Api"
},
"credentials": {
"youTubeOAuth2Api": {
"id": "KhD0GLQGWl8MtqCs",
"name": "YouTube - toan.ngo"
}
},
"typeVersion": 4.2
},
{
"id": "771aebee-d468-4352-ad25-7d13b09836b8",
"name": "代码 - 从内存检索数据",
"type": "n8n-nodes-base.code",
"position": [
0,
0
],
"parameters": {
"jsCode": "const workflowStaticData = $getWorkflowStaticData('global');\n\nconst lastExecution = workflowStaticData.lastExecution;\n\nreturn lastExecution;"
},
"typeVersion": 2,
"alwaysOutputData": false
},
{
"id": "c1afc8ff-6c26-433b-8b2c-6debda964ae1",
"name": "字段 - 响应",
"type": "n8n-nodes-base.set",
"position": [
220,
0
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "b9b9117b-ea14-482e-a13b-e68b8e6b441d",
"name": "response",
"type": "string",
"value": "={{ $input.all() }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "fd80746e-6a72-46e3-aefc-d7404cd3b50a",
"name": "如果 - 超过 3",
"type": "n8n-nodes-base.if",
"position": [
220,
280
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "and",
"conditions": [
{
"id": "08ba3db9-6bcf-47f8-a74d-9e26f28cb08f",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
},
"leftValue": "={{ \n (() => {\n const duration = $json.items[0].contentDetails.duration;\n\n // Helper function to convert ISO 8601 duration to seconds\n const iso8601ToSeconds = iso8601 => {\n const match = iso8601.match(/PT(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?/);\n const hours = parseInt(match[1] || 0, 10);\n const minutes = parseInt(match[2] || 0, 10);\n const seconds = parseInt(match[3] || 0, 10);\n return hours * 3600 + minutes * 60 + seconds;\n };\n\n // Convert duration to seconds\n const durationInSeconds = iso8601ToSeconds(duration);\n\n // Check if greater than 210 seconds (3 minutes 30 seconds)\n return durationInSeconds > 210;\n })() \n}}",
"rightValue": ""
}
]
},
"looseTypeValidation": true
},
"typeVersion": 2.2
},
{
"id": "bd86dca7-fdcc-4722-9247-1d5d5f16bb86",
"name": "字段 - 分组数据",
"type": "n8n-nodes-base.set",
"position": [
440,
280
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "47c172ad-90c8-4cf6-a9f5-50607e04cc90",
"name": "id",
"type": "string",
"value": "={{ $json.items[0].id }}"
},
{
"id": "9e639efa-0714-4b06-9847-f7b4b2fbef59",
"name": "viewCount",
"type": "string",
"value": "={{ $json.items[0].statistics.viewCount }}"
},
{
"id": "93328f00-91b8-425b-ad0f-a330b2f95242",
"name": "likeCount",
"type": "string",
"value": "={{ $json.items[0].statistics.likeCount }}"
},
{
"id": "015b0fb2-2a98-464c-a21b-51100616f26a",
"name": "commentCount",
"type": "string",
"value": "={{ $json.items[0].statistics.commentCount }}"
},
{
"id": "cf1e1ec3-a138-42b8-8747-d249afa58dd3",
"name": "description",
"type": "string",
"value": "={{ $json.items[0].snippet.description }}"
},
{
"id": "c5c9a3a2-b820-4932-a38a-e21102992215",
"name": "title",
"type": "string",
"value": "={{ $json.items[0].snippet.title }}"
},
{
"id": "38216ead-1f8d-4f93-b6ad-5ef709a1ad2a",
"name": "channelTitle",
"type": "string",
"value": "={{ $json.items[0].snippet.channelTitle }}"
},
{
"id": "ff34194d-3d46-43a8-9127-84708987f536",
"name": "tags",
"type": "string",
"value": "={{ $json.items[0].snippet.tags.join(', ') }}"
},
{
"id": "e50b0f7b-3e37-4557-8863-d68d4fa505c8",
"name": "channelId",
"type": "string",
"value": "={{ $json.items[0].snippet.channelId }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "f9326f4d-16e5-4078-9273-7ee3fb1c70a3",
"name": "代码 - 保存数据到内存",
"type": "n8n-nodes-base.code",
"position": [
660,
360
],
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "const workflowStaticData = $getWorkflowStaticData('global');\n\nif (!workflowStaticData.lastExecution || typeof workflowStaticData.lastExecution.response !== 'string') {\n workflowStaticData.lastExecution = { response: '' };\n}\n\nconst regexes = [\n { pattern: /https?:\\/\\/\\S+|www\\.\\S+/g, replace: '' },\n { pattern: /[\\u{1F600}-\\u{1F64F}\\u{1F300}-\\u{1F5FF}\\u{1F680}-\\u{1F6FF}\\u{2600}-\\u{26FF}\\u{2700}-\\u{27BF}]/gu, replace: '' },\n { pattern: /[\\r\\n\\\\]+/g, replace: ' ' },\n { pattern: / {2,}/g, replace: ' ' } \n];\n\nfunction sanitize(text) {\n return regexes.reduce((str, { pattern, replace }) => str.replace(pattern, replace), text).trim();\n}\n\nconst item = { ...$input.item };\nif (item.description) {\n item.description = sanitize(item.description);\n}\n\nconst sanitizedItem = sanitize(JSON.stringify(item));\n\nif (workflowStaticData.lastExecution.response) {\n workflowStaticData.lastExecution.response += ' ### NEXT VIDEO FOUND: ### ';\n}\nworkflowStaticData.lastExecution.response += sanitizedItem;\n\nreturn workflowStaticData.lastExecution;"
},
"typeVersion": 2
},
{
"id": "49187d4e-5258-48a2-ae9a-fe82a82b75b9",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-900,
-140
],
"parameters": {
"width": 580,
"height": 260,
"content": "## 子流程 - Youtube 搜索"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {
"When Executed by Another Workflow": [
{
"json": {
"query": {
"search_term": "cat games gameplay"
}
}
}
]
},
"settings": {
"executionOrder": "v1"
},
"versionId": "252a4d1e-eb32-4f40-b61a-c80ba62d1d57",
"connections": {
"Loop Over Items": {
"main": [
[
{
"node": "Code - Retrieve Data From Memory",
"type": "main",
"index": 0
}
],
[
{
"node": "HTTP - Find Video Data",
"type": "main",
"index": 0
}
]
]
},
"Field - Group Data": {
"main": [
[
{
"node": "Code - Save Data To Memory",
"type": "main",
"index": 0
}
]
]
},
"If - Longer Than 3": {
"main": [
[
{
"node": "Field - Group Data",
"type": "main",
"index": 0
}
],
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Youtube - Get Video": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"HTTP - Find Video Data": {
"main": [
[
{
"node": "If - Longer Than 3",
"type": "main",
"index": 0
}
]
]
},
"Code - Save Data To Memory": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Code - Retrieve Data From Memory": {
"main": [
[
{
"node": "Field - Response",
"type": "main",
"index": 0
}
]
]
},
"When Executed by Another Workflow": {
"main": [
[
{
"node": "Youtube - Get Video",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 人工智能
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
完成YouTube
基于细分领域的AI YouTube趋势发现器
If
Set
Code
+10
18 节点Leonardo Grigorio
人工智能
YouTube视频本地化更新 - Hoàng
基于Gemini AI和Google Sheets的多语言YouTube元数据翻译器
If
Set
Code
+8
28 节点Agent Circle
内容创作
API架构提取器
API架构提取器
If
Set
Code
+22
88 节点Polina Medvedieva
工程
使用AI自动为WordPress博客文章添加标签
使用AI自动为WordPress博客文章添加标签
If
Set
Code
+14
32 节点Ludwig
人工智能
YouTube 自动化
自动化 YouTube 视频排程和 AI 元数据生成 🎬
If
Set
Code
+11
33 节点JPres
人工智能
使用OpenAI脚本、Leonardo图像和HeyGen虚拟形象创建AI视频
使用OpenAI脚本、Leonardo图像和HeyGen虚拟形象创建AI视频
If
Set
Code
+15
68 节点Adam Crafts
设计