Last active
December 10, 2015 23:28
-
-
Save jlewin/4509284 to your computer and use it in GitHub Desktop.
Extract a quote from YouTube transcripts
This file contains 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
// Usage: Open the transcript view, select the line to start at, and call getQuoteFromVideo | |
// passing it just the number of lines to collect | |
// or | |
// Call getQuoteFromVideo passing it the number of lines to collect and an element id to start at | |
function getQuoteFromVideo(count, captionStartID){ | |
var captionLine = document.querySelector(captionStartID || '.caption-line-highlight'); | |
var text = ''; | |
for(var i = 0; i < count && captionLine; i++){ | |
text += captionLine.querySelector('.caption-line-text').textContent + ' '; | |
captionLine = captionLine.nextSibling; | |
} | |
// Trim newlines and return text | |
return text.replace(/\n/g, ' '); | |
} | |
// Start at a specific id | |
console.log(getQuoteFromVideo(20, '#cp-793')); | |
console.log('----'); | |
// or start at the currently selected line | |
console.log(getQuoteFromVideo(20)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Built so I could extract this gem from Linus Torvalds
http://www.youtube.com/watch?v=WVTWCPoUt8w&feature=youtu.be&t=37m30s