diff --git a/libse/SubtitleFormats/SubtitleFormat.cs b/libse/SubtitleFormats/SubtitleFormat.cs index 8e8aef7c5..3d6659980 100644 --- a/libse/SubtitleFormats/SubtitleFormat.cs +++ b/libse/SubtitleFormats/SubtitleFormat.cs @@ -507,12 +507,20 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats { var formats = new SubtitleFormat[] { - new FinalCutProImage(), - new SpuImage(), - new Ebu(), - new BdnXml(), - new Pac(), - new Cavena890(), + new Ebu(), new Pac(),new PacUnicode(), new Cavena890(), new Spt(), new CheetahCaption(), + new Chk(), new Ayato(), new CapMakerPlus(), new Captionate(), new Ultech130(), new NciCaption(), new AvidStl(), + new WinCaps32(), new IsmtDfxp(), new Cavena890(), new Spt(), new IaiSub(), new ELRStudioClosedCaption(), new CaptionsInc() + }; + return formats; + } + + public static SubtitleFormat[] GetTextOtherFormats() + { + var formats = new SubtitleFormat[] + { + new DlDd(),new Ted20(), new CapMakerPlus(), new Captionate(), + new TimeLineAscii(), new TimeLineFootageAscii(), new TimedTextImage(), new FinalCutProImage(), + new SpuImage(), new Dost(), new SeImageHtmlIndex(), new BdnXml() }; return formats; } diff --git a/src/Forms/BatchConvert.cs b/src/Forms/BatchConvert.cs index a0d2a5646..f115f119f 100644 --- a/src/Forms/BatchConvert.cs +++ b/src/Forms/BatchConvert.cs @@ -79,6 +79,8 @@ namespace Nikse.SubtitleEdit.Forms private string _customTextTemplate; private readonly DurationsBridgeGaps _bridgeGaps; private const int ConvertMaxFileSize = 1024 * 1024 * 10; // 10 MB + private SubtitleFormat[] _formatsBinary; + private SubtitleFormat[] _formatsOtherText; public BatchConvert(Icon icon) { @@ -87,6 +89,9 @@ namespace Nikse.SubtitleEdit.Forms UiUtil.FixFonts(this); Icon = (Icon)icon.Clone(); + _formatsBinary = SubtitleFormat.GetBinaryFormats(); + _formatsOtherText = SubtitleFormat.GetTextOtherFormats(); + progressBar1.Visible = false; labelStatus.Text = string.Empty; var l = Configuration.Settings.Language.BatchConvert; @@ -317,201 +322,29 @@ namespace Nikse.SubtitleEdit.Forms if (format == null) { - var ebu = new Ebu(); - if (ebu.IsMine(null, fileName)) + foreach (var f in _formatsBinary) { - format = ebu; + if (f.IsMine(null, fileName)) + { + f.LoadSubtitle(sub, null, fileName); + format = f; + break; + } } } + if (format == null) { - var pac = new Pac(); - if (pac.IsMine(null, fileName)) + var encoding = LanguageAutoDetect.GetEncodingFromFile(fileName); + var lines = FileUtil.ReadAllTextShared(fileName, encoding).SplitToLines(); + foreach (var f in _formatsOtherText) { - format = pac; - } - } - if (format == null) - { - var cavena890 = new Cavena890(); - if (cavena890.IsMine(null, fileName)) - { - format = cavena890; - } - } - if (format == null) - { - var spt = new Spt(); - if (spt.IsMine(null, fileName)) - { - format = spt; - } - } - if (format == null) - { - var cheetahCaption = new CheetahCaption(); - if (cheetahCaption.IsMine(null, fileName)) - { - format = cheetahCaption; - } - } - if (format == null) - { - var chk = new Chk(); - if (chk.IsMine(null, fileName)) - { - format = chk; - } - } - if (format == null) - { - var ayato = new Ayato(); - if (ayato.IsMine(null, fileName)) - { - format = ayato; - } - } - if (format == null) - { - var f = new PacUnicode(); - if (f.IsMine(null, fileName)) - { - format = f; - } - } - if (format == null) - { - var f = new IaiSub(); - if (f.IsMine(null, fileName)) - { - format = f; - } - } - var lines = new List(); - if (format == null) - { - lines = File.ReadAllText(fileName).SplitToLines(); - var f = new DlDd(); - if (f.IsMine(lines, fileName)) // not binary, so text lines are needed - { - format = f; - } - } - if (format == null) - { - var f = new Ted20(); - if (f.IsMine(null, fileName)) - { - format = f; - } - } - if (format == null) - { - var capMakerPlus = new CapMakerPlus(); - if (capMakerPlus.IsMine(null, fileName)) - { - format = capMakerPlus; - } - } - if (format == null) - { - var captionate = new Captionate(); - if (captionate.IsMine(null, fileName)) - { - format = captionate; - } - } - if (format == null) - { - var ultech130 = new Ultech130(); - if (ultech130.IsMine(null, fileName)) - { - format = ultech130; - } - } - if (format == null) - { - var nciCaption = new NciCaption(); - if (nciCaption.IsMine(null, fileName)) - { - format = nciCaption; - } - } - if (format == null) - { - var avidStl = new AvidStl(); - if (avidStl.IsMine(null, fileName)) - { - format = avidStl; - } - } - if (format == null) - { - var asc = new TimeLineAscii(); - if (asc.IsMine(lines, fileName)) - { - format = asc; - } - } - if (format == null) - { - var asc = new TimeLineFootageAscii(); - if (asc.IsMine(lines, fileName)) - { - format = asc; - } - } - if (format == null) - { - var timedTextImage = new TimedTextImage(); - if (timedTextImage.IsMine(lines, fileName)) - { - format = timedTextImage; - } - } - if (format == null) - { - var finalCutProImage = new FinalCutProImage(); - if (finalCutProImage.IsMine(lines, fileName)) - { - finalCutProImage.LoadSubtitle(sub, lines, fileName); - format = finalCutProImage; - } - } - if (format == null) - { - var spuImage = new SpuImage(); - if (spuImage.IsMine(lines, fileName)) - { - spuImage.LoadSubtitle(sub, lines, fileName); - format = spuImage; - } - } - if (format == null) - { - var dost = new Dost(); - if (dost.IsMine(lines, fileName)) - { - dost.LoadSubtitle(sub, lines, fileName); - format = dost; - } - } - if (format == null) - { - var seImageHtmlIndex = new SeImageHtmlIndex(); - if (seImageHtmlIndex.IsMine(lines, fileName)) - { - seImageHtmlIndex.LoadSubtitle(sub, lines, fileName); - format = seImageHtmlIndex; - } - } - if (format == null) - { - var bdnXml = new BdnXml(); - if (bdnXml.IsMine(lines, fileName)) - { - bdnXml.LoadSubtitle(sub, lines, fileName); - format = bdnXml; + if (f.IsMine(lines, fileName)) + { + f.LoadSubtitle(sub, lines, fileName); + format = f; + break; + } } } } @@ -778,142 +611,32 @@ namespace Nikse.SubtitleEdit.Forms if (fi.Length < ConvertMaxFileSize && !FileUtil.IsBluRaySup(fileName) && !FileUtil.IsVobSub(fileName)) { format = sub.LoadSubtitle(fileName, out _, null); + if (format == null) { - var ebu = new Ebu(); - if (ebu.IsMine(null, fileName)) + foreach (var f in _formatsBinary) { - ebu.LoadSubtitle(sub, null, fileName); - format = ebu; + if (f.IsMine(null, fileName)) + { + f.LoadSubtitle(sub, null, fileName); + format = f; + break; + } } } + if (format == null) { - var pac = new Pac(); - if (pac.IsMine(null, fileName)) + var encoding = LanguageAutoDetect.GetEncodingFromFile(fileName); + var lines = FileUtil.ReadAllTextShared(fileName, encoding).SplitToLines(); + foreach (var f in _formatsOtherText) { - 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(); - if (spt.IsMine(null, fileName)) - { - spt.LoadSubtitle(sub, null, fileName); - format = spt; - } - } - if (format == null) - { - var cheetahCaption = new CheetahCaption(); - if (cheetahCaption.IsMine(null, fileName)) - { - cheetahCaption.LoadSubtitle(sub, null, fileName); - format = cheetahCaption; - } - } - if (format == null) - { - var chk = new Chk(); - if (chk.IsMine(null, fileName)) - { - chk.LoadSubtitle(sub, null, fileName); - format = chk; - } - } - if (format == null) - { - var ayato = new Ayato(); - if (ayato.IsMine(null, fileName)) - { - ayato.LoadSubtitle(sub, null, fileName); - format = ayato; - } - } - if (format == null) - { - var capMakerPlus = new CapMakerPlus(); - if (capMakerPlus.IsMine(null, fileName)) - { - capMakerPlus.LoadSubtitle(sub, null, fileName); - format = capMakerPlus; - } - } - if (format == null) - { - var captionate = new Captionate(); - if (captionate.IsMine(null, fileName)) - { - captionate.LoadSubtitle(sub, null, fileName); - format = captionate; - } - } - if (format == null) - { - var ultech130 = new Ultech130(); - if (ultech130.IsMine(null, fileName)) - { - ultech130.LoadSubtitle(sub, null, fileName); - format = ultech130; - } - } - if (format == null) - { - var nciCaption = new NciCaption(); - if (nciCaption.IsMine(null, fileName)) - { - nciCaption.LoadSubtitle(sub, null, fileName); - format = nciCaption; - } - } - if (format == null) - { - var avidStl = new AvidStl(); - if (avidStl.IsMine(null, fileName)) - { - avidStl.LoadSubtitle(sub, null, fileName); - format = avidStl; - } - } - if (format == null) - { - var elr = new ELRStudioClosedCaption(); - if (elr.IsMine(null, fileName)) - { - elr.LoadSubtitle(sub, null, fileName); - format = elr; - } - } - var lines = new List(); - if (format == null) - { - lines = File.ReadAllText(fileName).SplitToLines(); - var timedTextImage = new TimedTextImage(); - if (timedTextImage.IsMine(lines, fileName)) - { - timedTextImage.LoadSubtitle(sub, lines, fileName); - format = timedTextImage; - } - } - if (format == null) - { - var bdnXml = new BdnXml(); - if (bdnXml.IsMine(lines, fileName)) - { - bdnXml.LoadSubtitle(sub, lines, fileName); - format = bdnXml; + if (f.IsMine(lines, fileName)) + { + f.LoadSubtitle(sub, lines, fileName); + format = f; + break; + } } } @@ -1885,6 +1608,9 @@ namespace Nikse.SubtitleEdit.Forms { var sub = new Subtitle(); var format = sub.LoadSubtitle(fileName, out _, null); + + var formats = new List { }; + if (format == null) { var ebu = new Ebu(); @@ -1981,6 +1707,24 @@ namespace Nikse.SubtitleEdit.Forms format = avidStl; } } + if (format == null) + { + var f = new WinCaps32(); + if (f.IsMine(null, fileName)) + { + f.LoadSubtitle(sub, null, fileName); + format = f; + } + } + if (format == null) + { + var f = new IsmtDfxp(); + if (f.IsMine(null, fileName)) + { + f.LoadSubtitle(sub, null, fileName); + format = f; + } + } var lines = new List(); if (format == null) diff --git a/src/Forms/JoinSubtitles.cs b/src/Forms/JoinSubtitles.cs index 4e21607b3..b4f6793d5 100644 --- a/src/Forms/JoinSubtitles.cs +++ b/src/Forms/JoinSubtitles.cs @@ -116,6 +116,22 @@ namespace Nikse.SubtitleEdit.Forms } } + if (format == null) + { + var encoding = LanguageAutoDetect.GetEncodingFromFile(fileName); + var lines = FileUtil.ReadAllTextShared(fileName, encoding).SplitToLines(); + foreach (var f in SubtitleFormat.GetTextOtherFormats()) + { + if (f.IsMine(lines, fileName)) + { + _fileNamesToJoin.Add(fileName); + f.LoadSubtitle(sub, lines, fileName); + format = f; + break; + } + } + } + if (format == null) { for (int j = k; j < _fileNamesToJoin.Count; j++) diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index dab2b553e..a9144d273 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -17084,7 +17084,7 @@ namespace Nikse.SubtitleEdit.Forms if (format == null) { - var formats = SubtitleFormat.GetBinaryFormats().Union(new SubtitleFormat[] + var formats = SubtitleFormat.GetBinaryFormats().Union(SubtitleFormat.GetTextOtherFormats()).Union(new SubtitleFormat[] { new TimeCodesOnly1(), new TimeCodesOnly2() diff --git a/src/Logic/CommandLineConvert.cs b/src/Logic/CommandLineConvert.cs index 1ad08598f..0a5735982 100644 --- a/src/Logic/CommandLineConvert.cs +++ b/src/Logic/CommandLineConvert.cs @@ -545,179 +545,32 @@ namespace Nikse.SubtitleEdit.Logic format = ebu; } } + if (format == null) { - var pac = new Pac(); - if (pac.IsMine(null, fileName)) + foreach (var f in SubtitleFormat.GetBinaryFormats()) { - pac.BatchMode = true; - pac.CodePage = pacCodePage; - pac.LoadSubtitle(sub, null, fileName); - format = pac; + if (f.IsMine(null, fileName)) + { + f.LoadSubtitle(sub, null, fileName); + format = f; + break; + } } } + if (format == null) { - var cavena890 = new Cavena890(); - if (cavena890.IsMine(null, fileName)) + var encoding = LanguageAutoDetect.GetEncodingFromFile(fileName); + var lines = FileUtil.ReadAllTextShared(fileName, encoding).SplitToLines(); + foreach (var f in SubtitleFormat.GetTextOtherFormats()) { - cavena890.LoadSubtitle(sub, null, fileName); - format = cavena890; - } - } - if (format == null) - { - var spt = new Spt(); - if (spt.IsMine(null, fileName)) - { - spt.LoadSubtitle(sub, null, fileName); - format = spt; - } - } - if (format == null) - { - var cheetahCaption = new CheetahCaption(); - if (cheetahCaption.IsMine(null, fileName)) - { - cheetahCaption.LoadSubtitle(sub, null, fileName); - format = cheetahCaption; - } - } - if (format == null) - { - var chk = new Chk(); - if (chk.IsMine(null, fileName)) - { - chk.LoadSubtitle(sub, null, fileName); - format = chk; - } - } - if (format == null) - { - var ayato = new Ayato(); - if (ayato.IsMine(null, fileName)) - { - ayato.LoadSubtitle(sub, null, fileName); - format = ayato; - } - } - if (format == null) - { - var capMakerPlus = new CapMakerPlus(); - if (capMakerPlus.IsMine(null, fileName)) - { - capMakerPlus.LoadSubtitle(sub, null, fileName); - format = capMakerPlus; - } - } - if (format == null) - { - var captionate = new Captionate(); - if (captionate.IsMine(null, fileName)) - { - captionate.LoadSubtitle(sub, null, fileName); - format = captionate; - } - } - if (format == null) - { - var ultech130 = new Ultech130(); - if (ultech130.IsMine(null, fileName)) - { - ultech130.LoadSubtitle(sub, null, fileName); - format = ultech130; - } - } - if (format == null) - { - var nciCaption = new NciCaption(); - if (nciCaption.IsMine(null, fileName)) - { - nciCaption.LoadSubtitle(sub, null, fileName); - format = nciCaption; - } - } - if (format == null) - { - var tsb4 = new TSB4(); - if (tsb4.IsMine(null, fileName)) - { - tsb4.LoadSubtitle(sub, null, fileName); - format = tsb4; - } - } - if (format == null) - { - var avidStl = new AvidStl(); - if (avidStl.IsMine(null, fileName)) - { - avidStl.LoadSubtitle(sub, null, fileName); - format = avidStl; - } - } - if (format == null) - { - var elr = new ELRStudioClosedCaption(); - if (elr.IsMine(null, fileName)) - { - elr.LoadSubtitle(sub, null, fileName); - format = elr; - } - } - var lines = new List(); - if (format == null) - { - lines = File.ReadAllText(fileName).SplitToLines(); - var timedTextImage = new TimedTextImage(); - if (timedTextImage.IsMine(lines, fileName)) - { - timedTextImage.LoadSubtitle(sub, lines, fileName); - format = timedTextImage; - } - } - if (format == null) - { - var finalCutProImage = new FinalCutProImage(); - if (finalCutProImage.IsMine(lines, fileName)) - { - finalCutProImage.LoadSubtitle(sub, lines, fileName); - format = finalCutProImage; - } - } - if (format == null) - { - var spuImage = new SpuImage(); - if (spuImage.IsMine(lines, fileName)) - { - spuImage.LoadSubtitle(sub, lines, fileName); - format = spuImage; - } - } - if (format == null) - { - var dost = new Dost(); - if (dost.IsMine(lines, fileName)) - { - dost.LoadSubtitle(sub, lines, fileName); - format = dost; - } - } - if (format == null) - { - var seImageHtmlIndex = new SeImageHtmlIndex(); - if (seImageHtmlIndex.IsMine(lines, fileName)) - { - seImageHtmlIndex.LoadSubtitle(sub, lines, fileName); - format = seImageHtmlIndex; - } - } - if (format == null) - { - var bdnXml = new BdnXml(); - if (bdnXml.IsMine(lines, fileName)) - { - bdnXml.LoadSubtitle(sub, lines, fileName); - format = bdnXml; + if (f.IsMine(lines, fileName)) + { + f.LoadSubtitle(sub, lines, fileName); + format = f; + break; + } } }