mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Added new subtitle format
This commit is contained in:
parent
8ee3387796
commit
954399267c
@ -139,6 +139,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
new YouTubeAnnotations(),
|
||||
new YouTubeSbv(),
|
||||
new YouTubeTranscript(),
|
||||
new YouTubeTranscriptOneLine(),
|
||||
new ZeroG(),
|
||||
|
||||
// new Idx(),
|
||||
|
94
src/Logic/SubtitleFormats/YouTubeTranscriptOneLine.cs
Normal file
94
src/Logic/SubtitleFormats/YouTubeTranscriptOneLine.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
public class YouTubeTranscriptOneLine : SubtitleFormat
|
||||
{
|
||||
static Regex regexTimeCodes = new Regex(@"^\d{1,3}:\d\d.+$", RegexOptions.Compiled);
|
||||
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".txt"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "YouTube Transcript one line"; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
var subtitle = new Subtitle();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
foreach (string line in lines)
|
||||
sb.AppendLine(line);
|
||||
|
||||
LoadSubtitle(subtitle, lines, fileName);
|
||||
return subtitle.Paragraphs.Count > _errorCount;
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
int index = 0;
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
sb.AppendLine(string.Format("{0}{1}", EncodeTimeCode(p.StartTime), Utilities.RemoveHtmlTags(p.Text.Replace(Environment.NewLine, " "))));
|
||||
index++;
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private string EncodeTimeCode(TimeCode time)
|
||||
{
|
||||
return string.Format("{0}:{1:00}", time.Hours * 60 + time.Minutes , time.Seconds);
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
Paragraph p = null;
|
||||
subtitle.Paragraphs.Clear();
|
||||
foreach (string line in lines)
|
||||
{
|
||||
if (regexTimeCodes.IsMatch(line))
|
||||
{
|
||||
int splitter = line.IndexOf(":") + 3;
|
||||
p = new Paragraph(DecodeTimeCode(line.Substring(0, splitter)), new TimeCode(0,0,0,0), line.Remove(0, splitter));
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
foreach (Paragraph p2 in subtitle.Paragraphs)
|
||||
{
|
||||
p2.Text = Utilities.AutoBreakLine(p2.Text);
|
||||
}
|
||||
subtitle.RecalculateDisplayTimes(Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds, null);
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
|
||||
private TimeCode DecodeTimeCode(string s)
|
||||
{
|
||||
string[] parts = s.Split(':');
|
||||
|
||||
string minutes = parts[0];
|
||||
string seconds = parts[1];
|
||||
|
||||
return new TimeCode(0, int.Parse(minutes), int.Parse(seconds), 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1084,6 +1084,7 @@
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle3.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle4.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\YouTubeTranscript.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\YouTubeTranscriptOneLine.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\ZeroG.cs" />
|
||||
<Compile Include="Logic\TarHeader.cs" />
|
||||
<Compile Include="Logic\TarReader.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user