2014-02-04 03:08:20 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-10-25 00:59:34 +00:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Linq;
|
2013-11-29 20:26:24 +00:00
|
|
|
|
using System.Text;
|
2013-10-25 00:59:34 +00:00
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
|
{
|
2013-10-28 01:31:30 +00:00
|
|
|
|
public class SubtitleList : List<Subtitle>
|
2013-10-25 00:59:34 +00:00
|
|
|
|
{
|
2013-10-27 22:13:08 +00:00
|
|
|
|
public IEnumerable<Subtitle> GetSubtitles(int frame)
|
2013-10-25 00:59:34 +00:00
|
|
|
|
{
|
2013-10-28 01:31:30 +00:00
|
|
|
|
return this.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration);
|
2013-10-25 00:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-29 20:26:24 +00:00
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
ForEach(subtitle => sb.AppendLine(subtitle.ToString()));
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-28 01:31:30 +00:00
|
|
|
|
public bool AddFromString(string subtitleStr)
|
2013-10-25 00:59:34 +00:00
|
|
|
|
{
|
2014-02-04 03:08:20 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(subtitleStr))
|
2013-10-25 00:59:34 +00:00
|
|
|
|
{
|
2013-10-27 22:13:08 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var subparts = subtitleStr.Split(' ');
|
2013-10-25 00:59:34 +00:00
|
|
|
|
|
2013-11-29 19:55:05 +00:00
|
|
|
|
// Unfortunately I made the file format space delminated so this hack is necessary to get the message
|
2014-02-04 03:08:20 +00:00
|
|
|
|
var message = string.Empty;
|
2013-11-29 19:55:05 +00:00
|
|
|
|
for (var i = 6; i < subparts.Length; i++)
|
2013-10-27 22:13:08 +00:00
|
|
|
|
{
|
|
|
|
|
message += subparts[i] + ' ';
|
|
|
|
|
}
|
2013-10-25 00:59:34 +00:00
|
|
|
|
|
2013-11-29 19:55:05 +00:00
|
|
|
|
Add(new Subtitle
|
2013-10-27 22:13:08 +00:00
|
|
|
|
{
|
|
|
|
|
Frame = int.Parse(subparts[1]),
|
|
|
|
|
X = int.Parse(subparts[2]),
|
|
|
|
|
Y = int.Parse(subparts[3]),
|
|
|
|
|
Duration = int.Parse(subparts[4]),
|
|
|
|
|
Color = uint.Parse(subparts[5], NumberStyles.HexNumber),
|
|
|
|
|
Message = message
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-10-25 00:59:34 +00:00
|
|
|
|
}
|
2014-02-04 03:08:20 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
2013-10-25 00:59:34 +00:00
|
|
|
|
}
|
2014-08-17 11:36:37 +00:00
|
|
|
|
|
|
|
|
|
public string ToSubRip(double fps)
|
|
|
|
|
{
|
|
|
|
|
int index = 1;
|
|
|
|
|
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
foreach (var subtitle in this)
|
|
|
|
|
sb.Append(subtitle.ToSubRip(index++, fps));
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
2013-10-25 00:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|