Culling captions from YouTube

Note: This script is basically no longer necessary since Youtube surfaces the captions. Under the video, to the right of the ‘save’ link is an ellipses (three periods). If you click on that, you get a submenu that reads ‘open transcript’. This is a much simpler way of getting transcripts than this script ;)

If you want to grab Youtube auto-generated captions, here is a better script:

var captionCollector = {
    captions : '',

    collect : function(){
      try {
        var currentCaption = document.getElementsByClassName("captions-text")[0].innerText.replace(/\n/,'');
        console.log(currentCaption);
      } catch (e) {

      }

    if(currentCaption) {
      if(captionCollector.captions.lastIndexOf(currentCaption) == -1) {
        captionCollector.captions += currentCaption;
      }
    }

      setTimeout(captionCollector.collect, 500);
    }
}

captionCollector.collect();

Then calle captionCollector.captions to print the captions to the console.

Published by

Estelle Weyl

My name is Estelle Weyl. I an open web evangelist and community engineer. I'm a consulting web developer, writing technical books with O'Reilly, running frontend workshops, and speaking about web development, performance, and other fun stuff all over the world. If you have any recommendations on topics for me to hit, please let me know via @estellevw.