当前位置: 首页>>代码示例>>C#>>正文


C# Subtitle.LoadSubtitle方法代码示例

本文整理汇总了C#中Nikse.SubtitleEdit.Logic.Subtitle.LoadSubtitle方法的典型用法代码示例。如果您正苦于以下问题:C# Subtitle.LoadSubtitle方法的具体用法?C# Subtitle.LoadSubtitle怎么用?C# Subtitle.LoadSubtitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nikse.SubtitleEdit.Logic.Subtitle的用法示例。


在下文中一共展示了Subtitle.LoadSubtitle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AppendTextVisuallyToolStripMenuItemClick

        private void AppendTextVisuallyToolStripMenuItemClick(object sender, EventArgs e)
        {
            if (IsSubtitleLoaded)
            {
                ReloadFromSourceView();

                if (MessageBox.Show(_language.SubtitleAppendPrompt, _language.SubtitleAppendPromptTitle, MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    openFileDialog1.Title = _language.OpenSubtitleToAppend;
                    openFileDialog1.FileName = string.Empty;
                    openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
                    if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
                    {
                        bool success = false;
                        string fileName = openFileDialog1.FileName;
                        if (File.Exists(fileName))
                        {
                            var subtitleToAppend = new Subtitle();
                            Encoding encoding;
                            SubtitleFormat format = null;

                            // do not allow blu-ray/vobsub
                            string extension = Path.GetExtension(fileName).ToLower();
                            if (extension == ".sub" && (IsVobSubFile(fileName, false) || IsSpDvdSupFile(fileName)))
                            {
                                format = null;
                            }
                            else if (extension == ".sup" && IsBluRaySupFile(fileName))
                            {
                                format = null;
                            }
                            else
                            {
                                format = subtitleToAppend.LoadSubtitle(fileName, out encoding, null);
                                if (GetCurrentSubtitleFormat().IsFrameBased)
                                    subtitleToAppend.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
                                else
                                    subtitleToAppend.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                            }

                            if (format != null)
                            {
                                if (subtitleToAppend != null && subtitleToAppend.Paragraphs.Count > 1)
                                {
                                    var visualSync = new VisualSync();
                                    visualSync.Initialize(toolStripButtonVisualSync.Image as Bitmap, subtitleToAppend, _fileName, _language.AppendViaVisualSyncTitle, CurrentFrameRate);
                                    visualSync.ShowDialog(this);
                                    if (visualSync.OKPressed)
                                    {
                                        if (MessageBox.Show(_language.AppendSynchronizedSubtitlePrompt, _language.SubtitleAppendPromptTitle, MessageBoxButtons.YesNo) == DialogResult.Yes)
                                        {
                                            int start = _subtitle.Paragraphs.Count +1;
                                            var fr = CurrentFrameRate;
                                            MakeHistoryForUndo(_language.BeforeAppend);
                                            foreach (Paragraph p in visualSync.Paragraphs)
                                            {
                                                if (format.IsFrameBased)
                                                    p.CalculateFrameNumbersFromTimeCodes(fr);
                                                _subtitle.Paragraphs.Add(new Paragraph(p));
                                            }
                                            if (format.GetType() == typeof(AdvancedSubStationAlpha) && GetCurrentSubtitleFormat().GetType() == typeof(AdvancedSubStationAlpha))
                                            {
                                                List<string> currentStyles = new List<string>();
                                                if (_subtitle.Header != null)
                                                    currentStyles = AdvancedSubStationAlpha.GetStylesFromHeader(_subtitle.Header);
                                                foreach (string styleName in AdvancedSubStationAlpha.GetStylesFromHeader(subtitleToAppend.Header))
                                                {
                                                    bool alreadyExists = false;
                                                    foreach (string currentStyleName in currentStyles)
                                                    {
                                                        if (currentStyleName.ToLower().Trim() == styleName.ToLower().Trim())
                                                            alreadyExists = true;
                                                    }
                                                    if (!alreadyExists)
                                                    {
                                                        var newStyle = AdvancedSubStationAlpha.GetSsaStyle(styleName, subtitleToAppend.Header);
                                                        _subtitle.Header = AdvancedSubStationAlpha.AddSsaStyle(newStyle, _subtitle.Header);
                                                    }
                                                }
                                            }

                                            _subtitle.Renumber(1);

                                            ShowSource();
                                            SubtitleListview1.Fill(_subtitle, _subtitleAlternate);

                                            // select appended lines
                                            for (int i = start; i < _subtitle.Paragraphs.Count; i++)
                                                SubtitleListview1.Items[i].Selected = true;
                                            SubtitleListview1.EnsureVisible(start);

                                            ShowStatus(string.Format(_language.SubtitleAppendedX, fileName));
                                            success = true;
                                        }
                                    }
                                    visualSync.Dispose();
                                }
                            }
                        }
                        if (!success)
//.........这里部分代码省略.........
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:101,代码来源:Main.cs

示例2: BatchConvert


//.........这里部分代码省略.........
                                            string newFileName = fileName;
                                            if (subtitleList.Count > 1)
                                                newFileName = fileName.Insert(fileName.Length - 4, "_" + x.TrackNumber +  "_" + x.Language.Replace("?", string.Empty).Replace("!", string.Empty).Replace("*", string.Empty).Replace(",", string.Empty).Replace("/", string.Empty).Trim());

                                            if (format.GetType() == typeof(AdvancedSubStationAlpha) || format.GetType() == typeof(SubStationAlpha))
                                            {
                                                if (toFormat.ToLower() != new AdvancedSubStationAlpha().Name.ToLower().Replace(" ", string.Empty) &&
                                                    toFormat.ToLower() != new SubStationAlpha().Name.ToLower().Replace(" ", string.Empty))
                                                {

                                                    foreach (SubtitleFormat sf in formats)
                                                    {
                                                        if (sf.Name.ToLower().Replace(" ", string.Empty) == toFormat.ToLower() || sf.Name.ToLower().Replace(" ", string.Empty) == toFormat.Replace(" ", string.Empty).ToLower())
                                                        {
                                                            format.RemoveNativeFormatting(sub, sf);
                                                            break;
                                                        }
                                                    }

                                                }
                                            }

                                            BatchConvertSave(toFormat, offset, targetEncoding, outputFolder, count, ref converted, ref errors, formats, newFileName, sub, format, overwrite, pacCodePage);
                                            done = true;
                                        }
                                    }
                                }
                            }
                        }

                        var fi = new FileInfo(fileName);
                        if (fi.Length < 10 * 1024 * 1024 && !done) // max 10 mb
                        {
                            format = sub.LoadSubtitle(fileName, out encoding, null, true);

                            if (format == null)
                            {
                                var ebu = new Ebu();
                                if (ebu.IsMine(null, fileName))
                                {
                                    ebu.LoadSubtitle(sub, null, fileName);
                                    format = ebu;
                                }
                            }
                            if (format == null)
                            {
                                var pac = new Pac();
                                if (pac.IsMine(null, fileName))
                                {
                                    pac.BatchMode = true;
                                    pac.LoadSubtitle(sub, null, fileName);
                                    format = pac;
                                }
                            }
                            if (format == null)
                            {
                                var cavena890 = new Cavena890();
                                if (cavena890.IsMine(null, fileName))
                                {
                                    cavena890.LoadSubtitle(sub, null, fileName);
                                    format = cavena890;
                                }
                            }
                            if (format == null)
                            {
                                var spt = new Spt();
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:67,代码来源:Main.cs

示例3: ToolStripMenuItemInsertSubtitleClick

        private void ToolStripMenuItemInsertSubtitleClick(object sender, EventArgs e)
        {
            openFileDialog1.Title = _languageGeneral.OpenSubtitle;
            openFileDialog1.FileName = string.Empty;
            openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                if (!File.Exists(openFileDialog1.FileName))
                    return;

                var fi = new FileInfo(openFileDialog1.FileName);
                if (fi.Length > 1024 * 1024 * 10) // max 10 mb
                {
                    if (MessageBox.Show(string.Format(_language.FileXIsLargerThan10Mb + Environment.NewLine +
                                                      Environment.NewLine +
                                                      _language.ContinueAnyway,
                                                      openFileDialog1.FileName), Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                        return;
                }

                MakeHistoryForUndo(string.Format(_language.BeforeInsertLine, openFileDialog1.FileName));

                Encoding encoding = null;
                var subtitle = new Subtitle();
                SubtitleFormat format = subtitle.LoadSubtitle(openFileDialog1.FileName, out encoding, encoding);

                if (format != null)
                {
                    SaveSubtitleListviewIndexes();
                    if (format.IsFrameBased)
                        subtitle.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
                    else
                        subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);

                    if (Configuration.Settings.General.RemoveBlankLinesWhenOpening)
                        subtitle.RemoveEmptyLines();

                    int index = FirstSelectedIndex + 1;
                    if (index < 0)
                        index = 0;
                    foreach (Paragraph p in subtitle.Paragraphs)
                    {
                        _subtitle.Paragraphs.Insert(index, new Paragraph(p));
                        index++;
                    }

                    if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
                    {
                        index = FirstSelectedIndex;
                        if (index < 0)
                            index = 0;
                        Paragraph current = _subtitle.GetParagraphOrDefault(index);
                        if (current != null)
                        {
                            Paragraph original = Utilities.GetOriginalParagraph(index, current, _subtitleAlternate.Paragraphs);
                            if (original != null)
                            {
                                index = _subtitleAlternate.GetIndex(original);
                                foreach (Paragraph p in subtitle.Paragraphs)
                                {
                                    _subtitleAlternate.Paragraphs.Insert(index, new Paragraph(p));
                                    index++;
                                }
                                if (subtitle.Paragraphs.Count > 0)
                                    _subtitleAlternate.Renumber(1);
                            }
                        }
                    }
                    _subtitle.Renumber(1);
                    ShowSource();
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    RestoreSubtitleListviewIndexes();
                }
            }
        }
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:75,代码来源:Main.cs

示例4: toolStripMenuItemInsertTextFromSub_Click

        private void toolStripMenuItemInsertTextFromSub_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title = _languageGeneral.OpenSubtitle;
            openFileDialog1.FileName = string.Empty;
            openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                if (!File.Exists(openFileDialog1.FileName))
                    return;

                var fi = new FileInfo(openFileDialog1.FileName);
                if (fi.Length > 1024 * 1024 * 10) // max 10 mb
                {
                    if (MessageBox.Show(string.Format(_language.FileXIsLargerThan10Mb + Environment.NewLine +
                                                      Environment.NewLine +
                                                      _language.ContinueAnyway,
                                                      openFileDialog1.FileName), Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                        return;
                }

                Encoding encoding = null;
                var tmp = new Subtitle();
                SubtitleFormat format = tmp.LoadSubtitle(openFileDialog1.FileName, out encoding, encoding);

                if (format != null)
                {
                    if (format.IsFrameBased)
                        tmp.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
                    else
                        tmp.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);

                    if (Configuration.Settings.General.RemoveBlankLinesWhenOpening)
                        tmp.RemoveEmptyLines();

                    if (SubtitleListview1.SelectedIndices.Count < 1)
                        return;

                    MakeHistoryForUndo(_language.BeforeColumnShiftCellsDown);

                    int index = FirstSelectedIndex;
                    for (int i = 0; i < tmp.Paragraphs.Count; i++)
                    {

                        {
                            for (int k = _subtitle.Paragraphs.Count - 2; k > index; k--)
                            {
                                _subtitle.Paragraphs[k + 1].Text = _subtitle.Paragraphs[k].Text;
                            }
                        }
                    }
                    for (int i = 0; i + index < _subtitle.Paragraphs.Count && i < tmp.Paragraphs.Count; i++)
                        _subtitle.Paragraphs[index + i].Text = tmp.Paragraphs[i].Text;
                    if (IsFramesRelevant && CurrentFrameRate > 0)
                        _subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate);
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    SubtitleListview1.SelectIndexAndEnsureVisible(index, true);
                    RefreshSelectedParagraph();
                }
            }

        }
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:61,代码来源:Main.cs

