mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 06:52:35 +01:00
Added new subtitle format
This commit is contained in:
parent
8b257c88be
commit
9a2fca09eb
@ -2642,6 +2642,30 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
}
|
||||
}
|
||||
|
||||
if (format == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var satBoxPng = new SatBoxPng();
|
||||
string[] arr = File.ReadAllLines(fileName, Utilities.GetEncodingFromFile(fileName));
|
||||
var list = new List<string>();
|
||||
foreach (string l in arr)
|
||||
list.Add(l);
|
||||
if (satBoxPng.IsMine(list, fileName))
|
||||
{
|
||||
var subtitle = new Subtitle();
|
||||
satBoxPng.LoadSubtitle(subtitle, list, fileName);
|
||||
if (ContinueNewOrExit())
|
||||
ImportAndOcrSrt(fileName, subtitle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
format = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (format == null || format.Name == new Scenarist().Name)
|
||||
{
|
||||
try
|
||||
|
102
src/Logic/SubtitleFormats/SatBoxPng.cs
Normal file
102
src/Logic/SubtitleFormats/SatBoxPng.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
/// <summary>
|
||||
/// http://forum.videohelp.com/threads/365786-Converting-Subtitles-%28XML-PNG%29-to-idx-sub
|
||||
/// </summary>
|
||||
public class SatBoxPng : SubtitleFormat
|
||||
{
|
||||
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".txt"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "SatBox png"; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
var subtitle = new Subtitle();
|
||||
LoadSubtitle(subtitle, lines, fileName);
|
||||
return subtitle.Paragraphs.Count > _errorCount;
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
return "Not implemented";
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
//<I s="0.600" e="3.720" x="268" y="458" w="218" h="58" i="AYZ1.png" />
|
||||
Paragraph p = null;
|
||||
subtitle.Paragraphs.Clear();
|
||||
_errorCount = 0;
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
return;
|
||||
string path = System.IO.Path.GetDirectoryName(fileName);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string s = line;
|
||||
if (line.Contains(" s=\"") && line.Contains(" e=\"") && line.Contains(" i=\"") && line.Contains(".png") && (line.Contains("<I ") || line.Contains("<I ")))
|
||||
{
|
||||
string start = GetTagValue("s", line);
|
||||
string end = GetTagValue("e", line);
|
||||
string text = GetTagValue("i", line);
|
||||
try
|
||||
{
|
||||
if (File.Exists(Path.Combine(path, text)))
|
||||
text = Path.Combine(path, text);
|
||||
p = new Paragraph(DecodeTimeCode(start), DecodeTimeCode(end), text);
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_errorCount++;
|
||||
System.Diagnostics.Debug.WriteLine(exception.Message);
|
||||
}
|
||||
}
|
||||
else if (line.Trim().Length > 0 && p != null)
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
|
||||
private string GetTagValue(string tag, string line)
|
||||
{
|
||||
int start = line.IndexOf(tag + "=\"");
|
||||
if (start > 0 && line.Length > start + 4)
|
||||
{
|
||||
int end = line.IndexOf("\"", start + 3);
|
||||
if (end > 0 && line.Length > end + 3)
|
||||
{
|
||||
string value = line.Substring(start + 3, end - start - 3);
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private TimeCode DecodeTimeCode(string s)
|
||||
{
|
||||
return TimeCode.FromSeconds(double.Parse(s, CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -875,6 +875,7 @@
|
||||
<Compile Include="Logic\StripableText.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\AdobeAfterEffectsFTME.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\AdobeEncore.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\SatBoxPng.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle73.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\AdobeEncoreLineTabNewLine.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\AdobeEncoreLineTabs.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user