public FormMediaSplit() { InitializeComponent(); txtSplitpoints.Text = "0:40" + Utils.NL + "1:30"; _runner = new RunToolHelper(txtStatus, lblShortStatus, FormAudioFromVideo.GetFfmpegStdoutFilter()); }
private static void GetPlaylistImplFromJson(RunToolHelper runner, string url, string json, string txtPath) { // we could also use JsonReaderWriterFactory instead runner.Trace("process returned successfully. parsing json..."); var parts = new List <string>(Utils.SplitByString(json, "\"id\": \"")); parts.RemoveAt(0); var linesOut = new List <string>(); foreach (var part in parts) { var proposedId = Utils.SplitByString(part, "\"")[0]; if (proposedId.Length >= 10 && proposedId.Length <= 12 && !proposedId.Contains(" ")) { linesOut.Add("https://www.youtube.com/watch?v=" + proposedId); runner.Trace("Found " + "https://www.youtube.com/watch?v=" + proposedId); } } if (linesOut.Count == 0) { throw new CsDownloadVidException("did not find any videos in this playlist."); } runner.Trace("Successfully found " + linesOut.Count + " ids."); File.WriteAllLines(txtPath, linesOut); }
private void btnCancel_Click(object sender, EventArgs e) { RunToolHelper.RunAndCatch(() => { _runner.CancelProcess(); }); }
private void btnGetPlaylist_Click(object sender, EventArgs e) { var url = txtUrl.Text; if (string.IsNullOrWhiteSpace(url)) { MessageBox.Show("no url entered. please enter one of the url with a " + "playlist in the box for 'step 1'."); return; } else if (!Utils.AskToConfirm("Get playlist for " + url + "?")) { return; } var txtPath = Utils.AskSaveFileDialog("Save playlist video ids to what text file?", new string[] { ".txt" }, new string[] { "Text file" }); if (string.IsNullOrEmpty(txtPath)) { return; } RunToolHelper.RunAndCatch(() => { _runner.RunInThread(() => { GetPlaylistStart(url, txtPath); }, "Getting playlist..."); }); }
private void btnSplit_Click(object sender, EventArgs e) { RunToolHelper.RunAndCatch(() => { var input = txtInput.Text; var times = GetSplitTimes(txtSplitpoints.Text); if (times.Count == 0) { throw new CsDownloadVidException("No split points added."); } else if (!File.Exists(input)) { throw new CsDownloadVidException("Input file not found"); } if (!(input.EndsWith(".m4a") || input.EndsWith(".m4v"))) { if (!Utils.AskToConfirm("Warning: designed for .m4a or .m4v files, " + "this might not work. Continue?")) { return; } } if (checkBoxFadeout.Checked) { SplitWithFadeout(input, times, txtFadeLength.Text); } else { SplitMedia(input, times); } }); }
private void btnImportAudacity_Click(object sender, EventArgs e) { var file = Utils.AskOpenFileDialog("Choose Audacity text file " + "(File->Export labels as text)", new string[] { "*.txt" }); if (file != null) { var lines = File.ReadAllLines(file); RunToolHelper.RunAndCatch(() => ImportAudacity(lines)); } }
private void btnGetUpdates_Click(object sender, EventArgs e) { RunToolHelper.RunAndCatch(() => { _runner.RunInThread(() => { GetUpdatesImpl(); }, "Getting new youtube-dl..."); }); }
private static void GetPlaylistImpl(string url, string txtpath, RunToolHelper runner) { bool isPytube = false; // use only ytdl, not pytube var args = new List <string>(); args.Add("--ignore-config"); // don't look for global config file args.Add("--no-mark-watched"); args.Add("--no-call-home"); args.Add("-j"); // send output in json format args.Add("--flat-playlist"); args.Add("-i"); // continue after errs args.Add(url); var info = new ProcessStartInfo(); info.FileName = CsDownloadVidFilepaths.GetYtdlPath(isPytube); info.Arguments = Utils.CombineProcessArguments(args.ToArray()); info.CreateNoWindow = true; info.RedirectStandardError = true; info.RedirectStandardOutput = true; info.UseShellExecute = false; if (CsDownloadVidFilepaths.GetYtdlPath(isPytube).EndsWith(".py")) { info.FileName = CsDownloadVidFilepaths.GetPython(); info.Arguments = "\"" + CsDownloadVidFilepaths.GetYtdlPath(isPytube) + "\" " + Utils.CombineProcessArguments(args.ToArray()); } var stdoutGot = ""; Process p = new Process(); p.StartInfo = info; p.Start(); p.OutputDataReceived += (o, eparam) => { stdoutGot += eparam.Data; }; p.BeginOutputReadLine(); p.WaitForExit(); if (p.ExitCode != 0) { throw new CsDownloadVidException("error - non-zero exit code of " + p.ExitCode); } stdoutGot = stdoutGot.Trim(); if (!stdoutGot.StartsWith("{")) { throw new CsDownloadVidException("error - did not get valid json back " + stdoutGot); } GetPlaylistImplFromJson(runner, url, stdoutGot, txtpath); }
private void btnShowSum_Click(object sender, EventArgs e) { RunToolHelper.RunAndCatch(() => { var splitPoints = GetSplitTimes(txtSplitpoints.Text); double total = splitPoints.Sum(); double subseconds = total - (int)total; int seconds = ((int)total) % 60; int minutes = ((int)total) / 60; MessageBox.Show("Sum of all times is " + minutes + ":" + seconds + subseconds.ToString("#.0000")); }); }
private void btnDownloadFromWeb_Click(object sender, EventArgs e) { MessageBox.Show("Go to the Chrome Inspector, go to the Network tab, " + "and refresh the page. Look for a .mp4, .m3u, or .m3u8 url."); var url = InputBoxForm.GetStrInput("Enter the url that was seen,"); if (!String.IsNullOrEmpty(url)) { RunToolHelper.RunAndCatch(() => { downloadFromWeb(url); }); } }
private void doCustomEncode(string example, InputBoxHistory key) { var files = this.GetInputFiles(1); var cmd = InputBoxForm.GetStrInput("Command for the ffmpeg encoder:", example, key); if (String.IsNullOrEmpty(cmd)) { return; } else if (!cmd.Contains("%in%") && !Utils.AskToConfirm("Did not see '%in%', " + "won't process input files. Continue?")) { return; } if (!Utils.AskToConfirm("Run the command right now? (or copy the command line to the clipboard)")) { var s = ""; foreach (var file in files) { s += "\r\n\"" + CsDownloadVidFilepaths.GetFfmpeg() + "\" "; s += cmd.Replace("%in%", files[0]); } Clipboard.SetText(s); MessageBox.Show("Command was copied to the clipboard."); return; } RunToolHelper.RunAndCatch(() => { var infos = new List <ProcessStartInfo>(); foreach (var file in files) { var info = new ProcessStartInfo(); info.FileName = CsDownloadVidFilepaths.GetFfmpeg(); info.Arguments = cmd.Replace("%in%", file); info.CreateNoWindow = true; info.RedirectStandardError = true; info.RedirectStandardOutput = true; info.UseShellExecute = false; infos.Add(info); } _runner.RunProcesses(infos.ToArray(), "Custom encode"); }); }
public FormMediaJoin(bool showCustom = false) { InitializeComponent(); txtInput.Text = ""; txtInput.Enabled = false; txtInput.BackColor = SystemColors.Control; _runner = new RunToolHelper(this.txtStatus, this.lblShortStatus, FormAudioFromVideo.GetFfmpegStdoutFilter()); if (showCustom) { this.Text = "Encode audio or video..."; this.label2.Text = "Choose some input files..."; this.label1.Visible = false; this.tbOutputFormat.Visible = false; } this.btnJoin.Visible = !showCustom; this.btnMakeAudioLouder.Visible = showCustom; this.btnMakeAudioLouder.Visible = showCustom; }
public FormGetVideo() { InitializeComponent(); panelAdvanced.Visible = chkShowAdvanced.Checked; lblEnterUrlsAdvanced.Visible = chkShowAdvanced.Checked; panelChooseQuality.Visible = false; panelChooseOutput.Visible = false; btnNextStepIsToChooseOutput.Enabled = false; lblShortStatus.Text = ""; txtStatus.Visible = false; AddGenericFormatsToListbox(); txtOutputDir.Text = CsDownloadVidFilepaths.GetDefaultDownloadsDir(); lblNamePattern.Text = "Filename pattern, see also" + Utils.NL + "%(upload_date)s"; _runner = new RunToolHelper(this.txtStatus, this.lblShortStatus, (line) => (!line.Contains("[download]"))); // pre-emptively ensure that we have paths var ensurePath = CsDownloadVidFilepaths.GetPython(); }
private void txtInput_Click(object sender, EventArgs e) { RunToolHelper.RunAndCatch(() => btnGetInput_Click(sender, e)); }
private void btnNextToChooseQuality_Click(object sender, EventArgs e) { RunToolHelper.RunAndCatch(() => NextStepIsToChooseQuality()); }
private void getVideo_Click(object sender, EventArgs e) { var suggestedFormat = tbOutputFormat.Text; RunToolHelper.RunAndCatch(() => GoExtract(false, suggestedFormat)); }
public void Go(RunToolHelper run) { var prefix = this.GetPrefix(); Directory.CreateDirectory("./tools"); var pathCurrentZip = "./tools/%.zip".Replace("%", prefix); var pathCurrentDir = "./tools/%dir".Replace("%", prefix); var pathOldZip = "./tools/%-old.zip".Replace("%", prefix); var pathOldDir = "./tools/%dir-old".Replace("%", prefix); var pathIncomingZip = "./tools/%-incoming.zip".Replace("%", prefix); var pathIncomingDir = "./tools/%dir-incoming".Replace("%", prefix); // check before calling Delete(), since we want this to work even if // dir is currently empty run.Trace("Deleting temporary files"); if (File.Exists(pathIncomingZip)) { File.Delete(pathIncomingZip); } if (Directory.Exists(pathIncomingDir)) { Directory.Delete(pathIncomingDir, true); } var url = this.GetUrl(); run.Trace("Downloading from " + url); DownloadFile(url, pathIncomingZip); if (!File.Exists(pathIncomingZip)) { throw new CsDownloadVidException("No file was downloaded. " + url); } if (new FileInfo(pathIncomingZip).Length < 500 * 1024) { throw new CsDownloadVidException("File downloaded was too small, " + "expect > 500k. " + pathIncomingZip); } var currentHash = Utils.GetSha512(pathCurrentZip); var incomingHash = Utils.GetSha512(pathIncomingZip); if (currentHash == incomingHash) { run.Trace("We seem to have the latest version -- already up to date!"); return; } run.Trace("Extracting from zip file..."); ZipFile.ExtractToDirectory(pathIncomingZip, pathIncomingDir); run.Trace("Removing unneeded files..."); var dir = pathIncomingDir + "/youtube-dl-master/youtube_dl/extractor"; this.DoPostProcessing(dir, pathIncomingDir); run.Trace("Found a newer version!"); run.Trace("Moving from current to old"); if (File.Exists(pathOldZip)) { File.Delete(pathOldZip); } if (Directory.Exists(pathOldDir)) { Directory.Delete(pathOldDir, true); } if (File.Exists(pathCurrentZip)) { File.Move(pathCurrentZip, pathOldZip); } if (Directory.Exists(pathCurrentDir)) { Directory.Move(pathCurrentDir, pathOldDir); } run.Trace("Moving incoming to current"); File.Move(pathIncomingZip, pathCurrentZip); Directory.Move(pathIncomingDir, pathCurrentDir); }
public FormAudioFromVideo() { InitializeComponent(); _runner = new RunToolHelper(this.txtStatus, this.lblShortStatus, GetFfmpegStdoutFilter()); }