Reputation: 1117
I am making a bilingual app to learn English. I will insert a youtube video into the app, and show subtitles below. Is there any way I can get the captions directly from the youtube video player and display it separately?
I see some current apps that are doing that as well. Don't know how they did? Or do I have to manually get the subtitles from each video then save them to the database, then process and display them? But the amount of data will be huge, with tens of millions of videos, and each video has dozens of subtitles in different languages.
I searched a lot but didn't find anyone answering this. There are posts from many years ago that also have no answers. Does anyone have any ideas? Thank you.
Upvotes: 6
Views: 9760
Reputation: 441
After a lot of searching I finally found the solution.
You have to GET the whole page first from the video url (e.g. https://www.youtube.com/watch?v=someID
) and then from inside the whole resposne, search for a url like this: https://www.youtube.com/api/timedtext?...
It contains the temporary signature and everything else you need to download the transcript. (DISCLAIMER: haven't tested if the signature expires --> EDIT: it expires in approx. 24h)
After that you just need to extract that whole url - I used Regex - and decode it using decodeURI() method to escape all Unicode characters :)
It should return something like:
Upvotes: 8
Reputation: 247
You should check the youtube api to get captions :https://developers.google.com/youtube/v3/docs/captions/list?apix_params=%7B%22part%22%3A%22snippet%22%2C%22videoId%22%3A%22PRU2ShMzQRg%22%7D
From there you can have separately captions and video
Upvotes: 0
Reputation: 2493
You can use the Youtube API for this:
Then you can have access to controls for a media player (and the current time) to display the correct subtitle: see HTMLMediaElement API for this.
Upvotes: 0