{
  "name": "Youtube Transcript Scraper Demo file",
  "nodes": [
    {
      "parameters": {
        "functionCode": "const apiResponse = $input.first().json; // Data from the \"Fetch Channel Videos1\" node (API response)\nconst processInputData = $('Process Channel Input').item.json; // Data from your \"Process Channel Input\" node\n\nconst videosList = apiResponse.body && Array.isArray(apiResponse.body.data) ? apiResponse.body.data : [];\n\n// Get the number of videos requested, sourced reliably from \"Process Channel Input\"\nlet limit = Number(processInputData.maxResults);\n\n// Fallback if 'limit' is not a valid number (e.g., NaN)\n// This might happen if 'maxResults' was unexpectedly not a number, though your \"Process Channel Input\" node has a default.\nif (isNaN(limit)) {\n  // If the intended limit isn't a valid number, default to processing all videos returned by the API.\n  // You might want to log an error here in a production workflow if this case is reached.\n  // console.error(\"Warning: maxResults from 'Process Channel Input' was not a valid number. Defaulting to API list length.\");\n  limit = videosList.length;\n}\n\n// Get the channelId reliably from \"Process Channel Input\"\nconst sourceChannelId = processInputData.channelId || \"\";\n\n// Enforce the limit and return as separate n8n items\nreturn videosList.slice(0, limit).map(video => ({\n  json: {\n    videoId: video.videoId || video.id || \"\",\n    title: video.title || \"\",\n    // channelTitle relies on the API response structure; adjust if necessary\n    channelTitle: apiResponse.body?.meta?.title || \"\",\n    channelId: sourceChannelId,\n    publishedAt: video.publishDate || video.publishedAt || new Date().toISOString(),\n    description: video.description || \"\"\n  }\n}));"
      },
      "id": "ece70f56-0895-481a-aa4a-9ad2a3b8d188",
      "name": "Extract Video IDs",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        2880,
        -340
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "5dddfb3a-c731-459e-89ea-88b0af5d27cc",
      "name": "Loop Over Videos",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        3100,
        -380
      ]
    },
    {
      "parameters": {
        "url": "https://youtube-transcribe-fastest-youtube-transcriber.p.rapidapi.com/transcript",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "=url",
              "value": "=https://www.youtube.com/watch?v={{ $json.videoId }}"
            },
            {
              "name": "lang",
              "value": "en"
            },
            {
              "name": "=videoId",
              "value": "={{ $json.videoId }}"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-rapidapi-host",
              "value": "youtube-transcribe-fastest-youtube-transcriber.p.rapidapi.com"
            },
            {
              "name": "x-rapidapi-key",
              "value": "your key here"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        }
      },
      "id": "42d6b710-42a9-4c96-9138-9504c30fcfa4",
      "name": "Get Video Transcript",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        3320,
        -420
      ]
    },
    {
      "parameters": {
        "functionCode": "// Process chunked transcript response\nconst videoInfo = $input.first().json;\nconst response = $input.first().json;\n\n// Initialize variables\nlet success = false;\nlet transcript = \"Transcription failed\";\nlet errorMsg = \"\";\n\n// Process the response\nif (response && response.statusCode < 400) {\n  // Check for error message in the response\n  if (response.body && response.body.error) {\n    errorMsg = response.body.error;\n    transcript = `Error: ${errorMsg}`;\n  }\n  // Check for chunked transcript format\n  else if (response.body && response.body.data && response.body.data.chunks) {\n    const chunks = response.body.data.chunks;\n    // Join all text chunks into a single transcript\n    if (chunks.length > 0) {\n      success = true;\n      transcript = chunks.map(chunk => chunk.text).join(\" \");\n    }\n  }\n  // Check for simple transcript format (fallback)\n  else if (response.body && response.body.transcript) {\n    success = true;\n    transcript = response.body.transcript;\n  }\n}\n\n// Calculate metrics\nconst wordCount = success ? transcript.split(/\\s+/).length : 0;\n\n// Return combined data\nreturn {\n  json: {\n    videoId: videoInfo.videoId || \"\",\n    title: videoInfo.title || \"\",\n    channelTitle: videoInfo.channelTitle || \"Unknown\",\n    channelId: videoInfo.channelId || \"Unknown\",\n    channelName: videoInfo.channelName || \"Unknown\",\n    transcript: transcript,\n    error: errorMsg,\n    wordCount: wordCount,\n    success: success,\n    processedAt: new Date().toISOString()\n  }\n};"
      },
      "id": "b0019803-fcac-4e2b-b0ba-fc9ccd8ec04a",
      "name": "Format Transcript",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        3540,
        -420
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "https://docs.google.com/spreadsheets/d/1MFhnm14OZ_saL7ht_84_vRWNKXc6UAQotrr4c882_kU/edit?gid=21452698#gid=21452698",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": 21452698,
          "mode": "list",
          "cachedResultName": "Transcripts",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1MFhnm14OZ_saL7ht_84_vRWNKXc6UAQotrr4c882_kU/edit#gid=21452698"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "transcript": "={{ $json.transcript }}",
            "title": "={{ $('Loop Over Videos').item.json.title }}",
            "videoId": "={{ $('Loop Over Videos').item.json.videoId }}",
            "channelTitle": "={{ $('Loop Over Videos').item.json.channelTitle }}",
            "channelId": "={{ $('Loop Over Videos').item.json.channelId }}",
            "publishedAt": "={{ $('Loop Over Videos').item.json.publishedAt }}",
            "processedAt": "={{ $json.processedAt }}",
            "wordCount": "={{ $json.wordCount }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "videoId",
              "displayName": "videoId",
              "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": "channelTitle",
              "displayName": "channelTitle",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "channelName",
              "displayName": "channelName",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "channelId",
              "displayName": "channelId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "publishedAt",
              "displayName": "publishedAt",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "processedAt",
              "displayName": "processedAt",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "transcriptLength",
              "displayName": "transcriptLength",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "wordCount",
              "displayName": "wordCount",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "language",
              "displayName": "language",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "transcript",
              "displayName": "transcript",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "99483779-dc6f-474c-bbde-b501b49ed799",
      "name": "Save Transcripts",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        3760,
        -420
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "bCbMm3In59SNnTTP",
          "name": "Google Sheets account 3"
        }
      }
    },
    {
      "parameters": {
        "amount": 10
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        3980,
        -340
      ],
      "id": "4f0fb393-6f8f-4817-a35a-3bf9780badf9",
      "name": "Wait",
      "webhookId": "6f487777-1edc-48b1-8cb5-92f254688b77"
    },
    {
      "parameters": {
        "functionCode": "// Expecting only Channel ID (UC...)\nconst channelId = $input.first().json['Channel ID'].trim();\nconst maxResults = parseInt($input.first().json['Number of Videos']) || 5;\nreturn [{ json: { channelId, maxResults } }];\n"
      },
      "id": "d924da42-54d7-47a8-b5eb-b60edd732f92",
      "name": "Process Channel Input",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        2440,
        -340
      ]
    },
    {
      "parameters": {
        "formTitle": "YouTube Transcriber",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Channel ID",
              "requiredField": true
            },
            {
              "fieldLabel": "Number of Videos",
              "fieldType": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "2f717b44-f94c-4d83-94ad-3aed65b72cde",
      "name": "YouTube Transcriber Form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        2220,
        -340
      ],
      "webhookId": "e5ecfbf1-1cb1-499f-a82f-ac078fccaf3e"
    },
    {
      "parameters": {
        "url": "https://yt-api.p.rapidapi.com/channel/videos",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "id",
              "value": "={{ $json.channelId }}"
            },
            {
              "name": "order",
              "value": "date"
            },
            {
              "name": "maxResults",
              "value": "={{ $json.maxResults }}"
            },
            {
              "name": "hl",
              "value": "en"
            },
            {
              "name": "gl",
              "value": "US"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-rapidapi-host",
              "value": "yt-api.p.rapidapi.com"
            },
            {
              "name": "x-rapidapi-key",
              "value": "you key here"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        }
      },
      "id": "22d1d77d-ed0c-4ba5-adc1-085ee5e2ee44",
      "name": "Fetch Channel Videos",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        2660,
        -340
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "Extract Video IDs": {
      "main": [
        [
          {
            "node": "Loop Over Videos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Videos": {
      "main": [
        [],
        [
          {
            "node": "Get Video Transcript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Video Transcript": {
      "main": [
        [
          {
            "node": "Format Transcript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Transcript": {
      "main": [
        [
          {
            "node": "Save Transcripts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Transcripts": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Loop Over Videos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Channel Input": {
      "main": [
        [
          {
            "node": "Fetch Channel Videos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YouTube Transcriber Form": {
      "main": [
        [
          {
            "node": "Process Channel Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Channel Videos": {
      "main": [
        [
          {
            "node": "Extract Video IDs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "76c9edf3-7833-4f06-8efc-36d051315615",
  "meta": {
    "instanceId": "6a1d9aff65c1cfbb36a4b21b5694b101946094d7ded7133d53bde1d1948c117c"
  },
  "id": "BdVG8gaRlOEBO4ZP",
  "tags": []
}