示例5: ButtonOpenSubtitle2Click

        private void ButtonOpenSubtitle2Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = string.Empty;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (Main.HasVobSubHeader(openFileDialog1.FileName) || Main.IsBluRaySupFile(openFileDialog1.FileName))
                {
                    MessageBox.Show(Configuration.Settings.Language.CompareSubtitles.CannotCompareWithImageBasedSubtitles);
                    return;
                }
                _subtitle2 = new Subtitle();
                Encoding encoding;
                var format = _subtitle2.LoadSubtitle(openFileDialog1.FileName, out encoding, null);
                if (format == null)
                {
                    var pac = new Pac();
                    if (pac.IsMine(null, openFileDialog1.FileName))
                    {
                        pac.BatchMode = true;
                        pac.LoadSubtitle(_subtitle2, null, openFileDialog1.FileName);
                        format = pac;
                    }
                }
                if (format == null)
                {
                    var cavena890 = new Cavena890();
                    if (cavena890.IsMine(null, openFileDialog1.FileName))
                    {
                        cavena890.LoadSubtitle(_subtitle2, null, openFileDialog1.FileName);
                        format = cavena890;
                    }
                }

                subtitleListView2.Fill(_subtitle2);
                subtitleListView1.SelectIndexAndEnsureVisible(0);
                subtitleListView2.SelectIndexAndEnsureVisible(0);
                labelSubtitle2.Text = openFileDialog1.FileName;
                if (_subtitle2.Paragraphs.Count > 0)
                    CompareSubtitles();
            }
        }
