Skip to content

Instantly share code, notes, and snippets.

@insin
Last active July 25, 2025 18:30
Show Gist options
  • Save insin/cb938324866c511066bcabe230b6a625 to your computer and use it in GitHub Desktop.
Save insin/cb938324866c511066bcabe230b6a625 to your computer and use it in GitHub Desktop.
Download YouTube Transcript - open the Transcript panel on a video then execute this function in the developer tools console
function downloadTranscript() {
let $segments = document.querySelector('.ytd-transcript-search-panel-renderer #segments-container')
let sections = []
let parts = []
for (let $el of $segments.children) {
if ($el.tagName == 'YTD-TRANSCRIPT-SECTION-HEADER-RENDERER') {
if (parts.length > 0) {
sections.push(parts.join(' '))
parts = []
}
sections.push(/** @type {HTMLElement} */ ($el).innerText.trim())
} else {
parts.push(/** @type {HTMLElement} */ ($el.querySelector('.segment-text')).innerText.trim())
}
}
if (parts.length > 0) {
sections.push(parts.join(' '))
}
let $link = document.createElement('a')
let url = URL.createObjectURL(new Blob([sections.join('\n\n')], {type: "text/plain"}))
let title = /** @type {HTMLElement} */ (document.querySelector('#above-the-fold #title'))?.innerText ?? 'transcript'
$link.setAttribute('href', url)
$link.setAttribute('download', `${title}.txt`)
$link.click()
URL.revokeObjectURL(url)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment