T
T
Timur Tuz2017-02-04 10:03:50
YouTube
Timur Tuz, 2017-02-04 10:03:50

How to intercept subtitles for youtube video from js?

Actually the task is completely the following: I need to display the titles for the video outside the video.
To do this, you need to somehow intercept the subtitle change event and get the current ones.
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dorothy, 2017-02-04
@Dorothy

In general, for good, all subtitles can be obtained at this link
This can be done for any video that has subtitles. vYou need to substitute the video identifier from the URL in the parameter , for example, for https://www.youtube.com/watch?v=7Y7LGxinPH0 , you need to substitute in the link to get subtitles 7Y7LGxinPH0, and then process the subtitles in time relative to the received XML.
But you can just listen to them. Connect jQuery to the video page:

var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);

Let's wait until the library is loaded, and you can register an event to receive subtitles:
jQuery.noConflict();

jQuery('body').on('DOMNodeInserted', 'span.captions-text span', function () {
      console.log(jQuery(this).text());
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question