예제 #1
0
        private void buttonImport_Click(object sender, EventArgs e)
        {
            using (var openFileDialog = new OpenFileDialog {
                Filter = "se-job files|*.se-job"
            })
            {
                if (openFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var seJob = SeJobHandler.LoadSeJob(FileUtil.ReadAllBytesShared(openFileDialog.FileName));
                if (seJob == null)
                {
                    return;
                }

                textBoxJobId.Text                  = seJob.JobId;
                textBoxJobName.Text                = seJob.JobName;
                textBoxJobDescription.Text         = seJob.Message;
                textBoxSubtitleFileName.Text       = seJob.SubtitleFileName;
                textBoxVideoUrl.Text               = seJob.VideoStreamingUrl;
                checkBoxIncludeWaveform.Checked    = seJob.Waveform?.PeakMins.Count > 0;
                checkBoxIncludeShotChanges.Checked = seJob.ShotChanges?.Count > 0;
                _waveform    = seJob.Waveform;
                _shotChanges = seJob.ShotChanges;
                checkBoxIncludeRules.Checked = seJob.Rules != null;
                if (seJob.Rules != null)
                {
                    numericUpDownMaxNumberOfLines.Value          = seJob.Rules.MaxNumberOfLines;
                    numericUpDownSubtitleLineMaximumLength.Value = seJob.Rules.SubtitleLineMaximumLength;
                    numericUpDownMaxCharsSec.Value     = seJob.Rules.SubtitleMaximumCharactersPerSeconds;
                    numericUpDownDurationMin.Value     = seJob.Rules.SubtitleMinimumDisplayMilliseconds;
                    numericUpDownDurationMax.Value     = seJob.Rules.SubtitleMaximumDisplayMilliseconds;
                    numericUpDownMinGapMs.Value        = seJob.Rules.MinimumMillisecondsBetweenLines;
                    numericUpDownMaxWordsMin.Value     = seJob.Rules.SubtitleMaximumWordsPerMinute;
                    numericUpDownOptimalCharsSec.Value = seJob.Rules.SubtitleOptimalCharactersPerSeconds;
                }

                _subtitle = new Subtitle();
                if (!string.IsNullOrEmpty(seJob.SubtitleFileFormat) && !string.IsNullOrEmpty(seJob.SubtitleContent))
                {
                    var format = SubtitleFormat.AllSubtitleFormats.FirstOrDefault(p => p.Name == seJob.SubtitleFileFormat);
                    format?.LoadSubtitle(_subtitle, seJob.SubtitleContent.SplitToLines(), string.Empty);
                }

                if (!string.IsNullOrEmpty(seJob.SubtitleFileFormat) && !string.IsNullOrEmpty(seJob.SubtitleContentOriginal))
                {
                    _subtitleOriginal = new Subtitle();
                    var format = SubtitleFormat.AllSubtitleFormats.FirstOrDefault(p => p.Name == seJob.SubtitleFileFormat);
                    format?.LoadSubtitle(_subtitleOriginal, seJob.SubtitleContentOriginal.SplitToLines(), string.Empty);
                }

                UpdateUiAfterLoad();
            }
        }
예제 #2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            var model = new SeJobModel
            {
                Version            = "1.0",
                JobId              = textBoxJobId.Text,
                JobName            = textBoxJobName.Text.Trim(),
                Message            = textBoxJobDescription.Text.Trim(),
                SubtitleFileFormat = _subtitleFormat.Name,
                SubtitleFileName   = textBoxSubtitleFileName.Text.Trim(),
                SubtitleContent    = _subtitle.ToText(_subtitleFormat),
                VideoStreamingUrl  = textBoxVideoUrl.Text.Trim(),
            };

            if (!string.IsNullOrEmpty(_videoFileName))
            {
                model.VideoHash = Path.GetFileNameWithoutExtension(WavePeakGenerator.GetPeakWaveFileName(_videoFileName));
                if (!string.IsNullOrEmpty(model.VideoStreamingUrl))
                {
                    model.VideoHash = MovieHasher.GenerateHashFromString(model.VideoStreamingUrl);
                }
            }

            if (checkBoxOriginal.Checked && _subtitleOriginal?.Paragraphs.Count > 0)
            {
                model.SubtitleFileNameOriginal = _subtitleOriginal.FileName;
                model.SubtitleContentOriginal  = _subtitleOriginal.ToText(_subtitleFormat);
            }

            if (checkBoxIncludeWaveform.Checked && _waveform?.PeakMins.Count > 0)
            {
                model.Waveform = _waveform;
            }

            if (checkBoxIncludeShotChanges.Checked && _shotChanges?.Count > 0)
            {
                model.ShotChanges = _shotChanges;
            }

            if (checkBoxIncludeBookmarks.Checked)
            {
                model.Bookmarks = new List <SeJobBookmark>();
                foreach (var p in _subtitle?.Paragraphs.Where(p => !string.IsNullOrEmpty(p.Bookmark)))
                {
                    model.Bookmarks.Add(new SeJobBookmark
                    {
                        Idx = _subtitle.GetIndex(p),
                        Txt = p.Bookmark,
                    });
                }
            }

            if (checkBoxIncludeRules.Checked)
            {
                model.Rules = new SeJobRules
                {
                    MaxNumberOfLines                    = (int)numericUpDownMaxNumberOfLines.Value,
                    SubtitleLineMaximumLength           = (int)numericUpDownSubtitleLineMaximumLength.Value,
                    SubtitleMaximumCharactersPerSeconds = numericUpDownMaxCharsSec.Value,
                    SubtitleMinimumDisplayMilliseconds  = (int)numericUpDownDurationMin.Value,
                    SubtitleMaximumDisplayMilliseconds  = (int)numericUpDownDurationMax.Value,
                    MinimumMillisecondsBetweenLines     = (int)numericUpDownMinGapMs.Value,
                    SubtitleMaximumWordsPerMinute       = numericUpDownMaxWordsMin.Value,
                    SubtitleOptimalCharactersPerSeconds = numericUpDownOptimalCharsSec.Value,
                };
            }

            using (var saveDialog = new SaveFileDialog {
                FileName = Path.GetFileNameWithoutExtension(model.SubtitleFileName), Filter = "se-job|*.se-job"
            })
            {
                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    File.WriteAllBytes(saveDialog.FileName, SeJobHandler.SaveSeJob(model));
                    DialogResult = DialogResult.OK;
                }
            }
        }