public YouTubeFileInfo(string filename, string title, MediaCategory categories, string description, bool? isVideoPublic) { this.Filename = filename; this.Title = title; this.MediaCategories = categories; this.Description = description; this.boolVideoPublic = (!isVideoPublic.HasValue) || isVideoPublic.Value; }
protected void SubmitVideo_ServerClick(object sender, EventArgs e) { if (String.IsNullOrEmpty(this.Title.Text) == false && String.IsNullOrEmpty(this.Description.Text) == false && String.IsNullOrEmpty(this.Category.SelectedValue) == false && String.IsNullOrEmpty(this.Keyword.Text) == false) { GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory(ServiceNames.YouTube, "TesterApp"); YouTubeService service = new YouTubeService(authFactory.ApplicationName, "ytapi-FrankMantek-TestaccountforGD-sjgv537n-0", "AI39si4v3E6oIYiI60ndCNDqnPP5lCqO28DSvvDPnQt-Mqia5uPz2e4E-gMSBVwHXwyn_LF1tWox4LyM-0YQd2o4i_3GcXxa2Q" ); authFactory.Token = HttpContext.Current.Session["token"] as string; service.RequestFactory = authFactory; try { YouTubeEntry entry = new YouTubeEntry(); entry.Media = new Google.GData.YouTube.MediaGroup(); entry.Media.Description = new MediaDescription(this.Description.Text); entry.Media.Title = new MediaTitle(this.Title.Text); entry.Media.Keywords = new MediaKeywords(this.Keyword.Text); // entry.Media.Categories MediaCategory category = new MediaCategory(this.Category.SelectedValue); category.Attributes["scheme"] = YouTubeService.DefaultCategory; entry.Media.Categories.Add(category); FormUploadToken token = service.FormUpload(entry); HttpContext.Current.Session["form_upload_url"] = token.Url; HttpContext.Current.Session["form_upload_token"] = token.Token; string page = "http://" + Request.ServerVariables["SERVER_NAME"]; if (Request.ServerVariables["SERVER_PORT"] != "80") { page += ":" + Request.ServerVariables["SERVER_PORT"]; } page += Request.ServerVariables["URL"]; HttpContext.Current.Session["form_upload_redirect"] = page; Response.Redirect("UploadVideo.aspx"); } catch (GDataRequestException gdre) { HttpWebResponse response = (HttpWebResponse)gdre.Response; } } }
private void btnUpload_Click(object sender, RoutedEventArgs e) { //**Clean all this up later** var Uploader = new YouTubeFileUploader(); Uploader.AsyncOperationProgress += new EventHandler<AsyncOperationProgressEventArgs>(Upload_AsyncOperationProgress); Uploader.AsyncOperationCompleted += new EventHandler<AsyncOperationCompletedEventArgs>(Upload_AsyncOperationCompleted); var uploaderParams = new UploaderParameters(txtLogin.Text, passwordBox1.Password); //especially this string filename = String.Format("{0}\\{1}", txtDirectory.Text, textBox1.Text); string description = textBox4.Text; string title = textBox2.Text; var category = new MediaCategory( ((ContentControl)(comboBox1.SelectedItem)).Content.ToString(), YouTubeNameTable.CategorySchema); var isVideoPublic = checkBox1.IsChecked; var videoFile = new YouTubeFileInfo(filename, title, category, description, isVideoPublic); button1.IsEnabled = false; //Disable upload button during an upload listVideosView.IsEnabled = false; Uploader.UploadFiles(uploaderParams, videoFile); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs a test on the YouTube Feed object</summary> ////////////////////////////////////////////////////////////////////// [Test] public void YouTubeRequestInsertTest() { Tracing.TraceMsg("Entering YouTubeRequestInsertTest"); YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", this.ytClient, this.ytDevKey, this.ytUser, this.ytPwd); YouTubeRequest f = new YouTubeRequest(settings); Video v = new Video(); v.Title = "Sample upload"; v.Description = "This is a test with and & in it"; MediaCategory category = new MediaCategory("Nonprofit"); category.Attributes["scheme"] = YouTubeService.DefaultCategory; v.Tags.Add(category); v.Keywords = "math"; v.YouTubeEntry.MediaSource = new MediaFileSource(this.resourcePath + "test_movie.mov", "video/quicktime"); Video newVideo = f.Upload(this.ytUser, v); newVideo.Title = "This test upload will soon be deleted"; Video updatedVideo = f.Update(newVideo); Assert.AreEqual(updatedVideo.Description, newVideo.Description, "Description should be equal"); Assert.AreEqual(updatedVideo.Keywords, newVideo.Keywords, "Keywords should be equal"); newVideo.YouTubeEntry.MediaSource = new MediaFileSource(this.resourcePath + "test.mp4", "video/mp4"); Video last = f.Update(updatedVideo); f.Delete(last); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs a test on the YouTube Feed object</summary> ////////////////////////////////////////////////////////////////////// [Test] public void YouTubeRatingsTest() { Tracing.TraceMsg("Entering YouTubeRatingsTest"); YouTubeService service = new YouTubeService("NETUnittests", this.ytClient, this.ytDevKey); if (this.userName != null) { service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd); } YouTubeEntry entry = new YouTubeEntry(); entry.MediaSource = new MediaFileSource(this.resourcePath + "test_movie.mov", "video/quicktime"); entry.Media = new YouTube.MediaGroup(); entry.Media.Description = new MediaDescription("This is a test"); entry.Media.Title = new MediaTitle("Sample upload"); entry.Media.Keywords = new MediaKeywords("math"); // entry.Media.Categories MediaCategory category = new MediaCategory("Nonprofit"); category.Attributes["scheme"] = YouTubeService.DefaultCategory; entry.Media.Categories.Add(category); YouTubeEntry newEntry = service.Upload(this.ytUser, entry); Assert.AreEqual(newEntry.Media.Description.Value, entry.Media.Description.Value, "Description should be equal"); Assert.AreEqual(newEntry.Media.Keywords.Value, entry.Media.Keywords.Value, "Keywords should be equal"); Rating rating = new Rating(); rating.Value = 1; newEntry.Rating = rating; YouTubeEntry ratedEntry = newEntry.Update(); ratedEntry.Delete(); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs a test on the YouTube Feed object</summary> ////////////////////////////////////////////////////////////////////// [Test] public void YouTubeInsertTest() { Tracing.TraceMsg("Entering YouTubeFeedTest"); YouTubeService service = new YouTubeService("NETUnittests", this.ytClient, this.ytDevKey); if (this.userName != null) { service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd); } GDataRequestFactory factory = service.RequestFactory as GDataRequestFactory; factory.Timeout = 1000000; YouTubeEntry entry = new YouTubeEntry(); entry.MediaSource = new MediaFileSource(this.resourcePath + "test_movie.mov", "video/quicktime"); entry.Media = new YouTube.MediaGroup(); entry.Media.Description = new MediaDescription("This is a test with and & in it"); entry.Media.Title = new MediaTitle("Sample upload"); entry.Media.Keywords = new MediaKeywords("math"); // entry.Media.Categories MediaCategory category = new MediaCategory("Nonprofit"); category.Attributes["scheme"] = YouTubeService.DefaultCategory; entry.Media.Categories.Add(category); YouTubeEntry newEntry = service.Upload(this.ytUser, entry); Assert.AreEqual(newEntry.Media.Description.Value, entry.Media.Description.Value, "Description should be equal"); Assert.AreEqual(newEntry.Media.Keywords.Value, entry.Media.Keywords.Value, "Keywords should be equal"); // now change the entry newEntry.Title.Text = "This test upload will soon be deleted"; YouTubeEntry anotherEntry = newEntry.Update() as YouTubeEntry; // bugbug in YouTube server. Returns empty category that the service DOES not like on reuse. so remove ExtensionList a = ExtensionList.NotVersionAware(); foreach (MediaCategory m in anotherEntry.Media.Categories) { if (String.IsNullOrEmpty(m.Value)) { a.Add(m); } } foreach (MediaCategory m in a) { anotherEntry.Media.Categories.Remove(m); } Assert.AreEqual(newEntry.Media.Description.Value, anotherEntry.Media.Description.Value, "Description should be equal"); Assert.AreEqual(newEntry.Media.Keywords.Value, anotherEntry.Media.Keywords.Value, "Keywords should be equal"); // now update the video anotherEntry.MediaSource = new MediaFileSource(this.resourcePath + "test.mp4", "video/mp4"); anotherEntry.Update(); // now delete the guy again newEntry.Delete(); }
public void YouTubeAccessControlTest() { Tracing.TraceMsg("Entering YouTubeAccessControlTest"); YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", this.ytDevKey, this.ytUser, this.ytPwd); YouTubeRequest f = new YouTubeRequest(settings); Video v = new Video(); v.Title = "Sample upload"; v.Description = "This is a test with different access control values"; MediaCategory category = new MediaCategory("Nonprofit"); category.Attributes["scheme"] = YouTubeService.DefaultCategory; v.Tags.Add(category); v.Keywords = "math"; v.YouTubeEntry.MediaSource = new MediaFileSource(Path.Combine(this.resourcePath, "test_movie.mov"), "video/quicktime"); v.YouTubeEntry.AccessControls.Add(new YtAccessControl(YtAccessControl.RateAction, YtAccessControl.DeniedPermission)); v.YouTubeEntry.AccessControls.Add(new YtAccessControl(YtAccessControl.CommentAction, YtAccessControl.ModeratedPermission)); Video newVideo = f.Upload(this.ytUser, v); ExtensionCollection<YtAccessControl> acl = newVideo.YouTubeEntry.AccessControls; for (int i = 0; i < acl.Count; i++) { YtAccessControl ac = acl[i]; switch (ac.Action) { case YtAccessControl.RateAction: Assert.AreEqual(ac.Permission, YtAccessControl.DeniedPermission, "Rating should be denied"); break; case YtAccessControl.CommentAction: Assert.AreEqual(ac.Permission, YtAccessControl.ModeratedPermission, "Comments should be moderated"); break; case YtAccessControl.CommentVoteAction: Assert.AreEqual(ac.Permission, YtAccessControl.AllowedPermission, "Comment rating should be allowed"); break; case YtAccessControl.VideoRespondAction: Assert.AreEqual(ac.Permission, YtAccessControl.ModeratedPermission, "Video responses should be moderated"); break; case YtAccessControl.ListAction: Assert.AreEqual(ac.Permission, YtAccessControl.AllowedPermission, "Video listing should be allowed"); break; case YtAccessControl.EmbedAction: Assert.AreEqual(ac.Permission, YtAccessControl.AllowedPermission, "Video embed should be allowed"); break; case YtAccessControl.SyndicateAction: Assert.AreEqual(ac.Permission, YtAccessControl.AllowedPermission, "Video syndicate should be allowed"); break; } } f.Delete(newVideo); }