{
  "nodes": [
    {
      "id": "42e836f4-219d-4ad7-9f01-aec4aedeaf25",
      "name": "Google Gemini Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -240,
        0
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "7f95419d-4916-4aa5-9db4-0f65df350eb9",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -112,
        0
      ],
      "parameters": {
        "sessionKey": "chat",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "7de516ce-cd4a-4628-b59e-30d1008f0e87",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        16,
        0
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"title\": \"object\",\n    \"description\": \"object\",\n    \"tags\": \"object\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "a4033f3e-2c8b-4009-b298-c5ea8e6299b4",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -944,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 388,
        "height": 304,
        "content": "## Set and Retrieve Information"
      },
      "typeVersion": 1
    },
    {
      "id": "b9dddc83-b3a2-4935-ae62-a39eb1af3864",
      "name": "Output URL",
      "type": "n8n-nodes-base.set",
      "position": [
        448,
        -224
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ffd3b7ab-4ac6-4c71-8ee1-a6c93732a701",
              "name": "URL",
              "type": "string",
              "value": "=https://studio.youtube.com/video/{{ $('Fetches video information').item.json.id }}/translations"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c84d84a2-6093-436e-9a37-597331d917e0",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1936,
        -448
      ],
      "parameters": {
        "width": 678,
        "height": 560,
        "content": "## YouTube Video Title and Description Translator\n\nIf you want to reach a wider audience, having your video title and description in multiple languages can help you connect with more viewers.\n\n### Requirements\n\n- YouTube Auth (In the **Fetch Video Information** node)\n- Google Gemini (PaLM) API (In the **AI Agent Translator** node)\n\n### How to Use\n\n- (First time only) Set up credentials for your user.\n- Edit the node \"Defines Video ID and Languages\".\n  - Modify the REPLACEME value with the video ID to translate.\n  - Update the languages and the localizations you want to use.\n- Click the Execute Workflow button.\n- Enjoy your translated video titles and descriptions!\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "ffdab92b-7d0a-460d-a4a5-5929a8d4695c",
      "name": "Fetches video information",
      "type": "n8n-nodes-base.youTube",
      "position": [
        -704,
        -224
      ],
      "parameters": {
        "options": {},
        "videoId": "={{ $json.video }}",
        "resource": "video",
        "operation": "get"
      },
      "credentials": {
        "youTubeOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8ec32768-a9c3-4dfd-9b96-2b88f81fcaed",
      "name": "Check languages to translate",
      "type": "n8n-nodes-base.code",
      "position": [
        -464,
        -224
      ],
      "parameters": {
        "jsCode": "// Get default language from the incoming item\nconst defaultLang = $input.first().json?.snippet?.defaultLanguage ?? 'en';\n\n// Get your mapping of name -> code from the node named: When clicking \u2018Execute workflow\u2019\nconst nameToCode = $('Defines Video ID and Languages').first().json.languages || {};\n\n// Build result excluding the default language\nconst entries = Object.entries(nameToCode).filter(([, code]) => code !== defaultLang);\n\nconst languages = entries.map(([name]) => name);\nconst keys = Object.fromEntries(entries);\n\n// Return a single item with the desired JSON\nreturn [\n  {\n    json: {\n      defaultLang,   // e.g. defaults to en\n      languages,     // e.g. [\"spanish\",\"japanese\"]\n      keys           // e.g. { spanish: \"es\", japanese: \"ja\" }\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "f513101f-9911-48d8-bd49-a5ddfbb8e00d",
      "name": "AI Agent Translator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "maxTries": 2,
      "position": [
        -192,
        -224
      ],
      "parameters": {
        "text": "=Translate the youtube video which has a default language of {{ $json.defaultLang }}, to {{ $json.languages }}.\n\nThis is the title: {{ $('Fetches video information').item.json.snippet.title }}\n\nand the description: {{ $('Fetches video information').item.json.snippet.description }}\n\nYou may suggest tags \n\nReturn only the translated languages in json format, with this structure:\n\n{\n      \"LANGUAGE KEY 1\": { \"title\": \"Example\", \"description\": \"Example desc\" },\n      \"LANGUAGE KEY 2\": { \"title\": \"Ejemplo\", \"description\": \"Desc Ejemplo\" },\n}",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "retryOnFail": true,
      "typeVersion": 2.2,
      "waitBetweenTries": 5000
    },
    {
      "id": "9861fb97-a088-45e1-baad-2f3e4b0d52e0",
      "name": "Updates Video Localization",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        208,
        -224
      ],
      "parameters": {
        "url": "https://www.googleapis.com/youtube/v3/videos?part=snippet,localizations",
        "method": "PUT",
        "options": {},
        "jsonBody": "={{\n{\nid: $(\"Fetches video information\").item.json.id,\nsnippet: {\ndefaultLanguage: $('Check languages to translate').item.json.defaultLang,\ntitle: $('Fetches video information').item.json.snippet.title,\ndescription: $('Fetches video information').item.json.snippet.description,\ncategoryId: $('Fetches video information').item.json.snippet.categoryId,\ntags: $('Fetches video information').item.json.snippet.tags\n},\nlocalizations: $json.output\n}\n}}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "youTubeOAuth2Api"
      },
      "credentials": {
        "youTubeOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "2d36fc0b-bd82-4b8a-a6c1-1a78d3e499e9",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -528,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 628,
        "height": 304,
        "content": "## Language Translation"
      },
      "typeVersion": 1
    },
    {
      "id": "11660cdc-4c28-4ecd-9898-684010a5bbd7",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 580,
        "height": 304,
        "content": "## Update Localization and Return YouTube URL"
      },
      "typeVersion": 1
    },
    {
      "id": "93132f37-61eb-4de7-9e75-d9703b95c486",
      "name": "When clicking 'Execute workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1120,
        -224
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "b538cca6-dead-408f-9648-b2683099b345",
      "name": "Defines Video ID and Languages",
      "type": "n8n-nodes-base.set",
      "position": [
        -896,
        -224
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "{\n  \"video\": \"REPLACEME\",\n  \"languages\": {\n    \"english\": \"en\",\n    \"spanish\": \"es-419\",\n    \"japanese\": \"ja\"\n  }\n}\n",
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    }
  ],
  "connections": {
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent Translator",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent Translator": {
      "main": [
        [
          {
            "node": "Updates Video Localization",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent Translator",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Fetches video information": {
      "main": [
        [
          {
            "node": "Check languages to translate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent Translator",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Updates Video Localization": {
      "main": [
        [
          {
            "node": "Output URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check languages to translate": {
      "main": [
        [
          {
            "node": "AI Agent Translator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Defines Video ID and Languages": {
      "main": [
        [
          {
            "node": "Fetches video information",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking 'Execute workflow'": {
      "main": [
        [
          {
            "node": "Defines Video ID and Languages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}