{
  "name": "A. TikTok Download (NEW \u2192 READY)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "*/15 * * * *"
            }
          ]
        }
      },
      "id": "schedule-download",
      "name": "Schedule Every 15 min",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "command": "node /scripts/read-excel-for-n8n.js"
      },
      "id": "read-excel",
      "name": "Read Excel",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Parse JSON output from Excel reader\nconst output = items[0].json.stdout;\nconst data = JSON.parse(output);\n\n// Filter only NEW status videos (need to download)\nconst newVideos = data.videos.filter(video => video.status === 'NEW');\n\nif (newVideos.length === 0) {\n  console.log('\u26a0\ufe0f No NEW videos to download');\n  return [];\n}\n\nconsole.log(`\u2705 Found ${newVideos.length} NEW videos to download`);\n\n// Return each video as separate item\nreturn newVideos.map(video => ({\n  json: video\n}));"
      },
      "id": "filter-new",
      "name": "Filter NEW Only",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "command": "node /scripts/download-videos-n8n.js"
      },
      "id": "download-videos",
      "name": "Download Videos",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "operation": "sendEmail",
        "to": "trieuphunongnam97@gmail.com",
        "subject": "\u2705 Videos Downloaded - {{ $now.toLocaleString('vi-VN') }}",
        "emailFormat": "html",
        "message": "<!DOCTYPE html>\n<html lang=\"vi\">\n<head>\n    <meta charset=\"UTF-8\">\n    <title>Videos Downloaded</title>\n</head>\n<body style=\"font-family: Arial, sans-serif; background: #f4f4f4; padding: 20px;\">\n    <div style=\"max-width: 600px; margin: 0 auto; background: white; border-radius: 8px; padding: 30px;\">\n        <h1 style=\"color: #28a745; margin: 0 0 20px;\">\ud83d\udce5 Videos Downloaded Successfully!</h1>\n        <div style=\"background: #d4edda; padding: 15px; border-left: 4px solid #28a745; margin-bottom: 20px;\">\n            <p style=\"margin: 0; color: #155724; font-weight: bold;\">\u2705 Download completed</p>\n        </div>\n        <h2 style=\"color: #333; font-size: 18px;\">\ud83d\udcca Details:</h2>\n        <table style=\"width: 100%; border: 1px solid #ddd; margin-bottom: 20px;\">\n            <tr style=\"background: #f8f9fa;\">\n                <td style=\"padding: 10px; font-weight: bold;\">Status:</td>\n                <td style=\"padding: 10px; color: #28a745;\">NEW \u2192 READY \u2713</td>\n            </tr>\n            <tr>\n                <td style=\"padding: 10px; font-weight: bold;\">Time:</td>\n                <td style=\"padding: 10px;\">{{ $now.toLocaleString('vi-VN') }}</td>\n            </tr>\n            <tr style=\"background: #f8f9fa;\">\n                <td style=\"padding: 10px; font-weight: bold;\">Output:</td>\n                <td style=\"padding: 10px; font-family: monospace; font-size: 12px;\">{{ $json.stdout ? $json.stdout.substring(0, 150) : 'Success' }}...</td>\n            </tr>\n        </table>\n        <div style=\"background: #fff3cd; padding: 15px; border-radius: 4px; border-left: 4px solid #ffc107;\">\n            <h3 style=\"margin: 0 0 10px; color: #856404;\">\u23ed\ufe0f Next Step:</h3>\n            <p style=\"margin: 5px 0;\">Videos are now <strong>READY</strong> to post</p>\n            <p style=\"margin: 5px 0;\">Workflow B will post them to Facebook</p>\n        </div>\n        <div style=\"background: #e3f2fd; padding: 15px; border-radius: 4px; margin-top: 15px;\">\n            <h3 style=\"margin: 0 0 10px; color: #1976d2;\">\ud83e\udd16 Workflow A Info:</h3>\n            <p style=\"margin: 5px 0;\"><strong>Purpose:</strong> Download videos from TikTok</p>\n            <p style=\"margin: 5px 0;\"><strong>Next run:</strong> 15 minutes</p>\n            <p style=\"margin: 5px 0;\"><strong>Excel:</strong> /data/posts.xlsx</p>\n        </div>\n        <hr style=\"margin: 20px 0; border: none; border-top: 1px solid #ddd;\">\n        <p style=\"color: #777; font-size: 12px; text-align: center; margin: 10px 0 0;\">\ud83e\udd16 Automated by n8n Docker<br>Workflow A: Download Pipeline</p>\n    </div>\n</body>\n</html>"
      },
      "id": "notify-download",
      "name": "Email: Download Complete",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2,
      "position": [
        1050,
        300
      ]
    }
  ],
  "connections": {
    "Schedule Every 15 min": {
      "main": [
        [
          {
            "node": "Read Excel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Excel": {
      "main": [
        [
          {
            "node": "Filter NEW Only",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter NEW Only": {
      "main": [
        [
          {
            "node": "Download Videos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Videos": {
      "main": [
        [
          {
            "node": "Email: Download Complete",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "download",
    "tiktok"
  ],
  "triggerCount": 0,
  "updatedAt": "2025-11-07T00:00:00.000Z",
  "versionId": "workflow-a-v1"
}