{
  "nodes": [
    {
      "parameters": {
        "content": "Here you update API key when you register on ThumbAPI \nTesting API key: thumbapi_test",
        "height": 96,
        "width": 246
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [368, -32],
      "typeVersion": 1,
      "id": "d47be3f2-33ab-4d64-a7d8-25e46091e6a4",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "Here you edit your chanell ID ",
        "height": 80,
        "width": 150
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [-336, -32],
      "typeVersion": 1,
      "id": "be346780-59f9-4f7d-8779-76d578f077fe",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "={{ $json.headers.location }}",
        "sendBody": true,
        "contentType": "binaryData",
        "inputDataFieldName": "={{ $('Thumbnail').item.binary.thumbnail}}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [944, 80],
      "id": "70b9d24a-80e0-4de7-91d7-4e9f3b45b341",
      "name": "HTTP upload thumbnail"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://www.googleapis.com/upload/youtube/v3/thumbnails/set?videoId={{ $('VideIdSet').item.json.videoId }}&uploadType=resumable",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleOAuth2Api",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Upload-Content-Type",
              "value": "image/png"
            },
            {
              "name": "X-Upload-Content-Length",
              "value": "={{ $('Thumbnail').item.binary.thumbnail.bytes }}"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [752, 80],
      "id": "441212ce-ddc4-4ca1-b9a4-f40687d3c828",
      "name": "HTTP-Get upload link",
      "credentials": {
        "googleOAuth2Api": {
          "id": "LgL98EcTf13Jsd6E",
          "name": "Google account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "7138bc63-e405-4c0a-a696-6d57e701cdb4",
              "name": "ChanelId",
              "value": "UCUKWzyXAAFUo4DCGfQhtVAg",
              "type": "string"
            },
            {
              "id": "b881458d-2403-45bb-bac5-f83ea36120aa",
              "name": "ThumbAPI_key",
              "value": "thumbapi_test",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-320, 80],
      "id": "32a93a23-a9c4-46fd-bf4f-5eb919c41db5",
      "name": "Input values"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a7d16741-06b4-4248-a06b-cf2971efb4d2",
              "name": "thumbnail",
              "value": "={{$binary.data}}",
              "type": "binary"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [592, 80],
      "id": "9b321aad-9dd6-4348-b3f3-9a81aa4e314d",
      "name": "Thumbnail"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "6c789f5b-6c63-4338-800b-e5d073e763bb",
              "name": "videoId",
              "value": "={{ $json.videoId }}",
              "type": "string"
            },
            {
              "id": "622c3edd-0ffb-4248-a46c-3e99dc598dec",
              "name": "title",
              "value": "={{ $json.title }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [224, 80],
      "id": "a88a834a-4bf8-4e37-9a35-ca871ea94a27",
      "name": "VideIdSet"
    },
    {
      "parameters": {
        "title": "={{ $json.title }}",
        "category": "=auto",
        "outputFormat": "png",
        "additionalOptions": {}
      },
      "type": "n8n-nodes-thumbapi.thumbApi",
      "typeVersion": 1,
      "position": [416, 80],
      "id": "4865c132-93be-4c3a-8364-fade8e1e0ca0",
      "name": "Generate a thumbnail",
      "credentials": {
        "thumbApiApi": {
          "id": "zyNQXTTfLk6jp3Tk",
          "name": "ThumbAPI account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const xml = $input.first().json.data;\n\n// Extract all entries\nconst entryMatches = xml.matchAll(/<entry>([\\s\\S]*?)<\\/entry>/g);\nconst entries = [...entryMatches];\n\n// Filter out shorts\nconst videos = entries.filter(e => {\n  return !e[1].includes('/shorts/');\n});\n\n// Get latest video\nconst latest = videos[0][1];\nconst videoId = latest.match(/<yt:videoId>(.*?)<\\/yt:videoId>/)[1];\nconst title = latest.match(/<title>(.*?)<\\/title>/)[1];\n\nreturn [{ json: { videoId, title } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [48, 80],
      "id": "5c77af43-1046-4307-8515-77ab70d71cbd",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "url": "=https://www.youtube.com/feeds/videos.xml?channel_id={{ $('Input values').item.json.ChanelId }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [-128, 80],
      "id": "015b75d1-ec21-4e81-bec0-17412ca166c0",
      "name": "HTTP Request"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [-512, 80],
      "id": "fad5b01b-e284-462c-a385-bfc375aa6ef6",
      "name": "When clicking 'Execute workflow'"
    }
  ],
  "connections": {
    "HTTP-Get upload link": {
      "main": [
        [
          {
            "node": "HTTP upload thumbnail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Input values": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Thumbnail": {
      "main": [
        [
          {
            "node": "HTTP-Get upload link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "VideIdSet": {
      "main": [
        [
          {
            "node": "Generate a thumbnail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate a thumbnail": {
      "main": [
        [
          {
            "node": "Thumbnail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "VideIdSet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking 'Execute workflow'": {
      "main": [
        [
          {
            "node": "Input values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "369c6f7060831c2832f4ab7ae05aa850d30f1cd4f9a7843cede962d50ce17b34"
  }
}
