SubtitleEdit/libse/SubtitleFormats/SamiAvDicPlayer.cs
2016-06-09 14:36:09 +00:00

54 lines
1.7 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class SamiAvDicPlayer : Sami
{
private static readonly Regex RegexAvDicPlayer = new Regex(@"<AVDicPlayer[^\s]*", RegexOptions.Compiled); //AVDicPlayer_TEDSYNⓒ_VER1.1
public override string Name
{
get { return "SAMI AVDicPlayer"; }
}
public override bool IsMine(List<string> lines, string fileName)
{
var text = GetSamiFromAvDicPlayerText(lines);
var subtitle = new Subtitle();
base.LoadSubtitle(subtitle, text.SplitToLines().ToList(), fileName);
return subtitle.Paragraphs.Count > _errorCount;
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
var text = GetSamiFromAvDicPlayerText(lines);
base.LoadSubtitle(subtitle, text.SplitToLines().ToList(), fileName);
}
public override string ToText(Subtitle subtitle, string title)
{
var text = base.ToText(subtitle, title);
return text.Replace("<SYNC", "<AVDicPlayer_TEDSYNⓒ_VER1.1");
}
private static string GetSamiFromAvDicPlayerText(List<string> lines)
{
var sb = new StringBuilder();
foreach (var line in lines)
{
sb.AppendLine(line);
}
var text = sb.ToString();
if (text.Contains("<AVDicPlayer"))
{
text = RegexAvDicPlayer.Replace(text, "<SYNC");
}
return text;
}
}
}