Last active
July 25, 2025 18:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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