{
  "version": "1.0.0",
  "exported_at": "2026-05-31T12:35:00.000Z",
  "project": {
    "name": "YouTube Comments  Replies Scraper",
    "description": "Best-effort scraper for public YouTube video comment threads. It loops through supplied YouTube video URLs, scrolls to lazy-load comments, expands visible reply/read-more controls, builds clean synthetic export rows in the browser, and exports usernames, comment text, publish time, likes, reply-thread fields, total comment count, crawl time, and comment URL. Uses navigate.urls[] plus loop-continue for multiple videos. YouTube may block automation with sign-in, bot checks, age restrictions, disabled comments, or private/unavailable videos.",
    "color": "bg-[#ff0000]",
    "template_id": "ai-generated"
  },
  "blocks": [
    {
      "block_id": "set-window-size-1",
      "block_type": "process",
      "title": "Set Window Size",
      "description": "Set browser viewport size",
      "position_x": 120,
      "position_y": 240,
      "config": {
        "width": 1920,
        "height": 1080,
        "color": "bg-[#4589ff]"
      }
    },
    {
      "block_id": "navigate-1",
      "block_type": "process",
      "title": "Navigate",
      "description": "Go to a URL",
      "position_x": 480,
      "position_y": 240,
      "config": {
        "urls": [
          "https://www.youtube.com/watch?v=xBBAD407zzU",
          "https://www.youtube.com/watch?v=WOuzDxHdz6I",
          "https://www.youtube.com/watch?v=Pm1P5hvsc-k"
        ],
        "color": "bg-[#08bdba]"
      }
    },
    {
      "block_id": "wait-for-page-load-1",
      "block_type": "process",
      "title": "Wait for Page Load",
      "description": "Wait for page to finish loading",
      "position_x": 840,
      "position_y": 240,
      "config": {
        "timeout": 45,
        "color": "bg-[#08bdba]"
      }
    },
    {
      "block_id": "wait-for-element-1",
      "block_type": "process",
      "title": "Wait for Element",
      "description": "Wait until element appears",
      "position_x": 1200,
      "position_y": 240,
      "config": {
        "selector": "ytd-watch-flexy",
        "timeout": 45,
        "visible": true,
        "color": "bg-[#08bdba]"
      }
    },
    {
      "block_id": "inject-javascript-1",
      "block_type": "process",
      "title": "Inject JavaScript",
      "description": "Run custom JavaScript",
      "position_x": 1560,
      "position_y": 240,
      "config": {
        "jsCode": "return (async () => {\n  const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));\n  const clean = (s) => (s || '').replace(/\\s+/g, ' ').trim();\n  const abs = (href) => href ? new URL(href, location.origin).href : '';\n\n  const clickVisible = async (el) => {\n    try {\n      if (!el) return false;\n      const rect = el.getBoundingClientRect();\n      if (rect.width === 0 || rect.height === 0) return false;\n      el.scrollIntoView({ block: 'center', inline: 'center' });\n      await sleep(250);\n      el.click();\n      await sleep(900);\n      return true;\n    } catch (e) {\n      return false;\n    }\n  };\n\n  const getPostCommentCount = () => {\n    const txt = clean((document.querySelector('ytd-comments-header-renderer h2') || document.querySelector('#count yt-formatted-string') || document.querySelector('#count'))?.textContent || '');\n    const m = txt.match(/[\\d,.]+/);\n    return m ? m[0] : txt;\n  };\n\n  const getVideoTitle = () => clean(((document.querySelector('h1.ytd-watch-metadata yt-formatted-string') || document.querySelector('h1 yt-formatted-string') || document.querySelector('h1'))?.textContent || document.title.replace(/ - YouTube$/, '')));\n\n  window.scrollTo(0, 0);\n  await sleep(1500);\n\n  let stableRounds = 0;\n  let lastAnyCommentCount = 0;\n  for (let i = 0; i < 65; i++) {\n    window.scrollBy(0, Math.floor(window.innerHeight * 0.9));\n    await sleep(850);\n\n    const readMoreButtons = Array.from(document.querySelectorAll('tp-yt-paper-button#more, ytd-expander tp-yt-paper-button#more, button'))\n      .filter(btn => /read more|show more|more/i.test(clean(btn.textContent || btn.getAttribute('aria-label') || '')));\n    for (const btn of readMoreButtons.slice(0, 10)) {\n      await clickVisible(btn);\n    }\n\n    const replyButtons = Array.from(document.querySelectorAll('button, ytd-button-renderer button, tp-yt-paper-button'))\n      .filter(btn => {\n        const txt = clean(btn.textContent || btn.getAttribute('aria-label') || '');\n        return /(view|show)\\s+(all\\s+)?(\\d+\\s+)?repl/i.test(txt) || /^\\d+\\s+repl/i.test(txt);\n      });\n    for (const btn of replyButtons.slice(0, 15)) {\n      await clickVisible(btn);\n    }\n\n    const anyCount = document.querySelectorAll('ytd-comment-thread-renderer, ytd-comment-renderer, ytd-comment-view-model').length;\n    if (anyCount === lastAnyCommentCount && anyCount > 0) {\n      stableRounds += 1;\n    } else {\n      stableRounds = 0;\n      lastAnyCommentCount = anyCount;\n    }\n    if (stableRounds >= 8) break;\n  }\n\n  await sleep(1000);\n\n  const old = document.querySelector('#uscraper-youtube-comment-export');\n  if (old) old.remove();\n\n  const container = document.createElement('div');\n  container.id = 'uscraper-youtube-comment-export';\n  container.style.position = 'absolute';\n  container.style.left = '-10000px';\n  container.style.top = '0';\n  container.style.width = '1px';\n  container.style.height = '1px';\n  container.style.overflow = 'hidden';\n  document.body.appendChild(container);\n\n  const videoUrl = location.href;\n  const videoTitle = getVideoTitle();\n  const postCommentCount = getPostCommentCount();\n  const crawlTime = new Date().toUTCString();\n\n  const topThreadsDirect = Array.from(document.querySelectorAll('ytd-comments ytd-item-section-renderer#sections > div#contents > ytd-comment-thread-renderer'));\n  const topThreadsFallback = Array.from(document.querySelectorAll('ytd-comment-thread-renderer')).filter(t => !t.closest('ytd-comment-replies-renderer'));\n  const topThreads = topThreadsDirect.length ? topThreadsDirect : topThreadsFallback;\n\n  const makeRow = (data) => {\n    const row = document.createElement('div');\n    row.setAttribute('data-uscraper-comment-row', '1');\n    for (const [key, value] of Object.entries(data)) {\n      row.setAttribute('data-' + key.replace(/[A-Z]/g, m => '-' + m.toLowerCase()), value == null ? '' : String(value));\n    }\n    container.appendChild(row);\n  };\n\n  const getCommentData = (root) => {\n    const commentRoot = root.querySelector('#comment') || root.querySelector('ytd-comment-view-model') || root;\n    const author = clean((commentRoot.querySelector('#author-text') || commentRoot.querySelector('a[href^=\"/@\"]'))?.textContent || '');\n    const content = clean(commentRoot.querySelector('#content-text')?.textContent || '');\n    const timeLink = commentRoot.querySelector('#published-time-text a') || commentRoot.querySelector('a[href*=\"lc=\"]');\n    const time = clean(timeLink?.textContent || '');\n    const likes = clean(commentRoot.querySelector('#vote-count-middle')?.textContent || '') || '0';\n    const url = abs(timeLink?.getAttribute('href') || '');\n    return { author, content, time, likes, url };\n  };\n\n  let created = 0;\n  const seenRows = new Set();\n\n  for (const thread of topThreads) {\n    const parent = getCommentData(thread);\n    if (!parent.author && !parent.content) continue;\n\n    const replyRoot = thread.querySelector('ytd-comment-replies-renderer');\n    let replies = [];\n    if (replyRoot) {\n      const replyCandidates = Array.from(replyRoot.querySelectorAll('ytd-comment-renderer, ytd-comment-view-model'));\n      const seenReplyNodes = new Set();\n      replies = replyCandidates.filter(r => {\n        const keyNode = r.closest('ytd-comment-renderer') || r.closest('ytd-comment-view-model') || r;\n        if (seenReplyNodes.has(keyNode)) return false;\n        seenReplyNodes.add(keyNode);\n        return true;\n      }).map(getCommentData).filter(r => r.author || r.content);\n    }\n\n    const base = {\n      videoUrl,\n      videoTitle,\n      commentUser: parent.author,\n      content: parent.content,\n      commentTime: parent.time,\n      likeCount: parent.likes,\n      dislikeCount: 'N/A',\n      postCommentCount,\n      crawlTime,\n      commentUrl: parent.url\n    };\n\n    if (replies.length) {\n      for (const reply of replies) {\n        const rowData = {\n          ...base,\n          replyUser: reply.author,\n          replyContent: reply.content,\n          replyCommentTime: reply.time,\n          replyLikeCount: reply.likes,\n          replyDislikeCount: 'N/A',\n          replyCount: String(replies.length),\n          commentUrl: parent.url || reply.url\n        };\n        const sig = JSON.stringify(rowData);\n        if (!seenRows.has(sig)) {\n          seenRows.add(sig);\n          makeRow(rowData);\n          created++;\n        }\n      }\n    } else {\n      const rowData = {\n        ...base,\n        replyUser: '',\n        replyContent: '',\n        replyCommentTime: '',\n        replyLikeCount: '',\n        replyDislikeCount: 'N/A',\n        replyCount: ''\n      };\n      const sig = JSON.stringify(rowData);\n      if (!seenRows.has(sig)) {\n        seenRows.add(sig);\n        makeRow(rowData);\n        created++;\n      }\n    }\n  }\n\n  return {\n    synthetic_rows_created: created,\n    top_threads_found: topThreads.length,\n    post_comment_count: postCommentCount,\n    url: location.href\n  };\n})();",
        "waitForCompletion": true,
        "timeout": 150,
        "color": "bg-[#a56eff]"
      }
    },
    {
      "block_id": "sleep-1",
      "block_type": "process",
      "title": "Sleep",
      "description": "Wait for specified time",
      "position_x": 1920,
      "position_y": 240,
      "config": {
        "duration": 1,
        "color": "bg-[#a56eff]"
      }
    },
    {
      "block_id": "wait-for-element-2",
      "block_type": "process",
      "title": "Wait for Element",
      "description": "Wait until element appears",
      "position_x": 2280,
      "position_y": 240,
      "config": {
        "selector": "[data-uscraper-comment-row]",
        "timeout": 45,
        "visible": false,
        "color": "bg-[#a56eff]"
      }
    },
    {
      "block_id": "structured-export-1",
      "block_type": "process",
      "title": "Structured Export",
      "description": "Export data with custom columns",
      "position_x": 2640,
      "position_y": 240,
      "config": {
        "rowSelector": "[data-uscraper-comment-row]",
        "fileName": "youtube-comments-replies-scraper.csv",
        "saveLocation": "C:\\Users\\theskd\\Documents\\UScraper\\templates",
        "includeHeaders": true,
        "fileMode": "append",
        "color": "bg-[#42be65]",
        "columns": [
          {
            "name": "video_url",
            "selector": "",
            "attribute": "data-video-url"
          },
          {
            "name": "video_title",
            "selector": "",
            "attribute": "data-video-title"
          },
          {
            "name": "comment_user",
            "selector": "",
            "attribute": "data-comment-user"
          },
          {
            "name": "content",
            "selector": "",
            "attribute": "data-content"
          },
          {
            "name": "comment_time",
            "selector": "",
            "attribute": "data-comment-time"
          },
          {
            "name": "like_count",
            "selector": "",
            "attribute": "data-like-count"
          },
          {
            "name": "dislike_count",
            "selector": "",
            "attribute": "data-dislike-count"
          },
          {
            "name": "reply_user",
            "selector": "",
            "attribute": "data-reply-user"
          },
          {
            "name": "reply_content",
            "selector": "",
            "attribute": "data-reply-content"
          },
          {
            "name": "reply_comment_time",
            "selector": "",
            "attribute": "data-reply-comment-time"
          },
          {
            "name": "reply_like_count",
            "selector": "",
            "attribute": "data-reply-like-count"
          },
          {
            "name": "reply_dislike_count",
            "selector": "",
            "attribute": "data-reply-dislike-count"
          },
          {
            "name": "post_comment_count",
            "selector": "",
            "attribute": "data-post-comment-count"
          },
          {
            "name": "CrawlTime",
            "selector": "",
            "attribute": "data-crawl-time"
          },
          {
            "name": "reply_count",
            "selector": "",
            "attribute": "data-reply-count"
          },
          {
            "name": "comment_url",
            "selector": "",
            "attribute": "data-comment-url"
          }
        ]
      }
    },
    {
      "block_id": "loop-continue-1",
      "block_type": "process",
      "title": "Loop Continue",
      "description": "Continue multi-input loop",
      "position_x": 2640,
      "position_y": 560,
      "config": {
        "color": "bg-[#8d8d8d]"
      }
    },
    {
      "block_id": "end-1",
      "block_type": "output",
      "title": "End",
      "description": "Terminate execution flow",
      "position_x": 3000,
      "position_y": 560,
      "config": {
        "color": "bg-[#8d8d8d]"
      }
    }
  ],
  "connections": [
    {
      "from_block_id": "set-window-size-1",
      "from_connector_id": "right",
      "to_block_id": "navigate-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "navigate-1",
      "from_connector_id": "right",
      "to_block_id": "wait-for-page-load-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "wait-for-page-load-1",
      "from_connector_id": "right",
      "to_block_id": "wait-for-element-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "wait-for-element-1",
      "from_connector_id": "right",
      "to_block_id": "inject-javascript-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "inject-javascript-1",
      "from_connector_id": "right",
      "to_block_id": "sleep-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "sleep-1",
      "from_connector_id": "right",
      "to_block_id": "wait-for-element-2",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "wait-for-element-2",
      "from_connector_id": "right",
      "to_block_id": "structured-export-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "structured-export-1",
      "from_connector_id": "right",
      "to_block_id": "loop-continue-1",
      "to_connector_id": "left"
    },
    {
      "from_block_id": "loop-continue-1",
      "from_connector_id": "right",
      "to_block_id": "end-1",
      "to_connector_id": "left"
    }
  ],
  "canvas_elements": [
    {
      "id": "group-entry",
      "element_type": "group",
      "title": "Entry & Setup",
      "color": "#4589ff",
      "position_x": 48,
      "position_y": 136,
      "width": 380,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "set-window-size-1"
        ]
      }
    },
    {
      "id": "group-load",
      "element_type": "group",
      "title": "Page Load",
      "color": "#08bdba",
      "position_x": 408,
      "position_y": 136,
      "width": 2120,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "navigate-1",
          "wait-for-page-load-1",
          "wait-for-element-1",
          "sleep-1",
          "wait-for-element-2"
        ]
      }
    },
    {
      "id": "group-interaction",
      "element_type": "group",
      "title": "Interaction",
      "color": "#a56eff",
      "position_x": 1488,
      "position_y": 136,
      "width": 380,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "inject-javascript-1"
        ]
      }
    },
    {
      "id": "group-extract",
      "element_type": "group",
      "title": "Data Extraction",
      "color": "#42be65",
      "position_x": 2568,
      "position_y": 136,
      "width": 380,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "structured-export-1"
        ]
      }
    },
    {
      "id": "group-pagination",
      "element_type": "group",
      "title": "Pagination Loop",
      "color": "#ff832b",
      "position_x": 2568,
      "position_y": 456,
      "width": 380,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "loop-continue-1"
        ]
      }
    },
    {
      "id": "group-control",
      "element_type": "group",
      "title": "Control Flow",
      "color": "#8d8d8d",
      "position_x": 2928,
      "position_y": 456,
      "width": 380,
      "height": 296,
      "z_index": 20,
      "data": {
        "memberBlockIds": [
          "end-1"
        ]
      }
    },
    {
      "id": "note-overview",
      "element_type": "note",
      "title": "Overview",
      "content": "Best-effort scraper for public YouTube video comment threads. It loops through supplied YouTube video URLs, scrolls to lazy-load comments, expands visible reply/read-more controls, builds clean synthetic export rows in the browser, and exports usernames, comment text, publish time, likes, reply-thread fields, total comment count, crawl time, and comment URL. Uses navigate.urls[] plus loop-continue for multiple videos. YouTube may block automation with sign-in, bot checks, age restrictions, disabled comments, or private/unavailable videos.",
      "color": "#f1c21b",
      "position_x": 80,
      "position_y": 20,
      "width": 480,
      "height": 160,
      "z_index": 22,
      "data": {}
    },
    {
      "id": "note-block-navigate-1",
      "element_type": "note",
      "title": "Note: Navigate",
      "content": "Multi-URL loop over 3 pages. Pair with loop-continue at the end of each iteration.",
      "color": "#ee5396",
      "position_x": 680,
      "position_y": 220,
      "width": 328,
      "height": 107,
      "z_index": 22,
      "data": {
        "block_id": "navigate-1"
      }
    },
    {
      "id": "note-block-inject-javascript-1",
      "element_type": "note",
      "title": "Note: Inject JavaScript",
      "content": "Runs custom JavaScript in the page: `return (async () => {\n  const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));\n  con...` Verify in browser if results are empty.",
      "color": "#ee5396",
      "position_x": 1760,
      "position_y": 220,
      "width": 340,
      "height": 140,
      "z_index": 22,
      "data": {
        "block_id": "inject-javascript-1"
      }
    },
    {
      "id": "note-block-structured-export-1",
      "element_type": "note",
      "title": "Note: Structured Export",
      "content": "Extracts rows matching `[data-uscraper-comment-row]`. Confirm row count > 0 before running at scale.",
      "color": "#ee5396",
      "position_x": 2840,
      "position_y": 220,
      "width": 340,
      "height": 113,
      "z_index": 22,
      "data": {
        "block_id": "structured-export-1"
      }
    },
    {
      "id": "note-block-loop-continue-1",
      "element_type": "note",
      "title": "Note: Loop Continue",
      "content": "Loop Continue advances a multi-URL or multi-text loop. Place at the end of the loop body with a clear back-edge to the loop start.",
      "color": "#ee5396",
      "position_x": 2840,
      "position_y": 540,
      "width": 340,
      "height": 123,
      "z_index": 22,
      "data": {
        "block_id": "loop-continue-1"
      }
    }
  ]
}