2019-01-13 15:02:23 -05:00
|
|
|
using System.IO;
|
2019-10-26 16:53:53 -04:00
|
|
|
using System.Text.Json;
|
2018-12-14 04:40:55 -05:00
|
|
|
using System.Threading;
|
2019-01-13 14:26:04 -05:00
|
|
|
using MediaBrowser.Model.MediaInfo;
|
2018-12-14 04:40:55 -05:00
|
|
|
|
|
|
|
namespace MediaBrowser.MediaEncoding.Subtitles
|
|
|
|
{
|
2019-10-26 16:53:53 -04:00
|
|
|
/// <summary>
|
|
|
|
/// JSON subtitle writer.
|
|
|
|
/// </summary>
|
2018-12-14 04:40:55 -05:00
|
|
|
public class JsonWriter : ISubtitleWriter
|
|
|
|
{
|
2019-10-26 16:53:53 -04:00
|
|
|
/// <inheritdoc />
|
2018-12-14 04:40:55 -05:00
|
|
|
public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken)
|
|
|
|
{
|
2019-10-26 16:53:53 -04:00
|
|
|
using (var writer = new Utf8JsonWriter(stream))
|
2018-12-14 04:40:55 -05:00
|
|
|
{
|
2019-10-26 16:53:53 -04:00
|
|
|
var trackevents = info.TrackEvents;
|
|
|
|
writer.WriteStartArray("TrackEvents");
|
|
|
|
|
|
|
|
for (int i = 0; i < trackevents.Count; i++)
|
|
|
|
{
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
var current = trackevents[i];
|
|
|
|
writer.WriteStartObject();
|
|
|
|
|
|
|
|
writer.WriteString("Id", current.Id);
|
|
|
|
writer.WriteString("Text", current.Text);
|
|
|
|
writer.WriteNumber("StartPositionTicks", current.StartPositionTicks);
|
|
|
|
writer.WriteNumber("EndPositionTicks", current.EndPositionTicks);
|
|
|
|
|
|
|
|
writer.WriteEndObject();
|
|
|
|
}
|
2018-12-14 04:40:55 -05:00
|
|
|
|
2019-10-26 16:53:53 -04:00
|
|
|
writer.WriteEndObject();
|
2018-12-14 04:40:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|