<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d8211560\x26blogName\x3dTech+Tips,+Tricks+%26+Trivia\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttps://mvark.blogspot.com/search\x26blogLocale\x3den\x26v\x3d2\x26homepageUrl\x3dhttp://mvark.blogspot.com/\x26vt\x3d601588505461698440', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Tech Tips, Tricks & Trivia

by 'Anil' Radhakrishna
An architect's notes, experiments, discoveries and annotated bookmarks.

HOW TO extract subtitles from YouTube videos as plain text

Most questions in the Google Webmaster Central YouTube video channel are answered by Matt Cutts. The questions are very interesting but the answers are available only in video format. You have to watch the video which is of around 2 minutes to know the answer. While the background that Matt Cutts provides is educative, even 2 minutes is a lot of time if you need a quick answer and when you are on a low bandwidth internet connection. So I started compiling short answers to build summaries of Google Webmaster Central YouTube videos.

I noticed that these videos have captions and I realized that I don't even have to watch the video to know the question and answer. It is possible to extract subtitles from YouTube videos by specifying the language and VideoId in this generic URL - http://video.google.com/timedtext?lang={LANG}&v={VIDEOID}.

For instance, instead of watching a Google Webmaster Central YouTube video that has a URL like this -

I can take the video ID - 6dlr-1Qk8Uc and use it in this URL -

...to get a .xml file containing the English subtitles for that video.

Update: The original URL pattern (struck through) appears to have changed. The subtitles can be fetched only if captions are manually transcribed i.e. not automatically generated (as shown in image below)

Reading text in a XML file is for machines. To view just the text in a XML (or HTML file), I paste the XML content in EditPlus (my favorite text editor) and use the Ctrl + Shift + P keyboard shortcut to convert. With other editors (I tried this in Notepad++ & Visual Studio) that support regular expressions, you can paste the XML content into it and use the expression <(.|\n)*?> with the Find and Replace option to get just plain text.

You can also use Excel to convert HTML content to text.


Tweet this | Share via Whatsapp | Share on FB

« Home | Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »


Post a Comment