More subtitle format refactor

This commit is contained in:
niksedk 2019-03-17 15:34:44 +01:00
parent 2fc8abcc75
commit 59978497b0
4 changed files with 53 additions and 459 deletions

View File

@ -20,8 +20,15 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
if (!string.IsNullOrEmpty(fileName) && fileName.EndsWith(".cmft", StringComparison.OrdinalIgnoreCase))
{
var parser = new CmafParser(fileName);
return parser.Subtitle.Paragraphs.Count > 0;
try
{
var parser = new CmafParser(fileName);
return parser.Subtitle.Paragraphs.Count > 0;
}
catch
{
return false;
}
}
return false;
}

View File

@ -507,10 +507,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
return new SubtitleFormat[]
{
new Ebu() { BatchMode = batchMode }, new Pac() { BatchMode = batchMode }, new PacUnicode(), new Cavena890() { BatchMode = batchMode },
new Spt(), new CheetahCaption(), new TSB4(), new Chk(), new Ayato(), new CapMakerPlus(), new Ultech130(), new NciCaption(),
new AvidStl(), new WinCaps32(), new IsmtDfxp(), new Cavena890(), new Spt(), new Sptx(), new IaiSub(),
new ELRStudioClosedCaption(), new CaptionsInc()
new Ebu { BatchMode = batchMode }, new Pac { BatchMode = batchMode }, new PacUnicode(), new Cavena890 { BatchMode = batchMode },
new Spt(), new CheetahCaption(), new CheetahCaptionOld(), new TSB4(), new Chk(), new Ayato(), new CapMakerPlus(), new Ultech130(),
new NciCaption(), new AvidStl(), new WinCaps32(), new IsmtDfxp(), new Cavena890(), new Spt(), new Sptx(), new IaiSub(),
new ELRStudioClosedCaption(), new CaptionsInc(), new TimeLineMvt(), new Cmaft(), new Pns()
};
}
@ -518,9 +518,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
return new SubtitleFormat[]
{
new DlDd(),new Ted20(), new Captionate(),
new TimeLineAscii(), new TimeLineFootageAscii(), new TimedTextImage(), new FinalCutProImage(),
new SpuImage(), new Dost(), new SeImageHtmlIndex(), new BdnXml()
new DlDd(), new Ted20(), new Captionate(), new TimeLineAscii(), new TimeLineFootageAscii(), new TimedTextImage(),
new FinalCutProImage(), new SpuImage(), new Dost(), new SeImageHtmlIndex(), new BdnXml(), new Wsb(),
new JsonTypeOnlyLoad1(), new TranscriptiveJson()
};
}
}

View File