开发者ID:athikan,项目名称:subtitleedit,代码行数:42,代码来源:Compare.cs

示例6: LoadAlternateSubtitleFile

        private bool LoadAlternateSubtitleFile(string fileName)
        {
            if (!File.Exists(fileName))
                return false;

            if (Path.GetExtension(fileName).ToLower() == ".sub" && IsVobSubFile(fileName, false))
                return false;

            var fi = new FileInfo(fileName);
            if (fi.Length > 1024 * 1024 * 10) // max 10 mb
            {
                if (MessageBox.Show(string.Format(_language.FileXIsLargerThan10Mb + Environment.NewLine +
                                                    Environment.NewLine +
                                                    _language.ContinueAnyway,
                                                    fileName), Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                    return false;
            }

            Encoding encoding;
            _subtitleAlternate = new Subtitle();
            _subtitleAlternateFileName = fileName;
            SubtitleFormat format = _subtitleAlternate.LoadSubtitle(fileName, out encoding, null);

            if (format == null)
            {
                var ebu = new Ebu();
                if (ebu.IsMine(null, fileName))
                {
                    ebu.LoadSubtitle(_subtitleAlternate, null, fileName);
                    format = ebu;
                }
            }
            if (format == null)
            {
                var pac = new Pac();
                if (pac.IsMine(null, fileName))
                {
                    pac.BatchMode = true;
                    pac.LoadSubtitle(_subtitleAlternate, null, fileName);
                    format = pac;
                }
            }
            if (format == null)
            {
                var cavena890 = new Cavena890();
                if (cavena890.IsMine(null, fileName))
                {
                    cavena890.LoadSubtitle(_subtitleAlternate, null, fileName);
                    format = cavena890;
                }
            }
            if (format == null)
            {
                var spt = new Spt();
                if (spt.IsMine(null, fileName))
                {
                    spt.LoadSubtitle(_subtitleAlternate, null, fileName);
                    format = spt;
                }
            }
            if (format == null)
            {
                var cheetahCaption = new CheetahCaption();
                if (cheetahCaption.IsMine(null, fileName))
                {
                    cheetahCaption.LoadSubtitle(_subtitleAlternate, null, fileName);
                    format = cheetahCaption;
                }
            }
            if (format == null)
            {
                var capMakerPlus = new CapMakerPlus();
                if (capMakerPlus.IsMine(null, fileName))
                {
                    capMakerPlus.LoadSubtitle(_subtitleAlternate, null, fileName);
                    format = capMakerPlus;
                }
            }
            if (format == null)
            {
                var captionate = new Captionate();
                if (captionate.IsMine(null, fileName))
                {
                    captionate.LoadSubtitle(_subtitleAlternate, null, fileName);
                    format = captionate;
                }
            }
            if (format == null)
            {
                var ultech130 = new Ultech130();
                if (ultech130.IsMine(null, fileName))
                {
                    ultech130.LoadSubtitle(_subtitleAlternate, null, fileName);
                    format = ultech130;
                }
            }
            if (format == null)
            {
                var nciCaption = new NciCaption();
                if (nciCaption.IsMine(null, fileName))
//.........这里部分代码省略.........
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:101,代码来源:Main.cs

示例7: SortAndLoad

        /// <summary>
        /// The sort and load.
        /// </summary>
        private void SortAndLoad()
        {
            this.JoinedFormat = new SubRip(); // default subtitle format
            string header = null;
            SubtitleFormat lastFormat = null;
            var subtitles = new List<Subtitle>();
            for (int k = 0; k < this._fileNamesToJoin.Count; k++)
            {
                string fileName = this._fileNamesToJoin[k];
                try
                {
                    var sub = new Subtitle();
                    Encoding encoding;
                    var format = sub.LoadSubtitle(fileName, out encoding, null);
                    if (format == null)
                    {
                        for (int j = k; j < this._fileNamesToJoin.Count; j++)
                        {
                            this._fileNamesToJoin.RemoveAt(j);
                        }

                        MessageBox.Show("Unkown subtitle format: " + fileName);
                        return;
                    }

                    if (sub.Header != null)
                    {
                        header = sub.Header;
                    }

                    if (lastFormat == null || lastFormat.FriendlyName == format.FriendlyName)
                    {
                        lastFormat = format;
                    }
                    else
                    {
                        lastFormat = new SubRip(); // default subtitle format
                    }

                    subtitles.Add(sub);
                }
                catch (Exception exception)
                {
                    for (int j = k; j < this._fileNamesToJoin.Count; j++)
                    {
                        this._fileNamesToJoin.RemoveAt(j);
                    }

                    MessageBox.Show(exception.Message);
                    return;
                }
            }

            this.JoinedFormat = lastFormat;

            for (int outer = 0; outer < subtitles.Count; outer++)
            {
                for (int inner = 1; inner < subtitles.Count; inner++)
                {
                    var a = subtitles[inner - 1];
                    var b = subtitles[inner];
                    if (a.Paragraphs.Count > 0 && b.Paragraphs.Count > 0 && a.Paragraphs[0].StartTime.TotalMilliseconds > b.Paragraphs[0].StartTime.TotalMilliseconds)
                    {
                        string t1 = this._fileNamesToJoin[inner - 1];
                        this._fileNamesToJoin[inner - 1] = this._fileNamesToJoin[inner];
                        this._fileNamesToJoin[inner] = t1;

                        var t2 = subtitles[inner - 1];
                        subtitles[inner - 1] = subtitles[inner];
                        subtitles[inner] = t2;
                    }
                }
            }

            this.listViewParts.BeginUpdate();
            this.listViewParts.Items.Clear();
            int i = 0;
            foreach (string fileName in this._fileNamesToJoin)
            {
                Subtitle sub = subtitles[i];
                var lvi = new ListViewItem(string.Format("{0:#,###,###}", sub.Paragraphs.Count));
                if (sub.Paragraphs.Count > 0)
                {
                    lvi.SubItems.Add(sub.Paragraphs[0].StartTime.ToString());
                    lvi.SubItems.Add(sub.Paragraphs[sub.Paragraphs.Count - 1].StartTime.ToString());
                }
                else
                {
                    lvi.SubItems.Add("-");
                    lvi.SubItems.Add("-");
                }

                lvi.SubItems.Add(fileName);
                this.listViewParts.Items.Add(lvi);
                i++;
            }

//.........这里部分代码省略.........
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:101,代码来源:JoinSubtitles.cs

示例8: buttonConvert_Click

        private void buttonConvert_Click(object sender, EventArgs e)
        {
            if (listViewInputFiles.Items.Count == 0)
            {
                MessageBox.Show(Configuration.Settings.Language.BatchConvert.NothingToConvert);
                return;
            }

            if (!checkBoxOverwriteOriginalFiles.Checked)
            {
                if (textBoxOutputFolder.Text.Length < 2)
                {
                    MessageBox.Show(Configuration.Settings.Language.BatchConvert.PleaseChooseOutputFolder);
                    return;
                }
                else if (!Directory.Exists(textBoxOutputFolder.Text))
                {
                    try
                    {
                        Directory.CreateDirectory(textBoxOutputFolder.Text);
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message);
                        return;
                    }
                }
            }

            _converting = true;
            buttonConvert.Enabled = false;
            buttonCancel.Enabled = false;
            progressBar1.Style = ProgressBarStyle.Blocks;
            progressBar1.Maximum = listViewInputFiles.Items.Count;
            progressBar1.Value = 0;
            progressBar1.Visible = progressBar1.Maximum > 2;
            string toFormat = comboBoxSubtitleFormats.Text;
            groupBoxOutput.Enabled = false;
            groupBoxConvertOptions.Enabled = false;
            buttonInputBrowse.Enabled = false;
            buttonSearchFolder.Enabled = false;
            _count = 0;
            _converted = 0;
            _errors = 0;
            _abort = false;

            BackgroundWorker worker1 = new BackgroundWorker();
            BackgroundWorker worker2 = new BackgroundWorker();
            BackgroundWorker worker3 = new BackgroundWorker();
            worker1.DoWork += DoThreadWork;
            worker1.RunWorkerCompleted += ThreadWorkerCompleted;
            worker2.DoWork += DoThreadWork;
            worker2.RunWorkerCompleted += ThreadWorkerCompleted;
            worker3.DoWork += DoThreadWork;
            worker3.RunWorkerCompleted += ThreadWorkerCompleted;

            listViewInputFiles.BeginUpdate();
            foreach (ListViewItem item in listViewInputFiles.Items)
                item.SubItems[3].Text = "-";
            listViewInputFiles.EndUpdate();
            Refresh();

            int index = 0;
            while (index < listViewInputFiles.Items.Count && _abort == false)
            {
                ListViewItem item = listViewInputFiles.Items[index];
                string fileName = item.Text;

                try
                {
                    SubtitleFormat format = null;
                    Encoding encoding;
                    var sub = new Subtitle();
                    var fi = new FileInfo(fileName);
                    if (fi.Length < 1024 * 1024) // max 1 mb
                    {
                        format = sub.LoadSubtitle(fileName, out encoding, null);

                        if (format == null)
                        {
                            var ebu = new Ebu();
                            if (ebu.IsMine(null, fileName))
                            {
                                ebu.LoadSubtitle(sub, null, fileName);
                                format = ebu;
                            }
                        }
                        if (format == null)
                        {
                            var pac = new Pac();
                            if (pac.IsMine(null, fileName))
                            {
                                pac.LoadSubtitle(sub, null, fileName);
                                format = pac;
                            }
                        }
                        if (format == null)
                        {
                            var cavena890 = new Cavena890();
                            if (cavena890.IsMine(null, fileName))
//.........这里部分代码省略.........
开发者ID:novaterata,项目名称:subtitleedit,代码行数:101,代码来源:BatchConvert.cs

示例9: ButtonOpenSubtitle2Click

        private void ButtonOpenSubtitle2Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = string.Empty;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (Main.HasVobSubHeader(openFileDialog1.FileName) || Main.IsBluRaySupFile(openFileDialog1.FileName))
                {
                    MessageBox.Show(Configuration.Settings.Language.CompareSubtitles.CannotCompareWithImageBasedSubtitles);
                    return;
                }
                _subtitle2 = new Subtitle();
                Encoding encoding;
                _subtitle2.LoadSubtitle(openFileDialog1.FileName, out encoding, null);
                subtitleListView2.Fill(_subtitle2);
                subtitleListView1.SelectIndexAndEnsureVisible(0);
                subtitleListView2.SelectIndexAndEnsureVisible(0);
                labelSubtitle2.Text = openFileDialog1.FileName;
                if (_subtitle2.Paragraphs.Count > 0)
                    CompareSubtitles();
            }
        }
开发者ID:nshayanfar,项目名称:subtitleedit,代码行数:22,代码来源:Compare.cs

示例10: VerifyDragDrop

        private void VerifyDragDrop(ListView listView, DragEventArgs e)
        {
            var files = e.Data.GetData(DataFormats.FileDrop) as string[];
            if (files.Length > 1)
            {
                MessageBox.Show(Configuration.Settings.Language.Main.DropOnlyOneFile,
                    "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string filePath = files[0];
            var listExt = new List<string>();
            foreach (var s in Utilities.GetOpenDialogFilter().Split("*".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
            {
                if (s.EndsWith(";"))
                    listExt.Add(s.Trim(';'));
            }
            if (!listExt.Contains(Path.GetExtension(filePath)))
                return;
            if (Main.HasVobSubHeader(filePath) || Main.IsBluRaySupFile(filePath))
            {
                MessageBox.Show(Configuration.Settings.Language.CompareSubtitles.CannotCompareWithImageBasedSubtitles);
                return;
            }
            Encoding encoding;
            if (listView.Name == "subtitleListView1")
            {
                _subtitle1 = new Subtitle();
                _subtitle1.LoadSubtitle(filePath, out encoding, null);
                subtitleListView1.Fill(_subtitle1);
                subtitleListView1.SelectIndexAndEnsureVisible(0);
                subtitleListView2.SelectIndexAndEnsureVisible(0);
                labelSubtitle1.Text = filePath;
                _language1 = Utilities.AutoDetectGoogleLanguage(_subtitle1);
                if (_subtitle1.Paragraphs.Count > 0)
                    CompareSubtitles();
            }
            else
            {
                _subtitle2 = new Subtitle();
                _subtitle2.LoadSubtitle(filePath, out encoding, null);
                subtitleListView2.Fill(_subtitle2);
                subtitleListView1.SelectIndexAndEnsureVisible(0);
                subtitleListView2.SelectIndexAndEnsureVisible(0);
                labelSubtitle2.Text = filePath;
                if (_subtitle2.Paragraphs.Count > 0)
                    CompareSubtitles();
            }
        }
开发者ID:nshayanfar,项目名称:subtitleedit,代码行数:49,代码来源:Compare.cs

示例11: importNewTimeCodesToolStripMenuItem_Click

        private void importNewTimeCodesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title = Configuration.Settings.Language.General.OpenSubtitle;
            openFileDialog1.FileName = string.Empty;
            openFileDialog1.Filter = Utilities.GetOpenDialogFilter();
            if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
            {
                string fileName = openFileDialog1.FileName;
                if (!File.Exists(fileName))
                    return;

                var fi = new FileInfo(fileName);
                if (fi.Length > 1024 * 1024 * 10) // max 10 mb
                {
                    if (MessageBox.Show(string.Format(Configuration.Settings.Language.Main.FileXIsLargerThan10MB + Environment.NewLine +
                                                      Environment.NewLine +
                                                      Configuration.Settings.Language.Main.ContinueAnyway,
                                                      fileName), Text, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                        return;
                }

                Subtitle sub = new Subtitle();
                Encoding encoding;
                SubtitleFormat format = sub.LoadSubtitle(fileName, out encoding, null);
                if (format == null)
                    return;

                int index = 0;
                foreach (Paragraph p in sub.Paragraphs)
                {
                    if (index < _subtitle.Paragraphs.Count)
                    {
                        Paragraph currentP = _subtitle.Paragraphs[index];
                        currentP.StartTime.TotalMilliseconds = p.StartTime.TotalMilliseconds;
                        currentP.EndTime.TotalMilliseconds = p.EndTime.TotalMilliseconds;
                        subtitleListView1.SetStartTime(index, currentP);
                    }
                    index++;
                }
            }
        }
开发者ID:athikan,项目名称:subtitleedit,代码行数:41,代码来源:VobSubOcr.cs

示例12: buttonExport_Click

        private void buttonExport_Click(object sender, EventArgs e)
        {
            if (listViewStyles.SelectedItems.Count != 1)
                return;

            string styleName = listViewStyles.SelectedItems[0].Text;

            saveFileDialogStyle.Title = Configuration.Settings.Language.SubStationAlphaStyles.ExportStyleToFile;
            saveFileDialogStyle.InitialDirectory = Configuration.DataDirectory;
            if (_isSubStationAlpha)
            {
                saveFileDialogStyle.Filter = new SubStationAlpha().Name + "|*.ssa|" + Configuration.Settings.Language.General.AllFiles + "|*.*";
                saveFileDialogStyle.FileName = "my_styles.ssa";
            }
            else
            {
                saveFileDialogStyle.Filter = new AdvancedSubStationAlpha().Name + "|*.ass|" + Configuration.Settings.Language.General.AllFiles + "|*.*";
                saveFileDialogStyle.FileName = "my_styles.ass";
            }

            if (saveFileDialogStyle.ShowDialog(this) == DialogResult.OK)
            {
                if (File.Exists(saveFileDialogStyle.FileName))
                {
                    Encoding encoding = null;
                    var s = new Subtitle();
                    var format = s.LoadSubtitle(saveFileDialogStyle.FileName, out encoding, null);
                    if (format == null)
                    {
                        MessageBox.Show("Not subtitle format: " + _format.Name);
                        return;
                    }
                    else if (format.Name != _format.Name)
                    {
                        MessageBox.Show(string.Format("Cannot save {1} style in {0} file!", format.Name, _format.Name));
                        return;
                    }
                    else
                    {
                        var sb = new StringBuilder();
                        bool stylesOn = false;
                        bool done = false;
                        string styleFormat = "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding";
                        foreach (string line in File.ReadAllLines(saveFileDialogStyle.FileName))
                        {
                            if (line.ToLower().StartsWith("format:"))
                            {
                                styleFormat = line;
                            }
                            else if (line.ToLower().StartsWith("style:"))
                            {
                                stylesOn = true;
                            }
                            else if (stylesOn && !done)
                            {
                                done = true;
                                SsaStyle style = GetSsaStyle(styleName);
                                if (_isSubStationAlpha)
                                {
                                    sb.AppendLine(style.ToRawSsa(styleFormat));
                                }
                                else
                                {
                                    sb.AppendLine(style.ToRawAss(styleFormat));
                                }
                            }
                            sb.AppendLine(line);
                            if (stylesOn && line.Replace(" ", string.Empty).Trim().ToLower().StartsWith("style:" + styleName.Replace(" ", string.Empty).Trim().ToLower() + ","))
                            {
                                MessageBox.Show(string.Format(Configuration.Settings.Language.SubStationAlphaStyles.StyleAlreadyExits, styleName));
                                return;
                            }
                        }
                        File.WriteAllText(saveFileDialogStyle.FileName, sb.ToString(), Encoding.UTF8);
                    }
                }
                else
                {
                    var sb = new StringBuilder();
                    foreach (string line in Header.Replace(Environment.NewLine, "\n").Split('\n'))
                    {
                        if (line.ToLower().StartsWith("style:"))
                        {
                            if (line.ToLower().Replace(" ", string.Empty).StartsWith("style:" + styleName.ToLower().Trim()))
                                sb.AppendLine(line);
                        }
                        else
                        {
                            sb.AppendLine(line);
                        }
                    }
                    string content = sb.ToString();
                    if (content.Trim().EndsWith("[Events]"))
                    {
                        content = content.Trim() + Environment.NewLine +
                            "Format: Layer, Start, End, Style, Actor, MarginL, MarginR, MarginV, Effect, Text" + Environment.NewLine +
                            "Dialogue: 0,0:00:31.91,0:00:33.91,Default,,0,0,0,,My Styles :)";
                    }
                    File.WriteAllText(saveFileDialogStyle.FileName, content, Encoding.UTF8);
                }
//.........这里部分代码省略.........
开发者ID:rragu,项目名称:subtitleedit,代码行数:101,代码来源:SubStationAlphaStyles.cs

示例13: buttonImport_Click

        private void buttonImport_Click(object sender, EventArgs e)
        {
            openFileDialogImport.Title = Configuration.Settings.Language.SubStationAlphaStyles.ImportStyleFromFile;
            openFileDialogImport.InitialDirectory = Configuration.DataDirectory;
            if (_isSubStationAlpha)
            {
                openFileDialogImport.Filter = new SubStationAlpha().Name + "|*.ssa|" + Configuration.Settings.Language.General.AllFiles + "|*.*";
                saveFileDialogStyle.FileName = "my_styles.ssa";
            }
            else
            {
                openFileDialogImport.Filter = new AdvancedSubStationAlpha().Name + "|*.ass|" + Configuration.Settings.Language.General.AllFiles + "|*.*";
                saveFileDialogStyle.FileName = "my_styles.ass";
            }

            if (openFileDialogImport.ShowDialog(this) == DialogResult.OK)
            {
                Encoding encoding = null;
                var s = new Subtitle();
                var format = s.LoadSubtitle(openFileDialogImport.FileName, out encoding, null);
                if (format != null && format.HasStyleSupport)
                {
                    var styles = AdvancedSubStationAlpha.GetStylesFromHeader(s.Header);
                    if (styles.Count > 0)
                    {
                        var cs = new ChooseStyle(s, format.GetType() == typeof(SubStationAlpha));
                        if (cs.ShowDialog(this) == DialogResult.OK && cs.SelectedStyleName != null)
                        {
                            SsaStyle style = AdvancedSubStationAlpha.GetSsaStyle(cs.SelectedStyleName, s.Header);
                            if (GetSsaStyle(style.Name).LoadedFromHeader)
                            {
                                int count = 2;
                                bool doRepeat = GetSsaStyle(style.Name + count.ToString()).LoadedFromHeader;
                                while (doRepeat)
                                {
                                    doRepeat = GetSsaStyle(style.Name + count.ToString()).LoadedFromHeader;
                                    count++;
                                }
                                style.RawLine = style.RawLine.Replace(" " + style.Name + ",", " " + style.Name + count.ToString() + ",");
                                style.Name = style.Name + count.ToString();
                            }

                            _doUpdate = false;
                            AddStyle(listViewStyles, style, _subtitle, _isSubStationAlpha);
                            SsaStyle oldStyle = GetSsaStyle(listViewStyles.Items[0].Text);
                            Header = Header.Trim();
                            if (Header.EndsWith("[Events]"))
                            {
                                Header = Header.Substring(0, Header.Length - "[Events]".Length).Trim();
                                Header += Environment.NewLine + style.RawLine;
                                Header += Environment.NewLine + Environment.NewLine + "[Events]" + Environment.NewLine;
                            }
                            else
                            {
                                Header = Header.Trim() + Environment.NewLine + style.RawLine + Environment.NewLine;
                            }

                            listViewStyles.Items[listViewStyles.Items.Count - 1].Selected = true;
                            listViewStyles.Items[listViewStyles.Items.Count - 1].EnsureVisible();
                            listViewStyles.Items[listViewStyles.Items.Count - 1].Focused = true;
                            textBoxStyleName.Text = style.Name;
                            textBoxStyleName.Focus();
                            _doUpdate = true;
                            SetControlsFromStyle(style);
                            listViewStyles_SelectedIndexChanged(null, null);

                            if (!string.IsNullOrEmpty(Configuration.Settings.Language.SubStationAlphaStyles.StyleXImportedFromFileY)) // TODO: Remove in 3.4
                                labelStatus.Text = string.Format(Configuration.Settings.Language.SubStationAlphaStyles.StyleXImportedFromFileY, style.Name, openFileDialogImport.FileName);
                            timerClearStatus.Start();
                        }
                    }
                }
            }
        }
开发者ID:rragu,项目名称:subtitleedit,代码行数:74,代码来源:SubStationAlphaStyles.cs

示例14: SearchFolder

 private void SearchFolder(string path)
 {
     foreach (string fileName in Directory.GetFiles(path))
     {
         try
         {
             string ext = Path.GetExtension(fileName).ToLower();
             if (ext != ".png" && ext != ".jpg" && ext != ".dll" && ext != ".exe" && ext != ".zip")
             {
                 var fi = new FileInfo(fileName);
                 if (fi.Length < 1024 * 1024) // max 1 mb
                 {
                     Encoding encoding;
                     var sub = new Subtitle();
                     SubtitleFormat format = sub.LoadSubtitle(fileName, out encoding, null);
                     if (format != null)
                     {
                         var item = new ListViewItem(fileName);
                         item.SubItems.Add(Utilities.FormatBytesToDisplayFileSize(fi.Length));
                         item.SubItems.Add(format.Name);
                         item.SubItems.Add("-");
                         listViewInputFiles.Items.Add(item);
                     }
                 }
                 progressBar1.Refresh();
                 Application.DoEvents();
                 if (_abort)
                     return;
             }
         }
         catch
         {
         }
     }
     if (checkBoxScanFolderRecursive.Checked)
     {
         foreach (string directory in Directory.GetDirectories(path))
         {
             if (directory != "." && directory != "..")
                 SearchFolder(directory);
             if (_abort)
                 return;
         }
     }
 }
开发者ID:novaterata,项目名称:subtitleedit,代码行数:45,代码来源:BatchConvert.cs

示例15: pointSyncViaOtherSubtitleToolStripMenuItem_Click


//.........这里部分代码省略.........
                            {
                                MessageBox.Show(_language.NoSubtitlesFound);
                                return;
                            }
                            else
                            {
                                if (subtitleList.Count > 1)
                                {
                                    MatroskaSubtitleChooser subtitleChooser = new MatroskaSubtitleChooser();
                                    subtitleChooser.Initialize(subtitleList);
                                    if (_loading)
                                    {
                                        subtitleChooser.Icon = (Icon)this.Icon.Clone();
                                        subtitleChooser.ShowInTaskbar = true;
                                        subtitleChooser.ShowIcon = true;
                                    }
                                    if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
                                    {
                                        sub = LoadMatroskaSubtitleForSync(subtitleList[subtitleChooser.SelectedIndex], fileName);
                                    }
                                }
                                else
                                {
                                    sub = LoadMatroskaSubtitleForSync(subtitleList[0], fileName);
                                }
                            }
                        }
                    }
                }

                if (Path.GetExtension(fileName).ToLower() == ".divx" || Path.GetExtension(fileName).ToLower() == ".avi")
                {
                    MessageBox.Show("Divx files not supported here");
                    return;
                }

                var fi = new FileInfo(fileName);

                if ((Path.GetExtension(fileName).ToLower() == ".mp4" || Path.GetExtension(fileName).ToLower() == ".m4v" || Path.GetExtension(fileName).ToLower() == ".3gp")
                    && fi.Length > 10000)
                {
                    var mp4Parser = new Logic.Mp4.Mp4Parser(fileName);
                    var mp4SubtitleTracks = mp4Parser.GetSubtitleTracks();
                    if (mp4SubtitleTracks.Count == 0)
                    {
                        MessageBox.Show(_language.NoSubtitlesFound);
                        return;
                    }
                    else if (mp4SubtitleTracks.Count == 1)
                    {
                        sub = LoadMp4SubtitleForSync(fileName, mp4SubtitleTracks[0]);
                    }
                    else
                    {
                        var subtitleChooser = new MatroskaSubtitleChooser();
                        subtitleChooser.Initialize(mp4SubtitleTracks);
                        if (subtitleChooser.ShowDialog(this) == DialogResult.OK)
                        {
                            sub = LoadMp4SubtitleForSync(fileName, mp4SubtitleTracks[0]);
                        }
                    }
                }

                if (fi.Length > 1024 * 1024 * 10 && sub.Paragraphs.Count == 0) // max 10 mb
                {
                    if (MessageBox.Show(this, string.Format(_language.FileXIsLargerThan10Mb + Environment.NewLine +
                                                      Environment.NewLine +
                                                      _language.ContinueAnyway,
                                                      fileName), Title, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                        return;
                }

                sub.Renumber(1);
                if (sub.Paragraphs.Count == 0)
                {
                    SubtitleFormat f = sub.LoadSubtitle(fileName, out enc, null);
                    if (f == null)
                    {
                        ShowUnknownSubtitle();
                        return;
                    }
                }

                pointSync.Initialize(_subtitle, _fileName, _videoFileName, _videoAudioTrackNumber, fileName, sub);
                mediaPlayer.Pause();
                if (pointSync.ShowDialog(this) == DialogResult.OK)
                {
                    _subtitleListViewIndex = -1;
                    MakeHistoryForUndo(_language.BeforePointSynchronization);
                    _subtitle.Paragraphs.Clear();
                    foreach (Paragraph p in pointSync.FixedSubtitle.Paragraphs)
                        _subtitle.Paragraphs.Add(p);
                    _subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate);
                    ShowStatus(_language.PointSynchronizationDone);
                    ShowSource();
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                }
                _videoFileName = pointSync.VideoFileName;
            }
        }
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:101,代码来源:Main.cs


注:本文中的Nikse.SubtitleEdit.Logic.Subtitle.LoadSubtitle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。