Refactor sub loading (in batch convert/cmd line convert)

This commit is contained in:
niksedk 2019-03-17 10:22:06 +01:00
parent 5349866da5
commit 4354d7d92b
5 changed files with 110 additions and 489 deletions

View File

@ -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;
}

View File

@ -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,202 +322,30 @@ namespace Nikse.SubtitleEdit.Forms
if (format == null)
{
var ebu = new Ebu();
if (ebu.IsMine(null, fileName))
foreach (var f in _formatsBinary)
{
format = ebu;
}
}
if (format == null)
{
var pac = new Pac();
if (pac.IsMine(null, fileName))
{
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))
{
f.LoadSubtitle(sub, null, fileName);
format = f;
break;
}
}
}
if (format == null)
{
var f = new IaiSub();
if (f.IsMine(null, fileName))
var encoding = LanguageAutoDetect.GetEncodingFromFile(fileName);
var lines = FileUtil.ReadAllTextShared(fileName, encoding).SplitToLines();
foreach (var f in _formatsOtherText)
{
if (f.IsMine(lines, fileName))
{
f.LoadSubtitle(sub, lines, fileName);
format = f;
break;
}
}
var lines = new List<string>();
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;
}
}
}
}
@ -778,143 +611,33 @@ 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 (f.IsMine(lines, fileName))
{
f.LoadSubtitle(sub, lines, fileName);
format = f;
break;
}
}
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<string>();
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 (format == null)
@ -1885,6 +1608,9 @@ namespace Nikse.SubtitleEdit.Forms
{
var sub = new Subtitle();
var format = sub.LoadSubtitle(fileName, out _, null);
var formats = new List<SubtitleFormat> { };
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<string>();
if (format == null)

View File

@ -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++)

View File

@ -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()

View File

@ -545,180 +545,33 @@ 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 (f.IsMine(lines, fileName))
{
f.LoadSubtitle(sub, lines, fileName);
format = f;
break;
}
}
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<string>();
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 (format != null && IsImageBased(format))