8
n8n 中文网amn8n.com

按频道统计的热门视频

高级

这是一个自动化工作流,包含 18 个节点。主要使用 Set, Code, FormTrigger, HttpRequest, GoogleSheets 等节点。 YouTube 竞品视频分析至 Google Sheets

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证

分类

-
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "aaitjN3jwXzLUnjB",
  "meta": {
    "instanceId": "7b35059aff065837b1c7d24142b37474554b08b3370f3096b2e57345690d178e"
  },
  "name": "按频道统计的热门视频",
  "tags": [],
  "nodes": [
    {
      "id": "2496298c-0720-48c2-b814-d2e6884bba81",
      "name": "表单提交时1",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        0,
        384
      ],
      "webhookId": "9aa528af-6673-4bfb-a84e-397e83b21f75",
      "parameters": {
        "options": {},
        "formTitle": "YouTube Channel Analyzer",
        "formFields": {
          "values": [
            {
              "fieldType": "dropdown",
              "fieldLabel": "Format",
              "fieldOptions": {
                "values": [
                  {
                    "option": "short"
                  },
                  {
                    "option": "medium"
                  },
                  {
                    "option": "long"
                  }
                ]
              },
              "requiredField": true
            },
            {
              "fieldType": "number",
              "fieldLabel": "Number of Videos",
              "placeholder": "Enter number of videos to fetch (default 5)",
              "requiredField": true
            },
            {
              "fieldLabel": "Channel Name",
              "placeholder": "Enter the YouTube channel name",
              "requiredField": true
            }
          ]
        },
        "formDescription": "Fetch trending videos from a specific channel"
      },
      "typeVersion": 2.2
    },
    {
      "id": "eaf07791-3de3-4b28-86b7-d9d8c72540aa",
      "name": "设置参数1",
      "type": "n8n-nodes-base.set",
      "position": [
        208,
        384
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "name": "api_key",
              "type": "string",
              "value": "<api-key>"
            },
            {
              "name": "format",
              "type": "string",
              "value": "={{ $json.Format }}"
            },
            {
              "name": "videoLimit",
              "type": "string",
              "value": "={{ $json['Number of Videos'] }}"
            },
            {
              "name": "channel_name",
              "type": "string",
              "value": "={{ $json['Channel Name'] }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "554048e6-db9b-4039-8a3f-e1223535581d",
      "name": "获取频道 ID1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        416,
        384
      ],
      "parameters": {
        "url": "https://www.googleapis.com/youtube/v3/search",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "part",
              "value": "snippet"
            },
            {
              "name": "type",
              "value": "channel"
            },
            {
              "name": "q",
              "value": "={{ $json.channel_name }}"
            },
            {
              "name": "key",
              "value": "Use your Api Key"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "d7f5e607-d8a7-4e0e-aeba-70ce0d0c605e",
      "name": "提取频道 ID1",
      "type": "n8n-nodes-base.code",
      "position": [
        592,
        384
      ],
      "parameters": {
        "jsCode": "return [{ json: { channelId: $json.items[0].id.channelId } }];"
      },
      "typeVersion": 2
    },
    {
      "id": "568257fb-7ebf-49ae-a2c2-b694554898e3",
      "name": "获取视频 ID1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        832,
        384
      ],
      "parameters": {
        "url": "https://www.googleapis.com/youtube/v3/search",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "part",
              "value": "snippet"
            },
            {
              "name": "maxResults",
              "value": "={{ $json.videoLimit || 5 }}"
            },
            {
              "name": "order",
              "value": "viewCount"
            },
            {
              "name": "channelId",
              "value": "={{ $json.channelId }}"
            },
            {
              "name": "type",
              "value": "video"
            },
            {
              "name": "videoDuration",
              "value": "={{ $json.format }}"
            },
            {
              "name": "key",
              "value": "Use your key"
            },
            {
              "name": "regionCode",
              "value": "US"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "5990323f-71c3-47b1-9c90-1223447b708c",
      "name": "提取 ID1",
      "type": "n8n-nodes-base.code",
      "position": [
        1008,
        384
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nreturn items.flatMap(item => (item.json?.items || []).map(videoItem => ({ json: { videoid: videoItem?.id?.videoId || null } })));\n"
      },
      "typeVersion": 2
    },
    {
      "id": "f6ea02fe-25c9-4a84-896f-f439ff4f07d5",
      "name": "获取视频数据1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1216,
        384
      ],
      "parameters": {
        "url": "https://www.googleapis.com/youtube/v3/videos",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "part",
              "value": "snippet,statistics"
            },
            {
              "name": "id",
              "value": "={{ $json.videoid }}"
            },
            {
              "name": "key",
              "value": "Use your Youtube Api"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "5fea0e50-6af3-46ff-80ff-10d0e76f1963",
      "name": "提取视频数据1",
      "type": "n8n-nodes-base.code",
      "position": [
        1408,
        384
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nreturn items.flatMap(item =>\n  (item.json?.items || []).map(videoItem => ({\n    json: {\n      channelTitle: videoItem.snippet?.channelTitle || '',\n      title: videoItem.snippet?.title || '',\n      description: videoItem.snippet?.description || '',   // ⬅️ added\n      viewCount: videoItem.statistics?.viewCount || 0,\n      likeCount: videoItem.statistics?.likeCount || 0,\n      commentCount: videoItem.statistics?.commentCount || 0,\n      videoURL: `https://www.youtube.com/watch?v=${videoItem.id || ''}`,\n      thumbnail: videoItem.snippet?.thumbnails?.high?.url || ''\n    }\n  }))\n);\n"
      },
      "typeVersion": 2
    },
    {
      "id": "8291de16-4e04-43dc-a5b2-b3f2c104be54",
      "name": "视频表现1",
      "type": "n8n-nodes-base.code",
      "position": [
        1792,
        384
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nreturn items.map(item => {\n  const viewCount = parseInt(item.json.viewCount || '0', 10);\n  const likeCount = parseInt(item.json.likeCount || '0', 10);\n  const commentCount = parseInt(item.json.commentCount || '0', 10);\n  let performance = 0;\n  if (viewCount > 0) {\n    performance = ((likeCount + commentCount) / viewCount) * 100;\n  }\n  return { json: { ...item.json, performance: performance.toFixed(2) } };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "c1053470-9136-4c9e-a492-dbfe207fa869",
      "name": "在 sheet1 中追加行",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2032,
        384
      ],
      "parameters": {
        "columns": {
          "value": {
            "hook": "={{ $json.hook }}",
            "title": "={{ $json.title }}",
            "videoURL": "={{ $json.videoURL }}",
            "likeCount": "={{ $json.likeCount }}",
            "thumbnail": "={{ $json.thumbnail }}",
            "viewCount": "={{ $json.viewCount }}",
            "description": "={{ $json.description }}",
            "performance": "={{ $json.performance }}",
            "channelTitle": "={{ $json.channelTitle }}",
            "commentCount": "={{ $json.commentCount }}"
          },
          "schema": [
            {
              "id": "channelTitle",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "channelTitle",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "description",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "description",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "viewCount",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "viewCount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "likeCount",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "likeCount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "commentCount",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "commentCount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "videoURL",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "videoURL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "thumbnail",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "thumbnail",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "hook",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "hook",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "performance",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "performance",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1muc55xphO5rYn6uO1rxfb_-W1xruMIcFmbQE6EPRFBQ/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1muc55xphO5rYn6uO1rxfb_-W1xruMIcFmbQE6EPRFBQ/edit?usp=drivesdk",
          "cachedResultName": "YouTube Viral Videos"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "UwnixXxqC0pFVvLS",
          "name": "My Account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "201adcea-9f77-4a32-8cd6-e47d750d8b36",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        320
      ],
      "parameters": {
        "width": 384,
        "height": 224,
        "content": "## 输入频道名称"
      },
      "typeVersion": 1
    },
    {
      "id": "07eee8a6-6ec2-43b9-8603-9a43e2e53976",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        352,
        320
      ],
      "parameters": {
        "color": 6,
        "width": 400,
        "height": 224,
        "content": "## 获取频道 ID"
      },
      "typeVersion": 1
    },
    {
      "id": "f3995972-de6a-45a5-8c07-b9da4e82c40e",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        768,
        320
      ],
      "parameters": {
        "color": 4,
        "width": 400,
        "height": 224,
        "content": "## 获取视频 ID"
      },
      "typeVersion": 1
    },
    {
      "id": "b912ba40-864b-4244-bcb8-c9a5ff854fd0",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1184,
        304
      ],
      "parameters": {
        "width": 736,
        "height": 272,
        "content": "## 提取视频数据(如观看量、点赞数、标题和描述)"
      },
      "typeVersion": 1
    },
    {
      "id": "1d538749-fe4c-4fa1-bffa-3cd40aac2cc3",
      "name": "便签说明4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1952,
        320
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "height": 240,
        "content": "## 将数据保存到表格"
      },
      "typeVersion": 1
    },
    {
      "id": "8a65fcbf-3734-4abb-9991-73015894cab2",
      "name": "便签说明5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        576,
        80
      ],
      "parameters": {
        "color": 4,
        "width": 752,
        "height": 144,
        "content": "# 获取竞争对手的爆款视频数据"
      },
      "typeVersion": 1
    },
    {
      "id": "2b71d06b-99dd-4dab-b022-b70e311029d7",
      "name": "钩子和描述",
      "type": "n8n-nodes-base.code",
      "position": [
        1584,
        384
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nreturn items.map(item => {\n  const desc = item.json.description || \"\";\n  // take the first 15 words of description as a \"hook\"\n  const hook = desc.split(\" \").slice(0, 15).join(\" \");\n  \n  return {\n    json: {\n      ...item.json,\n      hook\n    }\n  };\n});\n"
      },
      "typeVersion": 2
    },
    {
      "id": "4de94c83-21aa-498b-8eec-14f42ecff894",
      "name": "便签 6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -832,
        96
      ],
      "parameters": {
        "width": 768,
        "height": 768,
        "content": "# 获取竞争对手的爆款视频数据"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "a7671256-6235-4271-aff4-be36e1023da7",
  "connections": {
    "Extract IDs1": {
      "main": [
        [
          {
            "node": "Get Video Data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Video IDs1": {
      "main": [
        [
          {
            "node": "Extract IDs1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Channel ID1": {
      "main": [
        [
          {
            "node": "Extract Channel ID1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Video Data1": {
      "main": [
        [
          {
            "node": "Extract Video Data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Parameters1": {
      "main": [
        [
          {
            "node": "Get Channel ID1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Video Performance1": {
      "main": [
        [
          {
            "node": "Append row in sheet1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Channel ID1": {
      "main": [
        [
          {
            "node": "Get Video IDs1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Video Data1": {
      "main": [
        [
          {
            "node": "Hook and Description",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission1": {
      "main": [
        [
          {
            "node": "Set Parameters1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hook and Description": {
      "main": [
        [
          {
            "node": "Video Performance1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量18
分类-
节点类型6
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Asfandyar Malik

Asfandyar Malik

@asfandyar-malik

Building AI Calling | Voho Calling

外部链接
在 n8n.io 查看

分享此工作流