Home > Software engineering >  How can I get captions of a youtube video and display it separately?
How can I get captions of a youtube video and display it separately?

Time:09-27

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?

enter image description here

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.

enter image description here

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.

CodePudding user response:

You can use the Youtube API for this:

  1. First retrieve the list of captions using https://developers.google.com/youtube/v3/docs/captions/list
  2. Download the caption from https://developers.google.com/youtube/v3/docs/captions/download

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.

CodePudding user response:

You should check the youtube api to get captions :https://developers.google.com/youtube/v3/docs/captions/list?apix_params={"part":"snippet","videoId":"PRU2ShMzQRg"}

From there you can have separately captions and video

  • Related