@ -10,6 +10,15 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override string Name => "WSB";
public override bool IsMine(List<string> lines, string fileName)
{
if (fileName != null && !fileName.EndsWith(Extension, StringComparison.OrdinalIgnoreCase))
{
return false;
}
return base.IsMine(lines, fileName);
}
public override string ToText(Subtitle subtitle, string title)
{
var sb = new StringBuilder();

View File

@ -2339,35 +2339,6 @@ namespace Nikse.SubtitleEdit.Forms
ShowHideTextBasedFeatures(format);
bool justConverted = false;
if (format == null)
{
var ebu = new Ebu();
if (ebu.IsMine(null, fileName))
{
ebu.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = ebu;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var pac = new Pac();
if (pac.IsMine(null, fileName))
{
pac.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = pac;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (ext == ".m2ts" || ext == ".textst")
{
@ -2384,293 +2355,6 @@ namespace Nikse.SubtitleEdit.Forms
}
}
if (format == null)
{
var pns = new Pns();
if (pns.IsMine(null, fileName))
{
pns.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = pns;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var cavena890 = new Cavena890();
if (cavena890.IsMine(null, fileName))
{
cavena890.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = cavena890;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var spt = new Spt();
if (spt.IsMine(null, fileName))
{
spt.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = spt;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var sptx = new Sptx();
if (sptx.IsMine(null, fileName))
{
sptx.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = sptx;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null && ext == ".wsb")
{
var wsb = new Wsb();
var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
if (wsb.IsMine(list, fileName))
{
wsb.LoadSubtitle(_subtitle, list, fileName);
_oldSubtitleFormat = wsb;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var cheetahCaption = new CheetahCaption();
if (cheetahCaption.IsMine(null, fileName))
{
cheetahCaption.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = cheetahCaption;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var cheetahCaption = new CheetahCaptionOld();
if (cheetahCaption.IsMine(null, fileName))
{
cheetahCaption.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = cheetahCaption;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var capMakerPlus = new CapMakerPlus();
if (capMakerPlus.IsMine(null, fileName))
{
capMakerPlus.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = capMakerPlus;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var captionsInc = new CaptionsInc();
if (captionsInc.IsMine(null, fileName))
{
captionsInc.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = captionsInc;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var ultech130 = new Ultech130();
if (ultech130.IsMine(null, fileName))
{
ultech130.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = ultech130;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var nciCaption = new NciCaption();
if (nciCaption.IsMine(null, fileName))
{
nciCaption.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = nciCaption;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var tsb4 = new TSB4();
if (tsb4.IsMine(null, fileName))
{
tsb4.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = tsb4;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var avidStl = new AvidStl();
if (avidStl.IsMine(null, fileName))
{
avidStl.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = avidStl;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var chk = new Chk();
if (chk.IsMine(null, fileName))
{
chk.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = chk;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var ayato = new Ayato();
if (ayato.IsMine(null, fileName))
{
ayato.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = ayato;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var pacUnicode = new PacUnicode();
if (pacUnicode.IsMine(null, fileName))
{
pacUnicode.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = pacUnicode;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var iai = new IaiSub();
if (iai.IsMine(null, fileName))
{
iai.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = iai;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var f = new DlDd();
var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
if (f.IsMine(list, fileName))
{
f.LoadSubtitle(_subtitle, list, fileName);
_oldSubtitleFormat = f;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var f = new Ted20();
if (f.IsMine(null, fileName))
{
f.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = f;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var f = new TimeCodesOnly1();
@ -2703,38 +2387,6 @@ namespace Nikse.SubtitleEdit.Forms
}
}
if (format == null)
{
var f = new JsonTypeOnlyLoad1();
var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
if (f.IsMine(list, fileName))
{
f.LoadSubtitle(_subtitle, list, fileName);
_oldSubtitleFormat = f;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var f = new TranscriptiveJson();
var list = new List<string>(File.ReadAllLines(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)));
if (f.IsMine(list, fileName))
{
f.LoadSubtitle(_subtitle, list, fileName);
_oldSubtitleFormat = f;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
try
@ -2823,66 +2475,6 @@ namespace Nikse.SubtitleEdit.Forms
}
}
if (format == null)
{
var elr = new ELRStudioClosedCaption();
if (elr.IsMine(null, fileName))
{
elr.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = elr;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var asc = new TimeLineAscii();
if (asc.IsMine(null, fileName))
{
asc.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = asc;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var asc = new TimeLineFootageAscii();
if (asc.IsMine(null, fileName))
{
asc.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = asc;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var mtv = new TimeLineMvt();
if (mtv.IsMine(null, fileName))
{
mtv.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = mtv;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
if (format == null)
{
var arib = new AribB36();
@ -2964,27 +2556,6 @@ namespace Nikse.SubtitleEdit.Forms
}
}
if (format == null)
{
try
{
var cmaf = new Cmaft();
if (cmaf.IsMine(null, fileName))
{
cmaf.LoadSubtitle(_subtitle, null, fileName);
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
}
}
catch
{
// ignore
}
}
if (format == null || format.Name == Scenarist.NameOfFormat)
{
try
@ -3104,31 +2675,38 @@ namespace Nikse.SubtitleEdit.Forms
if (format == null)
{
var f = new WinCaps32();
if (f.IsMine(null, fileName))
foreach (var f in SubtitleFormat.GetBinaryFormats(false))
{
f.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = f;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
if (f.IsMine(null, fileName))
{
f.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = f;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
break;
}
}
}
if (format == null)
{
var f = new IsmtDfxp();
if (f.IsMine(null, fileName))
var lines = FileUtil.ReadAllTextShared(fileName, LanguageAutoDetect.GetEncodingFromFile(fileName)).SplitToLines();
foreach (var f in SubtitleFormat.GetTextOtherFormats())
{
f.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = f;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
if (f.IsMine(lines, fileName))
{
f.LoadSubtitle(_subtitle, null, fileName);
_oldSubtitleFormat = f;
SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
SetEncoding(Configuration.Settings.General.DefaultEncoding);
encoding = GetCurrentEncoding();
justConverted = true;
format = GetCurrentSubtitleFormat();
break;
}
}
}