{
  "name": "[\uc544\uc138\uc544\uce58\uacfc] \uc720\ud29c\ube0c \uc601\uc0c1 \uc5c5\ub85c\ub4dc",
  "nodes": [
    {
      "parameters": {},
      "id": "trigger-manual",
      "name": "\uc218\ub3d9 \ud2b8\ub9ac\uac70",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "33dc6cbb17c9813ebc14de445d63e2c0",
        "returnAll": true,
        "filterType": "manual",
        "matchType": "allFilters",
        "filters": {
          "conditions": [
            {
              "key": "\uc0c1\ud0dc|status",
              "condition": "equals",
              "statusValue": "\ub300\uae30"
            }
          ]
        }
      },
      "id": "notion-fetch-pending",
      "name": "Notion \ub300\uae30\uc601\uc0c1 \uc870\ud68c",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "pageId": "={{ $json.id }}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "\uc0c1\ud0dc|status",
              "statusValue": "\uc5c5\ub85c\ub4dc\uc911"
            }
          ]
        }
      },
      "id": "notion-status-uploading",
      "name": "Notion \uc0c1\ud0dc \uc5c5\ub85c\ub4dc\uc911",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\nconst fileName = data.properties['\uc601\uc0c1\ud30c\uc77c']?.rich_text?.[0]?.plain_text || '';\nconst isShort = fileName.toLowerCase().includes('short') || fileName.toLowerCase().includes('\uc20f\ud3fc');\n\nlet title = data.properties['\uc81c\ubaa9']?.rich_text?.[0]?.plain_text || '';\nif (isShort && !title.includes('#Shorts')) title += ' #Shorts';\n\nconst tagsRaw = data.properties['\ud0dc\uadf8']?.multi_select || [];\nconst tags = tagsRaw.map(t => t.name);\n\nconst scheduledKst = data.properties['\uc608\uc57d\uc77c\uc2dc']?.date?.start;\nlet publishAt = null;\nif (scheduledKst) {\n  const dt = new Date(scheduledKst);\n  publishAt = dt.toISOString();\n}\n\nreturn [{\n  json: {\n    notion_page_id: data.id,\n    video_file_name: fileName,\n    thumbnail_a: data.properties['\uc378\ub124\uc77cA']?.rich_text?.[0]?.plain_text || '',\n    thumbnail_b: data.properties['\uc378\ub124\uc77cB']?.rich_text?.[0]?.plain_text || '',\n    title: title,\n    description: data.properties['\uc124\uba85']?.rich_text?.map(r => r.plain_text).join('') || '',\n    tags: tags,\n    comment: data.properties['\ub313\uae00']?.rich_text?.map(r => r.plain_text).join('') || '',\n    category_id: data.properties['\uce74\ud14c\uace0\ub9ac ID']?.number?.toString() || '26',\n    publish_at: publishAt,\n    is_short: isShort\n  }\n}];"
      },
      "id": "parse-metadata",
      "name": "\uba54\ud0c0\ub370\uc774\ud130 \ud30c\uc2f1",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "resource": "fileFolder",
        "queryString": "={{ $json.video_file_name }}",
        "filter": {
          "folderId": {
            "__rl": true,
            "value": "1XMRHLsEPxIfDe1drUdxEn-HjgU0VeOKD",
            "mode": "id"
          }
        },
        "options": {}
      },
      "id": "drive-find-video",
      "name": "Drive \uc601\uc0c1\uac80\uc0c9",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1120,
        300
      ]
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "download",
        "fileId": "={{ $json.id }}",
        "options": {
          "binaryPropertyName": "video_data"
        }
      },
      "id": "drive-download-video",
      "name": "Drive \uc601\uc0c1\ub2e4\uc6b4\ub85c\ub4dc",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1340,
        300
      ]
    },
    {
      "parameters": {
        "resource": "video",
        "operation": "upload",
        "title": "={{ $('\uba54\ud0c0\ub370\uc774\ud130 \ud30c\uc2f1').item.json.title }}",
        "regionCode": "KR",
        "categoryId": "={{ $('\uba54\ud0c0\ub370\uc774\ud130 \ud30c\uc2f1').item.json.category_id }}",
        "options": {
          "description": "={{ $('\uba54\ud0c0\ub370\uc774\ud130 \ud30c\uc2f1').item.json.description }}",
          "tags": "={{ $('\uba54\ud0c0\ub370\uc774\ud130 \ud30c\uc2f1').item.json.tags.join(',') }}",
          "privacyStatus": "={{ $('\uba54\ud0c0\ub370\uc774\ud130 \ud30c\uc2f1').item.json.publish_at ? 'private' : 'public' }}",
          "publishAt": "={{ $('\uba54\ud0c0\ub370\uc774\ud130 \ud30c\uc2f1').item.json.publish_at }}",
          "defaultLanguage": "ko",
          "selfDeclaredMadeForKids": false
        },
        "binaryPropertyName": "video_data"
      },
      "id": "youtube-upload",
      "name": "YouTube \uc5c5\ub85c\ub4dc",
      "type": "n8n-nodes-base.youTube",
      "typeVersion": 1,
      "position": [
        1560,
        300
      ]
    },
    {
      "parameters": {
        "resource": "fileFolder",
        "queryString": "={{ $('\uba54\ud0c0\ub370\uc774\ud130 \ud30c\uc2f1').item.json.thumbnail_a }}",
        "filter": {
          "folderId": {
            "__rl": true,
            "value": "1HuF-bDaX5RyaURr07o0OTpnNzWMk5OOM",
            "mode": "id"
          }
        }
      },
      "id": "drive-find-thumbnail",
      "name": "Drive \uc378\ub124\uc77c\uac80\uc0c9",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1780,
        300
      ]
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "download",
        "fileId": "={{ $json.id }}",
        "options": {
          "binaryPropertyName": "thumbnail_data"
        }
      },
      "id": "drive-download-thumbnail",
      "name": "Drive \uc378\ub124\uc77c\ub2e4\uc6b4\ub85c\ub4dc",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        2000,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://www.googleapis.com/upload/youtube/v3/thumbnails/set?videoId={{ $('YouTube \uc5c5\ub85c\ub4dc').item.json.id }}&uploadType=media",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "youTubeOAuth2Api",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "image/png"
            }
          ]
        },
        "sendBinaryData": true,
        "binaryPropertyName": "thumbnail_data",
        "options": {}
      },
      "id": "youtube-set-thumbnail",
      "name": "YouTube \uc378\ub124\uc77c \uc124\uc815",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        2220,
        300
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "pageId": "={{ $('\uba54\ud0c0\ub370\uc774\ud130 \ud30c\uc2f1').item.json.notion_page_id }}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "\uc0c1\ud0dc|status",
              "statusValue": "\uc644\ub8cc"
            },
            {
              "key": "\uc601\uc0c1 URL|url",
              "urlValue": "=https://youtu.be/{{ $('YouTube \uc5c5\ub85c\ub4dc').item.json.id }}"
            },
            {
              "key": "\uc5c5\ub85c\ub4dc \uc77c\uc2dc|date",
              "date": "={{ $now.toISO() }}"
            }
          ]
        }
      },
      "id": "notion-status-complete",
      "name": "Notion \uc0c1\ud0dc \uc644\ub8cc",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        2440,
        300
      ]
    }
  ],
  "connections": {
    "\uc218\ub3d9 \ud2b8\ub9ac\uac70": {
      "main": [
        [
          {
            "node": "Notion \ub300\uae30\uc601\uc0c1 \uc870\ud68c",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notion \ub300\uae30\uc601\uc0c1 \uc870\ud68c": {
      "main": [
        [
          {
            "node": "Notion \uc0c1\ud0dc \uc5c5\ub85c\ub4dc\uc911",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notion \uc0c1\ud0dc \uc5c5\ub85c\ub4dc\uc911": {
      "main": [
        [
          {
            "node": "\uba54\ud0c0\ub370\uc774\ud130 \ud30c\uc2f1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\uba54\ud0c0\ub370\uc774\ud130 \ud30c\uc2f1": {
      "main": [
        [
          {
            "node": "Drive \uc601\uc0c1\uac80\uc0c9",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Drive \uc601\uc0c1\uac80\uc0c9": {
      "main": [
        [
          {
            "node": "Drive \uc601\uc0c1\ub2e4\uc6b4\ub85c\ub4dc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Drive \uc601\uc0c1\ub2e4\uc6b4\ub85c\ub4dc": {
      "main": [
        [
          {
            "node": "YouTube \uc5c5\ub85c\ub4dc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YouTube \uc5c5\ub85c\ub4dc": {
      "main": [
        [
          {
            "node": "Drive \uc378\ub124\uc77c\uac80\uc0c9",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Drive \uc378\ub124\uc77c\uac80\uc0c9": {
      "main": [
        [
          {
            "node": "Drive \uc378\ub124\uc77c\ub2e4\uc6b4\ub85c\ub4dc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Drive \uc378\ub124\uc77c\ub2e4\uc6b4\ub85c\ub4dc": {
      "main": [
        [
          {
            "node": "YouTube \uc378\ub124\uc77c \uc124\uc815",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YouTube \uc378\ub124\uc77c \uc124\uc815": {
      "main": [
        [
          {
            "node": "Notion \uc0c1\ud0dc \uc644\ub8cc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Asia/Seoul"
  }
}