{
  "name": "YouTube Trend Detector Part 1 - Track Channel Videos",
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -60,
        -120
      ],
      "id": "07812d30-b5dd-41c1-83b6-d26098230358",
      "name": "When clicking ‘Test workflow’"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Channels"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        160,
        0
      ],
      "id": "8f48251c-e738-4fe7-9be1-075ec6c0a705",
      "name": "Google Sheets"
    },
    {
      "parameters": {
        "resource": "video",
        "limit": 5,
        "filters": {
          "channelId": "={{ $json.channel_id }}"
        },
        "options": {
          "order": "date"
        }
      },
      "type": "n8n-nodes-base.youTube",
      "typeVersion": 1,
      "position": [
        580,
        0
      ],
      "id": "a3ab3fca-b1a6-44ca-b5b0-b51d74ebb03d",
      "name": "YouTube"
    },
    {
      "parameters": {
        "resource": "video",
        "operation": "get",
        "videoId": "={{ $json.id.videoId }}",
        "options": {}
      },
      "type": "n8n-nodes-base.youTube",
      "typeVersion": 1,
      "position": [
        800,
        0
      ],
      "id": "9e1d2bdd-b922-43ca-8612-a44c403d5009",
      "name": "YouTube1"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "8bc4396b-0ca3-4c3d-b103-f785b67845a5",
              "leftValue": "={{ $json.contentDetails.duration.length }}",
              "rightValue": 5,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        1020,
        0
      ],
      "id": "02e2fdbb-1295-4a24-97b4-03f4018c5b33",
      "name": "Filter"
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_GOOGLE_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $json.snippet.channelId }}",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "id": "={{ $json.id }}",
            "published_at": "={{ $json.snippet.publishedAt }}",
            "title": "={{ $json.snippet.title }}",
            "views": "={{ $json.statistics.viewCount }}",
            "likes": "={{ $json.statistics.likeCount }}",
            "comments": "={{ $json.statistics.commentCount }}",
            "favorites": "={{ $json.statistics.favoriteCount }}",
            "description": "={{ $json.snippet.description }}",
            "duration": "={{ \n  (() => {\n    const duration = $json.contentDetails.duration;\n    const match = duration.match(/PT(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)S)?/);\n    if (!match) return 0;\n\n    const hours = match[1] ? parseInt(match[1]) : 0;\n    const minutes = match[2] ? parseInt(match[2]) : 0;\n    const seconds = match[3] ? parseInt(match[3]) : 0;\n\n    return hours * 3600 + minutes * 60 + seconds;\n  })()\n}}",
            "definition": "={{ $json.contentDetails.definition }}",
            "small_thumb": "={{ $json.snippet.thumbnails.default.url }}",
            "med_thumb": "={{ $json.snippet.thumbnails.medium.url }}",
            "large_thumb": "={{ $json.snippet.thumbnails.high.url }}",
            "standard_thumb": "={{ $json.snippet.thumbnails.standard.url }}",
            "channel_id": "={{ $json.snippet.channelId }}",
            "channel_title": "={{ $json.snippet.channelTitle }}",
            "embed_html": "={{ $json.player.embedHtml }}",
            "tags": "={{ $json.snippet.tags?.join(\", \") }}"
          },
          "matchingColumns": [
            "id"
          ],
          "schema": [
            {
              "id": "id",
              "displayName": "id",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "published_at",
              "displayName": "published_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "title",
              "displayName": "title",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "views",
              "displayName": "views",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "likes",
              "displayName": "likes",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "comments",
              "displayName": "comments",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "favorites",
              "displayName": "favorites",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "description",
              "displayName": "description",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "tags",
              "displayName": "tags",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "duration",
              "displayName": "duration",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "definition",
              "displayName": "definition",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "small_thumb",
              "displayName": "small_thumb",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "med_thumb",
              "displayName": "med_thumb",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "large_thumb",
              "displayName": "large_thumb",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "standard_thumb",
              "displayName": "standard_thumb",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "channel_id",
              "displayName": "channel_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "channel_title",
              "displayName": "channel_title",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "embed_html",
              "displayName": "embed_html",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1240,
        0
      ],
      "id": "5d6749ab-36e4-496e-a86f-c07f1d8d808e",
      "name": "Google Sheets1"
    },
    {
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        380,
        0
      ],
      "id": "2ffc1249-89d0-40d7-82e6-e013d5277b9d",
      "name": "Loop Over Items"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 6
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -60,
        120
      ],
      "id": "f36d790c-7e1b-4afa-aaea-9b2f978c0d5d",
      "name": "Schedule Trigger"
    }
  ],
  "connections": {
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YouTube": {
      "main": [
        [
          {
            "node": "YouTube1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YouTube1": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter": {
      "main": [
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "YouTube",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}
