mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 06:52:35 +01:00
Add new binary format - thx George :)
This commit is contained in:
parent
1ec58dc2d5
commit
fe1ca00afe
107
libse/SubtitleFormats/PlayCaptionsFreeEditor.cs
Normal file
107
libse/SubtitleFormats/PlayCaptionsFreeEditor.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
public class PlayCaptionsFreeEditor : SubtitleFormat
|
||||
{
|
||||
public override string Extension => ".tmm";
|
||||
public override string Name => "Play Captions FreeEditor";
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
return "Not Implemented";
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName) || Path.GetExtension(fileName).ToLowerInvariant() != Extension)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ReadTimeCodes(subtitle, fileName);
|
||||
var path = Path.GetDirectoryName(fileName);
|
||||
if (path == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var texts = ReadTexts(Path.Combine(path, Path.GetFileNameWithoutExtension(fileName)) + ".rtf");
|
||||
FillTexts(subtitle, texts);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
subtitle.Renumber();
|
||||
}
|
||||
|
||||
private void ReadTimeCodes(Subtitle subtitle, string fileName)
|
||||
{
|
||||
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
var bytes = new byte[26];
|
||||
while (fs.Read(bytes, 0, bytes.Length) == 26)
|
||||
{
|
||||
if (bytes[24] == 13 && bytes[25] == 10)
|
||||
{
|
||||
var startFrames = bytes[0] + bytes[1] * byte.MaxValue + bytes[2] * byte.MaxValue * byte.MaxValue;
|
||||
var endFrames = bytes[4] + bytes[5] * byte.MaxValue + bytes[6] * byte.MaxValue * byte.MaxValue;
|
||||
subtitle.Paragraphs.Add(new Paragraph(string.Empty, FramesToMilliseconds(startFrames), FramesToMilliseconds(endFrames)));
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<string> ReadTexts(string fileName)
|
||||
{
|
||||
var result = new List<string>();
|
||||
if (!File.Exists(fileName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var rtf = FileUtil.ReadAllTextShared(fileName, Encoding.ASCII);
|
||||
return rtf.FromRtf().SplitToLines();
|
||||
}
|
||||
|
||||
private void FillTexts(Subtitle subtitle, List<string> lines)
|
||||
{
|
||||
var counter = 0;
|
||||
var sb = new StringBuilder();
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (string.IsNullOrEmpty(line))
|
||||
{
|
||||
if (sb.Length > 0)
|
||||
{
|
||||
if (counter < subtitle.Paragraphs.Count)
|
||||
{
|
||||
subtitle.Paragraphs[counter].Text = sb.ToString().Trim();
|
||||
counter++;
|
||||
sb.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -70,7 +70,6 @@ TimeCode Format: " + Configuration.Settings.General.CurrentFrameRate + @" frames
|
||||
}
|
||||
|
||||
lines = rtf.FromRtf().SplitToLines();
|
||||
_errorCount = 0;
|
||||
Paragraph p = null;
|
||||
char[] splitChars = { ':', ';', ',' };
|
||||
foreach (string line in lines)
|
||||
|
@ -63,7 +63,6 @@ TimeCode Format: " + Configuration.Settings.General.CurrentFrameRate + @" frames
|
||||
}
|
||||
|
||||
lines = rtf.FromRtf().SplitToLines();
|
||||
_errorCount = 0;
|
||||
Paragraph p = null;
|
||||
char[] splitChars = { ':', ';', ',' };
|
||||
foreach (string line in lines)
|
||||
|
@ -566,10 +566,32 @@ 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 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()
|
||||
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(),
|
||||
new PlayCaptionsFreeEditor(),
|
||||
};
|
||||
}
|
||||
|
||||
@ -577,9 +599,22 @@ 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 Wsb(),
|
||||
new JsonTypeOnlyLoad1(), new TranscriptiveJson(), new KaraokeCdgCreatorText(), new VidIcelandic(),
|
||||
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(),
|
||||
new KaraokeCdgCreatorText(),
|
||||
new VidIcelandic(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1046,6 +1046,12 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
text = text.Replace(" </i>", "</i> ");
|
||||
text = text.Replace(" </b>", "</b> ");
|
||||
text = text.Replace(" </u>", "</u> ");
|
||||
text = text.Replace($" {Environment.NewLine}", Environment.NewLine);
|
||||
text = text.Replace($"</i>{Environment.NewLine}<i>", string.Empty);
|
||||
text = text.Replace($"</b></i>{Environment.NewLine}<i><b>", string.Empty);
|
||||
text = text.Replace($"</u></i>{Environment.NewLine}<i><u>", string.Empty);
|
||||
text = text.Replace($"</u></b>{Environment.NewLine}<b><u>", string.Empty);
|
||||
text = text.Replace($"</u></b></i>{Environment.NewLine}<i><b><u>", string.Empty);
|
||||
return string.Join(Environment.NewLine, text.SplitToLines());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user