Tiktok Downloader

工作流概述

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

工作流源代码

下载
{
  "id": "aVienX696oMCH1DR",
  "meta": {
    "instanceId": "dce6d05169adc9f802863a06c3edb9925b178c4fce2360953cce9c1b509705cc"
  },
  "name": "Tiktok Downloader",
  "tags": [],
  "nodes": [
    {
      "id": "4dc30078-c7df-4bcb-91ed-953cd6da4a13",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -280,
        20
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "5598aa10-f667-4023-b9de-fe07e86badec",
      "name": "Get TikTok Video Page Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        40,
        20
      ],
      "parameters": {
        "url": "https://www.tiktok.com/@randomspamvideos25/video/7251387037834595630",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "responseFormat": "text"
            }
          }
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/91.0.4472.124"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "734a5304-f67f-4ace-a1da-0d268664452c",
      "name": "Scrape raw video URL",
      "type": "n8n-nodes-base.code",
      "position": [
        480,
        20
      ],
      "parameters": {
        "jsCode": "const html = $input.first().json.data;
const headers = $input.first().json.headers || {};
const cookies = headers['set-cookie'] || [];

if (!html) {
  throw new Error(\"HTML body is undefined. Check the previous node's output.\");
}
const regex = /<script id=\"__UNIVERSAL_DATA_FOR_REHYDRATION__\" type=\"application\/json\">([\s\S]*?)<\/script>/;
const match = html.match(regex);

if (match) {
  const jsonStr = match[1];
  const data = JSON.parse(jsonStr);
  const videoUrl = data?.__DEFAULT_SCOPE__?.[\"webapp.video-detail\"]?.itemInfo?.itemStruct?.video?.playAddr;
  if (!videoUrl) {
    throw new Error(\"Could not find video URL in the JSON data.\");
  }
  return [{ json: { videoUrl, cookies: cookies.join('; ') } }];
} else {
  throw new Error(\"Could not find __UNIVERSAL_DATA_FOR_REHYDRATION__ script in the HTML.\");
}"
      },
      "typeVersion": 2
    },
    {
      "id": "f574ccb8-6f5f-4e55-a2d5-7ad775d3c4e5",
      "name": "Output video file without watermark",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        900,
        20
      ],
      "parameters": {
        "url": "={{ $json.videoUrl }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          },
          "allowUnauthorizedCerts": true
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
            },
            {
              "name": "Referer",
              "value": "https://www.tiktok.com/"
            },
            {
              "name": "Accept",
              "value": "video/mp4,video/webm,video/*;q=0.9,application/octet-stream;q=0.8"
            },
            {
              "name": "Accept-Language",
              "value": "en-US,en;q=0.5"
            },
            {
              "name": "Connection",
              "value": "keep-alive"
            },
            {
              "name": "Cookie",
              "value": "={{ $json.cookies }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "73d4ffa7-2264-4a84-9ab2-2004342e3039",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -140,
        -180
      ],
      "parameters": {
        "color": 6,
        "width": 460,
        "height": 360,
        "content": "## 1. Load the video page
Open this node and replace the URL with the one of the video you want to download without a watermark.

A Tiktok video URL looks like: https://www.tiktok.com/@Username_here/video/Video_ID_Here

Outputs the returned page HTML along with the session cookies

"
      },
      "typeVersion": 1
    },
    {
      "id": "848fc04b-2620-4d83-8701-52c053f7c017",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        340,
        -180
      ],
      "parameters": {
        "color": 5,
        "width": 380,
        "height": 360,
        "content": "## 2. Find the raw video URL
Parses through all of the HTML and finds the section containing the video URL before the watermark is applied"
      },
      "typeVersion": 1
    },
    {
      "id": "40b3a2bd-5733-43a8-951c-d5fa26647615",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        740,
        -180
      ],
      "parameters": {
        "color": 4,
        "width": 400,
        "height": 360,
        "content": "## 3. Output video file without watermark
Using the cookies from step 1, a request is made to access the original video file as shown on TikTok"
      },
      "typeVersion": 1
    },
    {
      "id": "36629265-f139-433f-9603-0670a08be1ed",
      "name": "Upload to Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        300,
        360
      ],
      "parameters": {
        "name": "={{ $node[\"Get TikTok Video Page Data\"].parameter[\"url\"].match(/\/video\/(\d+)/)[1] + \".mp4\" }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultUrl": "https://drive.google.com/drive",
          "cachedResultName": "/ (Root folder)"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ZvDuyVfbZJbDJXcS",
          "name": "Google Drive account"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "94364c83-14ce-48c3-afe5-b7cd8addd2a0",
      "name": "Set file permissions to public with link",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        560,
        360
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "share",
        "permissionsUi": {
          "permissionsValues": {
            "role": "writer",
            "type": "anyone",
            "allowFileDiscovery": true
          }
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "ZvDuyVfbZJbDJXcS",
          "name": "Google Drive account"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "d37ad36c-0b7f-4c2c-9538-dc8bf75e997f",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        260,
        200
      ],
      "parameters": {
        "color": 7,
        "width": 500,
        "height": 320,
        "content": "## (Optional) Upload video to Google Drive
An expression is used to save the file to your Google Drive as Video_ID.mp4

Note: Must have Google Drive API enabled in [Google Cloud Console](https://console.cloud.google.com/apis/api/drive.googleapis.com/overview) OAuth ClientID and Client Secret credentials setup"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "70234bbb-ccaf-4291-a50b-063e07303678",
  "connections": {
    "Scrape raw video URL": {
      "main": [
        [
          {
            "node": "Output video file without watermark",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Google Drive": {
      "main": [
        [
          {
            "node": "Set file permissions to public with link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get TikTok Video Page Data": {
      "main": [
        [
          {
            "node": "Scrape raw video URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Get TikTok Video Page Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Output video file without watermark": {
      "main": [
        [
          {
            "node": "Upload to Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

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

技术分析

节点类型及作用

  • Manualtrigger
  • Httprequest
  • Code
  • Stickynote
  • Googledrive

复杂度评估

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

实施指南

前置条件

  • 有效的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错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作