mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-15 23:02:18 +01:00
added json subtitle output
This commit is contained in:
@@ -61,6 +61,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Subtitles\ISubtitleParser.cs" />
|
||||
<Compile Include="Subtitles\ISubtitleWriter.cs" />
|
||||
<Compile Include="Subtitles\JsonWriter.cs" />
|
||||
<Compile Include="Subtitles\SrtParser.cs" />
|
||||
<Compile Include="Subtitles\SrtWriter.cs" />
|
||||
<Compile Include="Subtitles\AssParser.cs" />
|
||||
|
||||
27
MediaBrowser.MediaEncoding/Subtitles/JsonWriter.cs
Normal file
27
MediaBrowser.MediaEncoding/Subtitles/JsonWriter.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
{
|
||||
public class JsonWriter : ISubtitleWriter
|
||||
{
|
||||
private readonly IJsonSerializer _json;
|
||||
|
||||
public JsonWriter(IJsonSerializer json)
|
||||
{
|
||||
_json = json;
|
||||
}
|
||||
|
||||
public void Write(SubtitleTrackInfo info, Stream stream, CancellationToken cancellationToken)
|
||||
{
|
||||
using (var writer = new StreamWriter(stream, Encoding.UTF8, 1024, true))
|
||||
{
|
||||
var json = _json.SerializeToString(info);
|
||||
|
||||
writer.Write(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
@@ -26,14 +27,16 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
private readonly IApplicationPaths _appPaths;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly IMediaEncoder _mediaEncoder;
|
||||
private readonly IJsonSerializer _json;
|
||||
|
||||
public SubtitleEncoder(ILibraryManager libraryManager, ILogger logger, IApplicationPaths appPaths, IFileSystem fileSystem, IMediaEncoder mediaEncoder)
|
||||
public SubtitleEncoder(ILibraryManager libraryManager, ILogger logger, IApplicationPaths appPaths, IFileSystem fileSystem, IMediaEncoder mediaEncoder, IJsonSerializer json)
|
||||
{
|
||||
_libraryManager = libraryManager;
|
||||
_logger = logger;
|
||||
_appPaths = appPaths;
|
||||
_fileSystem = fileSystem;
|
||||
_mediaEncoder = mediaEncoder;
|
||||
_json = json;
|
||||
}
|
||||
|
||||
private string SubtitleCachePath
|
||||
@@ -263,6 +266,10 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
throw new ArgumentNullException("format");
|
||||
}
|
||||
|
||||
if (string.Equals(format, "json", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new JsonWriter(_json);
|
||||
}
|
||||
if (string.Equals(format, SubtitleFormat.SRT, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new SrtWriter();
|
||||
|
||||
Reference in New Issue
Block a user