Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Michael Lockrey
2,762 PointsAccessing and manipulating a YouTube video with Javascript
Fixing up YouTube's auto captioning
I'm putting together a website that enables users to put in a YouTube 11 character video ID and then enable users to review and fix up the auto-captions, which don't provide any accessibility benefits for Deaf and hard of hearing users (unless they are reviewed and fixed up first!)
How do I access the auto-captioning file for a YouTube video? Is it possible to do this via the DOM?
2 Answers
Iain Simmons
Treehouse Moderator 32,305 PointsIf you load the video on YouTube itself and turn the captions on then you can 'listen' to the events being fired from the .captions-text element.
e.g. you can run the following in your console (only tested in Chrome)
$('.captions-text').addEventListener("DOMNodeInserted", function(evt) {
if (evt.target.nodeType === 3) console.log(evt.target.data);
}, false);
Using embedded players will usually use an iframe or flash object, neither of which you will be able to access with JavaScript from the containing document...
This might be something that can be achieved with the JavaScript API, but I'm not sure the API allows access to the captions...
Michael Lockrey
2,762 PointsVery interesting feedback Iain!
But I'm now well and truly out of my depth......
Iain Simmons
Treehouse Moderator 32,305 PointsOtherwise, someone has sort of done something similar already in PHP: http://stackoverflow.com/a/15040888
Michael Lockrey
2,762 PointsHi Iian,
Here's our current proof of concept at theAcrowd
Would love your feedback and any suggestions you may have.
Cheers for now, Mike Lockrey
Michael Lockrey
2,762 PointsMichael Lockrey
2,762 PointsI can see the caption lines in the interactive transcript as per the attached screenshot but I can't see how to access or manipulate them using javascript:
Link to a screen shot of the YouTube interactive transcript object in the Chrome Javascript console