public OtherHelper() { InitializeComponent(); #region Init this.StartPosition = FormStartPosition.CenterParent; this.FormBorderStyle = FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; OpenFileDialog.CheckFileExists = true; OpenFileDialog.CheckPathExists = true; wrapper.Dock = DockStyle.Fill; wrapper.RowCount = 0; wrapper.ColumnCount = 0; wrapper.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 70F)); wrapper.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 30F)); label.Text = L18n.Get("OtherHelper", "Text_nofile"); label.Anchor = AnchorStyles.None; label.AutoSize = true; btnChoose.Text = L18n.Get("OtherHelper", "Text_choosefile"); btnChoose.Anchor = AnchorStyles.None; btnChoose.Click += Choose_Click; btnUpload.Text = L18n.Get("OtherHelper", "Text_upload"); btnUpload.Anchor = AnchorStyles.None; btnUpload.Enabled = false; txbLink.ReadOnly = true; txbLink.Anchor = AnchorStyles.None; //txbLink.AutoSize = true; txbLink.Size = new Size(200, 23); txbLink.Enabled = false; txbLink.Click += link_Click; group.Text = L18n.Get("OtherHelper", "Text_videoaccess"); group.Dock = DockStyle.Fill; rbPublic.Checked = true; rbPrivate.Text = L18n.Get("OtherHelper", "Text_private"); rbPublic.Text = L18n.Get("OtherHelper", "Text_public"); rbUnlisted.Text = L18n.Get("OtherHelper", "Text_unlisted"); rbPrivate.Location = new Point(215, 15); rbPublic.Location = new Point(5, 15); rbUnlisted.Location = new Point(110, 15); group.Controls.Add(rbPrivate); group.Controls.Add(rbPublic); group.Controls.Add(rbUnlisted); bar.Anchor = AnchorStyles.Left; bar.Size = new Size(208, 23); #endregion self = this; }
public static async Task Upload(OtherHelper form, string path, string privacy, CancellationToken token) { sender = form; file_name = Path.GetFileName(path); ClientSecrets secrets = new ClientSecrets(); secrets.ClientId = "769375267841-4401scf3hltnavuthdaipoduootau2hk.apps.googleusercontent.com"; secrets.ClientSecret = "7pgdfz5NLEVmNregj7gkgz4W"; UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( secrets, new[] { YouTubeService.Scope.YoutubeUpload }, "user", CancellationToken.None); var youtubeService = new YouTubeService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = Assembly.GetExecutingAssembly().GetName().Name }); FileInfo file = new FileInfo(path); file_length = file.Length; var video = new Video(); video.Snippet = new VideoSnippet(); video.Snippet.Title = file.Name; video.Status = new VideoStatus(); video.Status.PrivacyStatus = privacy; using (var fileStream = new FileStream(file.FullName, FileMode.Open)) { var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*"); long maxchunk = (long)Math.Round((float)file_length / 100); int minchunk = ResumableUpload <Video> .MinimumChunkSize; if (minchunk >= maxchunk) { videosInsertRequest.ChunkSize = minchunk; } else { videosInsertRequest.ChunkSize = minchunk * (int)Math.Floor((float)maxchunk / minchunk); } videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged; videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived; //token.ThrowIfCancellationRequested(); await videosInsertRequest.UploadAsync(token); } }
private void btnUploadVideo_Click(object sender, EventArgs e) { if (OtherHelper.self == null) { this.Hide(); OtherHelper window = new OtherHelper(); window.CreateForm(OtherHelper.OtherType.UploadVideo); window.ShowDialog(); this.Show(); } else { if (OtherHelper.self.WindowState == FormWindowState.Minimized) { OtherHelper.self.WindowState = FormWindowState.Normal; } else { OtherHelper.self.Show(); } } }
private void OtherHelper_FormClosing(object sender, FormClosingEventArgs e) { self = null; }