0

For the application I'm developing, I need to know the duration of certain YouTube-videos. I'm using the .NET libs for the YouTube API V3.

Requesting the durationMs properties of the FileDetails works for some video's, but returns 'null' for other videos (all fully processed). The video's are all unlisted and are supposed to stay the way, so I'd rather not disclose the ID of the video that's causing issues.

What could be the cause this issue? I'm not getting any errors from the API, and I do get the container (MOV), but properties like the duration are all null.

I have include the the relevant code snippet.

var videosListRequest = youtube.Videos.List("processingDetails,FileDetails");
videosListRequest.Id = file.FileName;

videosListRequest.OauthToken = Authresult.Result.Credential.Token.AccessToken;
VideoListResponse vlr = videosListRequest.Execute();

if (vlr.Items.Count > 0 && vlr.Items[0].ProcessingDetails.ProcessingStatus == "succeeded")
{
    file.IsVideoProcessed = true;
    int durationInS = (int)(vlr.Items[0].FileDetails.DurationMs / 1000.0);
    UpdateVideoStatus(file.Id, ClientId.Value, MediaStatus.READY, durationInS);
}
Sibert
  • 21
  • 3

1 Answers1

0

I think you should use part=contentDetails instead of fileDetails.

From this SO question, it is clearly stated that part=contentDetails contains the duration.

Here is the example request using part=contentDetails

https://www.googleapis.com/youtube/v3/videos?id=9bZkp7q19f0&part=contentDetails&key={YOUR_API_KEY}

For more information check this documentation and this related SO question.

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31
  • Following up on this (three years later!) it's worth noting that there is both `fileDetails.durationMs` and `contentDetails.duration` (although, for the videos I've worked with at least, fileDetails.durationMs is null). https://developers.google.com/youtube/v3/docs/videos#contentDetails.duration https://developers.google.com/youtube/v3/docs/videos#fileDetails.durationMs – Sam Dutton Oct 14 '19 at 10:40