Reputation: 21
Once the video is uploaded, how to check its processing status using C# .NET's API? The answer should be in the Google.Apis.Youtube.v3.Data.VideoProcessingDetails, but how exactly should that object be instantiated? The following code throws a System.Net.Http.HttpRequestException:
video.ProcessingDetails = new VideoProcessingDetails();
The code above is being used in the following context:
UserCredential credential;
using (FileStream stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None,
new FileDataStore("YouTube.Auth.Store")).Result;
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = Title;
video.Snippet.Description = Description;
video.Snippet.Tags = Tags;
video.ProcessingDetails = new VideoProcessingDetails(); // Here it throws an exception
video.Snippet.CategoryId = CategotyId;
video.Status = new VideoStatus();
video.Status.PrivacyStatus = PrivacyStatus;
var filePath = FilePath;
The idea, is once the video is uploaded, check in a loop if the video is still processing and perform other operations on it once the processing is done.
UPDATE: I figured out that if the object is instantiated after the video is uploaded (i.e. in the private static void videosInsertRequest_ResponseReceived() method, for example), the exception is gone, but once I try accessing video.ProcessingDetails.ProcessingProgress.TimeLeftMs.Value, it says that that value is null.
Thanks.
Upvotes: 2
Views: 1612
Reputation: 516
In my own work, I have found that when ProcessingDetails.ProcessingStatus equals "terminated", all of the other properties in ProcessingDetails are equal to nothing (i.e. null). I believe that this means that YouTube has finished processing the video.
I usually check a Google API v3 property to see if it is null before attempting to use it.
Upvotes: 1