Question

I am using Async ResumableUpload to upload videos to YouTube however I have not been able to retrieve the VideoID for the successfully uploaded video. This was very easy for the single Sync uploads but I have been unable to find any examples for the Async.

Here's the code:

        var mResumableUploader = new ResumableUploader(chunkSize);
        mResumableUploader.AsyncOperationCompleted += MResumableUploaderAsyncOperationCompleted;
        mResumableUploader.AsyncOperationProgress += MResumableUploaderAsyncOperationProgress;

        var youTubeAuthenticator = new ClientLoginAuthenticator(appName, ServiceNames.YouTube, uName, passWord);
        youTubeAuthenticator.DeveloperKey = devKey;

        newVideo = new Video();

        newVideo.Title = "video";
        newVideo.Tags.Add(new MediaCategory("Entertainment", YouTubeNameTable.CategorySchema));
        newVideo.Keywords = "video";
        newVideo.Description = "video";
        newVideo.YouTubeEntry.Private = false;
        newVideo.YouTubeEntry.MediaSource = new MediaFileSource(fileName, fileContType);

        var link = new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads");
        link.Rel = ResumableUploader.CreateMediaRelation;
        newVideo.YouTubeEntry.Links.Add(link);

        Console.WriteLine("Starting upload: ");
        mResumableUploader.InsertAsync(youTubeAuthenticator, newVideo.YouTubeEntry, "inserter");

Any help will be much appreciated.

Thanks.

Was it helpful?

Solution

As shown on google data provided samples you can parse the video after the upload process is completed. Regards

        ru.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(ru_AsyncOperationCompleted);

void ru_AsyncOperationCompleted(object sender, AsyncOperationCompletedEventArgs e)
        {

            //upload complete
            YouTubeRequestSettings ytSettings = new YouTubeRequestSettings("myApp", googleDevKey, ytUsername, ytPassword);
            Video v = ytRequest.ParseVideo(e.ResponseStream);
            string videoId = v.VideoId;
            string watchPage = v.WatchPage.ToString();

        }

OTHER TIPS

With YouTube API v3 you don't need to use ResumableUploader. You just need to add a delegate to the VideoInsertRequest ResponseReceived:

var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = "Default Video Title";
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"
var filePath = @"REPLACE_ME.mp4"; // Replace with path to actual movie file.

using (var fileStream = new FileStream(filePath, FileMode.Open))
{
  var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
  videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
  await videosInsertRequest.UploadAsync();
}

void videosInsertRequest_ResponseReceived(Video video)
{
  Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id);
}

The complete code is here: https://developers.google.com/youtube/v3/code_samples/dotnet#upload_a_video

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top