Skip to content

Instantly share code, notes, and snippets.

@davestewart
Last active May 23, 2023 15:38
Show Gist options
  • Save davestewart/e0c5f919cb97532d6ddbafcb0443fb9e to your computer and use it in GitHub Desktop.
Save davestewart/e0c5f919cb97532d6ddbafcb0443fb9e to your computer and use it in GitHub Desktop.
YouTube transcript bookmarklet

YouTube Transcript Bookmarklet

For any YouTube video with captions, you can access the captions via a linked URL.

This bookmarklet grabs that URL, loads the captions, and converts the XML to text.

That text is then:

  • copied to the clipboard (if supported)
  • dumped in the console (Opt+Cmd+I / F12) where you can click the copy button to grab it
javascript:fetch(ytInitialPlayerResponse.captions.playerCaptionsTracklistRenderer.captionTracks[0].baseUrl).then(res => res.status === 200 ? res.text() : Promise.reject(new Error('Transcript not available'))).then(text => { var d = document.createElement('div'); d.innerHTML = text; text = Array.from(d.querySelectorAll('text')).map(t => t.innerText).join('\n\n').replace(/&#(\d+);/g, m => String.fromCharCode(m.replace(/\D/g, ''))); console.log(text); navigator.clipboard.writeText(text); }).catch(err => alert(err.message))
@mlg4035
Copy link

mlg4035 commented May 20, 2023

I found that I have to clear cache when using it with multiple YouTube videos in one session, but otherwise it works great, thank you!

@davestewart
Copy link
Author

Ok, thanks for the info!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment