Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

YouTube captions download incorrect format

$
0
0

I using YouTube Data API to download captions and it seems to work but when I download the subtitles from api the content is not in the correct format.

100:00:00,719 --> 00:00:06,000{LONG TEXT CONTAINS ALL SCRIPT}200:00:03,240 --> 00:00:09,120300:00:06,000 --> 00:00:11,219[REST OF THE TIME WITH EMPTY LINES]

However, it looks correct when I download using studio.youtube.com.

Is there a fix for that?

PS: Google says I must use stackoverflow with tags but so far I cannot get any answers or comments. Is it now correct approach?

EDIT:

Based on the API document I am using below code and it downloads the subtitle but not with correctly formated data.

YouTubeService youtubeService = await GetYouTubeService();// Get the list of available captions for the videovar captionListRequest = youtubeService.Captions.List("snippet, id", book.BSYouTubeId);var captionListResponse = await captionListRequest.ExecuteAsync();// Get the first caption trackvar captionTrack = captionListResponse.Items.FirstOrDefault();if (captionTrack == null){    context.WriteLine("No caption track found.");    return;}// Download the caption trackvar captionDownloadRequest = youtubeService.Captions.Download(captionTrack.Id);captionDownloadRequest.Tfmt = "srt";captionDownloadRequest.Tlang = book.GetShortLanguageCode();var captionStream = await captionDownloadRequest.ExecuteAsStreamAsync();// Read the caption track into a stringvar captionString = new StreamReader(captionStream).ReadToEnd();

Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>