{"meta":{"instanceId":"40e2ddc17723de14c7d0537f9006dd246a3f4df33df6ca7f746ccb612d5f27b9","templateCredsSetupCompleted":true},"nodes":[{"id":"fa800f3c-f679-4d51-a3dc-30c07531e7e1","name":"Get Video Data","type":"n8n-nodes-base.httpRequest","position":[1420,660],"parameters":{"url":"https://www.googleapis.com/youtube/v3/videos","options":{},"sendQuery":true,"sendHeaders":true,"queryParameters":{"parameters":[{"name":"part","value":"snippet,statistics,contentDetails,status,topicDetails,recordingDetails,liveStreamingDetails,localizations,player"},{"name":"id","value":"={{ $json.videoid }}"},{"name":"key","value":"={{ $('Set you keys').item.json.api_key }}"}]},"headerParameters":{"parameters":[{"name":"Accept","value":"application/json"}]}},"typeVersion":4.2},{"id":"7d1d2e06-a1ab-4e37-8e27-fe30abe312fd","name":"Get Video IDs","type":"n8n-nodes-base.httpRequest","position":[280,440],"parameters":{"url":"https://www.googleapis.com/youtube/v3/search","options":{},"sendQuery":true,"sendHeaders":true,"queryParameters":{"parameters":[{"name":"part","value":"snippet"},{"name":"maxResults","value":"={{ $json.videoLimit || 1}}"},{"name":"order","value":"viewCount"},{"name":"publishedAfter","value":"={{ $now.minus({days: 7}).startOf('day').toISO() }}"},{"name":"publishedBefore","value":"={{ $now.toISO() }}"},{"name":"q","value":"={{ $json.search_term }}"},{"name":"type","value":"video"},{"name":"videoDuration","value":"={{ $json.format }}"},{"name":"key","value":"={{ $json.api_key }}"},{"name":"regionCode","value":"US"}]},"headerParameters":{"parameters":[{"name":"Accept","value":"application/json"}]}},"typeVersion":4.2},{"id":"9c779f52-da65-4d4d-943f-982eb87a6170","name":"Extract IDs","type":"n8n-nodes-base.code","position":[600,660],"parameters":{"jsCode":"const items = $input.all();\nreturn items.flatMap(item => \n  (item.json?.items || []).map(videoItem => ({\n    json: {\n      videoid: videoItem?.id?.videoId || null\n    }\n  }))\n);"},"typeVersion":2},{"id":"05d526bd-92ec-4ff4-8fa1-526fc44eace7","name":"Extract Video Data","type":"n8n-nodes-base.code","position":[1760,880],"parameters":{"jsCode":"const items = $input.all();\nreturn items.flatMap(item =>\n  (item.json?.items || []).map(videoItem => ({\n    json: {\n      channelTitle: videoItem.snippet?.channelTitle || '',\n      channel:\"https://www.youtube.com/channel/\"+$input.first().json.items[0].snippet.channelId,\n      title: videoItem.snippet?.title || '',\n      viewCount: videoItem.statistics?.viewCount || 0,\n      likeCount: videoItem.statistics?.likeCount || 0,\n      commentCount: videoItem.statistics?.commentCount || 0,\n      videoURL: `https://www.youtube.com/watch?v=${videoItem.id || ''}`,\n      thumbnail: videoItem.snippet?.thumbnails?.maxres?.url || '',\n      thumbnailPreview:`=IMAGE(\"${videoItem.snippet?.thumbnails?.maxres?.url || ''}\" ,4,200,150)`\n    }\n  }))\n);"},"typeVersion":2},{"id":"51b68aa9-1ee9-434d-8509-2f7488764969","name":"Video Performance","type":"n8n-nodes-base.code","position":[1980,880],"parameters":{"jsCode":"const items = $input.all();\nreturn items.map(item => {\n  const viewCount = parseInt(String(item.json?.viewCount || '0'), 10);\n  const likeCount = parseInt(String(item.json?.likeCount || '0'), 10);\n  const commentCount = parseInt(String(item.json?.commentCount || '0'), 10);\n\n  \n  let performance = 0;\n  \n  if (viewCount > 0) {\n    // Calculate engagement rate and scale by 10x for more realistic YouTube scores\n    const engagementRate = ((likeCount + commentCount) / viewCount) * 1000; // 10x boost\n    performance = Math.min(Math.max(engagementRate, 0), 100);\n  }\n  \n  const roundedPerformance = Math.round(performance);\n  \n  let performanceText = \"💀 Dead\";\n  \n  // Adjusted thresholds for realistic YouTube engagement rates (much stricter)\n  if (roundedPerformance >= 80) {\n    performanceText = \"🚀 HOLY HELL\"; // 8%+ engagement = truly exceptional/viral\n  } else if (roundedPerformance >= 60) {\n    performanceText = \"🔥 INSANE\"; // 6%+ engagement = insane performance\n  } else if (roundedPerformance >= 40) {\n    performanceText = \"💪 CRUSHING IT\"; // 4%+ engagement = crushing it\n  } else if (roundedPerformance >= 30) {\n    performanceText = \"⭐ Stellar\"; // 3%+ engagement = stellar\n  } else if (roundedPerformance >= 20) {\n    performanceText = \"💪 Strong\"; // 2%+ engagement = strong\n  } else if (roundedPerformance >= 15) {\n    performanceText = \"😊 Good\"; // 1.5%+ engagement = good\n  } else if (roundedPerformance >= 10) {\n    performanceText = \"🙂 Decent\"; // 1%+ engagement = decent\n  } else if (roundedPerformance >= 5) {\n    performanceText = \"😐 Average\"; // 0.5%+ engagement = average\n  } else {\n    // Use switch for very low scores (0-4%)\n    switch(roundedPerformance) {\n      case 0: performanceText = \"💀 Dead\"; break;\n      case 1: performanceText = \"😴 Sleeping\"; break;\n      case 2: performanceText = \"😐 Meh\"; break;\n      case 3: performanceText = \"😕 Not good\"; break;\n      case 4: performanceText = \"😞 Poor\"; break;\n      default: performanceText = \"💀 Dead\";\n    }\n  }\n  $input.first().json.performance = performance;\n  $input.first().json.performanceText = performanceText;\n  \n  \n  return {\n    ...$json\n  };\n});"},"typeVersion":2},{"id":"0112f55c-b506-4a08-8ce4-7f5c8b8a0e3e","name":"Sticky Note","type":"n8n-nodes-base.stickyNote","position":[-240,620],"parameters":{"color":4,"width":344,"height":208,"content":"# Start\n\n1. Send your search term\n2. And Select format -'short', 'medium' or 'long'\n\nEg: best open source workflow tool"},"typeVersion":1},{"id":"9d7abab9-7af2-4b2f-a1bf-d07086a95330","name":"Sticky Note2","type":"n8n-nodes-base.stickyNote","position":[20,220],"parameters":{"color":5,"width":336,"height":192,"content":"# Video ID's\n\n### Simply just getting the video ID's from YouTube API\n\nAdd your Google API key here"},"typeVersion":1},{"id":"c5d4d3a4-2f54-42e6-bf6e-914e8cb3c9b7","name":"Sticky Note3","type":"n8n-nodes-base.stickyNote","position":[600,820],"parameters":{"width":432,"height":196,"content":"# Extracting ID's\n\n### Extracting video ID's so we can feed them into the next YouTube API endpoint"},"typeVersion":1},{"id":"fb8111db-b21c-44b1-b4f8-8251cf09e720","name":"Sticky Note4","type":"n8n-nodes-base.stickyNote","position":[1160,340],"parameters":{"color":5,"width":408,"height":224,"content":"# Get Video Data\n\n### Now we're getting the video data from each of the video ID's. Titles, likes, views, comments, etc\n\nAdd your Google API key here"},"typeVersion":1},{"id":"c338fb9c-2eeb-425c-a234-49c2d948cccc","name":"Sticky Note5","type":"n8n-nodes-base.stickyNote","position":[1180,860],"parameters":{"width":364,"height":192,"content":"# Extracting Video Data\n\n### Extracting the video engagement metrics"},"typeVersion":1},{"id":"933503b9-507a-422a-9dcd-a520466cee01","name":"Sticky Note6","type":"n8n-nodes-base.stickyNote","position":[1700,160],"parameters":{"width":352,"height":192,"content":"# Video Performance\n\n### Using a simple calculation to determine video performance, allowing us to see what is performing well vs. not"},"typeVersion":1},{"id":"6e286763-02b6-4dd3-9c0b-6233ce64aa62","name":"Sticky Note7","type":"n8n-nodes-base.stickyNote","position":[2440,360],"parameters":{"color":5,"width":432,"height":240,"content":"# Send to Google Sheets\n\n### Upload everything to our google sheet so we can view everything easier\n"},"typeVersion":1},{"id":"8bf37e0f-9b9c-4f16-be2e-02ea952c4488","name":"Append row in sheet","type":"n8n-nodes-base.googleSheets","position":[2720,640],"parameters":{"columns":{"value":{},"schema":[{"id":"viewCount","type":"string","display":true,"removed":false,"required":false,"displayName":"viewCount","defaultMatch":false,"canBeUsedToMatch":true},{"id":"subscriberCount","type":"string","display":true,"removed":false,"required":false,"displayName":"subscriberCount","defaultMatch":false,"canBeUsedToMatch":true},{"id":"hiddenSubscriberCount","type":"string","display":true,"removed":false,"required":false,"displayName":"hiddenSubscriberCount","defaultMatch":false,"canBeUsedToMatch":true},{"id":"videoCount","type":"string","display":true,"removed":false,"required":false,"displayName":"videoCount","defaultMatch":false,"canBeUsedToMatch":true},{"id":"channelTitle","type":"string","display":true,"removed":false,"required":false,"displayName":"channelTitle","defaultMatch":false,"canBeUsedToMatch":true},{"id":"channel","type":"string","display":true,"removed":false,"required":false,"displayName":"channel","defaultMatch":false,"canBeUsedToMatch":true},{"id":"title","type":"string","display":true,"removed":false,"required":false,"displayName":"title","defaultMatch":false,"canBeUsedToMatch":true},{"id":"likeCount","type":"string","display":true,"removed":false,"required":false,"displayName":"likeCount","defaultMatch":false,"canBeUsedToMatch":true},{"id":"commentCount","type":"string","display":true,"removed":false,"required":false,"displayName":"commentCount","defaultMatch":false,"canBeUsedToMatch":true},{"id":"videoURL","type":"string","display":true,"removed":false,"required":false,"displayName":"videoURL","defaultMatch":false,"canBeUsedToMatch":true},{"id":"thumbnail","type":"string","display":true,"removed":false,"required":false,"displayName":"thumbnail","defaultMatch":false,"canBeUsedToMatch":true},{"id":"thumbnailPreview","type":"string","display":true,"removed":false,"required":false,"displayName":"thumbnailPreview","defaultMatch":false,"canBeUsedToMatch":true},{"id":"performance","type":"string","display":true,"removed":false,"required":false,"displayName":"performance","defaultMatch":false,"canBeUsedToMatch":true},{"id":"performanceText","type":"string","display":true,"removed":false,"required":false,"displayName":"performanceText","defaultMatch":false,"canBeUsedToMatch":true},{"id":"youtubeUrl","type":"string","display":true,"removed":false,"required":false,"displayName":"youtubeUrl","defaultMatch":false,"canBeUsedToMatch":true},{"id":"label","type":"string","display":true,"removed":false,"required":false,"displayName":"label","defaultMatch":false,"canBeUsedToMatch":true},{"id":"viewToSubRatio","type":"string","display":true,"removed":false,"required":false,"displayName":"viewToSubRatio","defaultMatch":false,"canBeUsedToMatch":true}],"mappingMode":"autoMapInputData","matchingColumns":[],"attemptToConvertTypes":false,"convertFieldsToString":false},"options":{"useAppend":true},"operation":"append","sheetName":{"__rl":true,"mode":"list","value":"gid=0","cachedResultUrl":"https://docs.google.com/spreadsheets/d/1oOxuTacCQ_57knZTaTtohQZ9qYY2WHmozes-E-1YG_I/edit#gid=0","cachedResultName":"Youtube Videos"},"documentId":{"__rl":true,"mode":"list","value":"1oOxuTacCQ_57knZTaTtohQZ9qYY2WHmozes-E-1YG_I","cachedResultUrl":"https://docs.google.com/spreadsheets/d/1oOxuTacCQ_57knZTaTtohQZ9qYY2WHmozes-E-1YG_I/edit?usp=drivesdk","cachedResultName":"YouTube Viral Videos"}},"credentials":{"googleSheetsOAuth2Api":{"id":"9NL9w5d9bKz7xt16","name":"Akash Google Sheet Account"}},"typeVersion":4.6},{"id":"433ee6cf-2c84-4131-9bf8-a0f00d1c04ca","name":"On form submission","type":"n8n-nodes-base.formTrigger","position":[-240,440],"webhookId":"77ab6399-3597-439f-a2b2-3641e7a4fceb","parameters":{"options":{},"formTitle":"test","formFields":{"values":[{"fieldLabel":"Share your idea?","placeholder":"Eg. Best automation tool","requiredField":true},{"fieldType":"dropdown","fieldLabel":"Format","fieldOptions":{"values":[{"option":"short"},{"option":"medium"},{"option":"long"}]},"requiredField":true},{"fieldType":"number","fieldLabel":"Number of Videos","placeholder":"Enter number of video to research by default 1","requiredField":true}]},"formDescription":"tets"},"typeVersion":2.2},{"id":"e7daac48-5d66-4ba3-8753-614f46d40515","name":"Get Channel Statistics","type":"n8n-nodes-base.httpRequest","position":[1760,420],"parameters":{"url":"https://www.googleapis.com/youtube/v3/channels","options":{"redirect":{"redirect":{}}},"sendQuery":true,"queryParameters":{"parameters":[{"name":"part","value":"snippet,statistics,contentDetails"},{"name":"id","value":"={{ $json.items[0].snippet.channelId }}"},{"name":"key","value":"={{ $('Set you keys').item.json.api_key }}"}]}},"typeVersion":4.2},{"id":"f06636a4-df6c-4de4-bfed-6b44b5835c85","name":"Merge","type":"n8n-nodes-base.merge","position":[2240,640],"parameters":{"mode":"combine","options":{},"combineBy":"combineAll"},"typeVersion":3.2},{"id":"d97a43b5-4646-4e2b-b6f3-e815dac5eeed","name":"Channel Data","type":"n8n-nodes-base.code","position":[1980,420],"parameters":{"jsCode":"// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nvar json = {}\n\njson = $input.first().json.items[0].statistics;\n\n\nreturn [json];"},"typeVersion":2},{"id":"2856d447-5cc2-428b-a443-d6cd9d0d2ecd","name":"Code","type":"n8n-nodes-base.code","position":[2460,640],"parameters":{"jsCode":"return $input.all().map(item => {\n  const views = parseInt(item.json.viewCount || '0');\n  const subs = parseInt(item.json.subscriberCount || '0');\n\n  let label = '';\n  const ratio = subs > 0 ? views / subs : 0;\n\n  if ((subs < 500 && views > 5000) || (ratio > 1 && subs > 1000)) {\n    label = 'Outlier';\n  } else if (ratio < 0.02) {\n    label = 'Bad';\n  } else if (ratio >= 0.02 && ratio < 0.1) {\n    label = 'Okay';\n  } else if (ratio >= 0.1) {\n    label = 'Good';\n  } else {\n    label = 'Uncategorized';\n  }\n\n  return {\n    json: {\n      ...item.json,\n      label,\n      viewToSubRatio: ratio.toFixed(4)\n    }\n  };\n});\n"},"typeVersion":2},{"id":"2d5c7fe7-ae08-4919-937b-d089dcacb07a","name":"Loop Over Items","type":"n8n-nodes-base.splitInBatches","position":[1080,660],"parameters":{"options":{}},"typeVersion":3},{"id":"cffd4aad-67c7-405b-b1bf-816e93db3c01","name":"Wait","type":"n8n-nodes-base.wait","position":[2740,960],"webhookId":"7f98e718-4009-410d-8039-6ef89e198c97","parameters":{"amount":2},"typeVersion":1.1},{"id":"92302dac-6e31-46a6-8740-820f15c41541","name":"Sticky Note1","type":"n8n-nodes-base.stickyNote","position":[-1020,180],"parameters":{"width":700,"height":1280,"content":"# 🔍 YouTube Viral Video Research Workflow 📈 — Bulk Video Analysis for Viral Content!\n\n🚀 **Discover trending and viral YouTube videos easily with this powerful n8n automation!** This workflow helps you perform bulk research on YouTube videos related to any search term, analyzing engagement data like views, likes, comments, and channel statistics — all in one streamlined process.\n\n✨ **Perfect for:**  \n- Content creators wanting to find viral video ideas  \n- Marketers analyzing competitor content  \n- YouTubers optimizing their content strategy\n\n### How It Works 🎯\n\n1️⃣ **Input Your Search Term** — Simply enter any keyword or topic you want to research.  \n2️⃣ **Select Video Format** — Choose between `short`, `medium`, or `long` videos.  \n3️⃣ **Choose Number of Videos** — Define how many videos to analyze in bulk.  \n4️⃣ **Automatic Data Fetch** — The workflow grabs video IDs, then fetches detailed video data and channel statistics from the YouTube API.  \n5️⃣ **Performance Scoring** — Videos are scored based on engagement rates with easy-to-understand labels like 🚀 *HOLY HELL* (viral) or 💀 *Dead*.  \n6️⃣ **Export to Google Sheets** — All data, including thumbnails and video URLs, is appended to your Google Sheet for comprehensive review and easy sharing.\n\n### Setup Instructions 🛠️\n\n1. **Google API Key**  \n   - Get your YouTube Data API key from [Google Developers Console](https://console.developers.google.com/).  \n   - Add it securely in the n8n credentials manager (do **not** hardcode).\n\n2. **Google Sheets Setup**  \n   - Create a Google Sheet to store your results (template link is provided).  \n   - Share the sheet with your Google account used in n8n.  \n   - Update the workflow with your sheet's Document ID and Sheet Name if needed.\n\n3. **Run the Workflow**  \n   - Trigger the form webhook via browser or POST call.  \n   - Enter search term, format, and number of videos.  \n   - Let it process and check your Google Sheet for insights!\n\n### Features ✨\n\n- Bulk fetches the latest and top-viewed YouTube videos.  \n- Intelligent video performance scoring with emojis for quick insights 🔥🎬.  \n- Organizes data into Google Sheets with thumbnail previews 🖼️.  \n- Easy to customize search parameters via an intuitive form.  \n- Fully automated, no manual API calls needed.\n\n### Get Started Today! 🌟\n\nBoost your YouTube content strategy and stay ahead with this powerful viral video research automation! Try it now on your n8n instance and tap into the world of viral content like a pro 🎥💡\n"},"typeVersion":1},{"id":"e0e91135-4c24-4566-8eb2-4d23fc133b1c","name":"Set you keys","type":"n8n-nodes-base.set","position":[20,440],"parameters":{"options":{},"assignments":{"assignments":[{"id":"e04aa951-a569-4adc-ae0f-727e5b678ed9","name":"api_key","type":"string","value":"<api-key>"},{"id":"490f5e38-e3eb-463e-8716-9ac1f92651c8","name":"search_term","type":"string","value":"={{ $json[\"Share your idea?\"] }}"},{"id":"69b72b2f-6edc-4a00-b4e9-3e72a48e1322","name":"format","type":"string","value":"={{ $json.Format }}"},{"id":"545e6c23-0b63-4461-b9e2-dd8ff1fd00bd","name":"videoLimit","type":"string","value":"={{ $json[\"Number of Videos\"] }}"}]}},"typeVersion":3.4}],"pinData":{},"connections":{"Code":{"main":[[{"node":"Append row in sheet","type":"main","index":0}]]},"Wait":{"main":[[{"node":"Loop Over Items","type":"main","index":0}]]},"Merge":{"main":[[{"node":"Code","type":"main","index":0}]]},"Extract IDs":{"main":[[{"node":"Loop Over Items","type":"main","index":0}]]},"Channel Data":{"main":[[{"node":"Merge","type":"main","index":0}]]},"Set you keys":{"main":[[{"node":"Get Video IDs","type":"main","index":0}]]},"Get Video IDs":{"main":[[{"node":"Extract IDs","type":"main","index":0}]]},"Get Video Data":{"main":[[{"node":"Extract Video Data","type":"main","index":0},{"node":"Get Channel Statistics","type":"main","index":0}]]},"Loop Over Items":{"main":[[],[{"node":"Get Video Data","type":"main","index":0}]]},"Video Performance":{"main":[[{"node":"Merge","type":"main","index":1}]]},"Extract Video Data":{"main":[[{"node":"Video Performance","type":"main","index":0}]]},"On form submission":{"main":[[{"node":"Set you keys","type":"main","index":0}]]},"Append row in sheet":{"main":[[{"node":"Wait","type":"main","index":0}]]},"Get Channel Statistics":{"main":[[{"node":"Channel Data","type":"main","index":0}]]}}}