mirror of https://github.com/jellyfin/jellyfin.git
added json subtitle output
This commit is contained in:
parent
ca66390e24
commit
21d88faa18
|
@ -180,6 +180,10 @@ namespace MediaBrowser.Api.Subtitles
|
||||||
|
|
||||||
public object Get(GetSubtitle request)
|
public object Get(GetSubtitle request)
|
||||||
{
|
{
|
||||||
|
if (string.Equals(request.Format, "js", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
request.Format = "json";
|
||||||
|
}
|
||||||
if (string.IsNullOrEmpty(request.Format))
|
if (string.IsNullOrEmpty(request.Format))
|
||||||
{
|
{
|
||||||
var item = (Video)_libraryManager.GetItemById(new Guid(request.Id));
|
var item = (Video)_libraryManager.GetItemById(new Guid(request.Id));
|
||||||
|
|
|
@ -203,6 +203,10 @@ namespace MediaBrowser.Common.Net
|
||||||
{
|
{
|
||||||
return "application/x-javascript";
|
return "application/x-javascript";
|
||||||
}
|
}
|
||||||
|
if (ext.Equals(".json", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return JsonMimeType;
|
||||||
|
}
|
||||||
if (ext.Equals(".map", StringComparison.OrdinalIgnoreCase))
|
if (ext.Equals(".map", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return "application/x-javascript";
|
return "application/x-javascript";
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Subtitles\ISubtitleParser.cs" />
|
<Compile Include="Subtitles\ISubtitleParser.cs" />
|
||||||
<Compile Include="Subtitles\ISubtitleWriter.cs" />
|
<Compile Include="Subtitles\ISubtitleWriter.cs" />
|
||||||
|
<Compile Include="Subtitles\JsonWriter.cs" />
|
||||||
<Compile Include="Subtitles\SrtParser.cs" />
|
<Compile Include="Subtitles\SrtParser.cs" />
|
||||||
<Compile Include="Subtitles\SrtWriter.cs" />
|
<Compile Include="Subtitles\SrtWriter.cs" />
|
||||||
<Compile Include="Subtitles\AssParser.cs" />
|
<Compile Include="Subtitles\AssParser.cs" />
|
||||||
|
|
|
@ -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.Entities;
|
||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
using MediaBrowser.Model.MediaInfo;
|
using MediaBrowser.Model.MediaInfo;
|
||||||
|
using MediaBrowser.Model.Serialization;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
@ -26,14 +27,16 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
private readonly IMediaEncoder _mediaEncoder;
|
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;
|
_libraryManager = libraryManager;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_appPaths = appPaths;
|
_appPaths = appPaths;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_mediaEncoder = mediaEncoder;
|
_mediaEncoder = mediaEncoder;
|
||||||
|
_json = json;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string SubtitleCachePath
|
private string SubtitleCachePath
|
||||||
|
@ -263,6 +266,10 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||||
throw new ArgumentNullException("format");
|
throw new ArgumentNullException("format");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (string.Equals(format, "json", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return new JsonWriter(_json);
|
||||||
|
}
|
||||||
if (string.Equals(format, SubtitleFormat.SRT, StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(format, SubtitleFormat.SRT, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return new SrtWriter();
|
return new SrtWriter();
|
||||||
|
|
|
@ -54,7 +54,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return (DateTime.UtcNow - Session.LastActivityDate).TotalMinutes <= 10;
|
return (DateTime.UtcNow - Session.LastActivityDate).TotalMinutes <= 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -535,7 +535,7 @@ namespace MediaBrowser.ServerApplication
|
||||||
RegisterSingleInstance<ISessionContext>(new SessionContext(UserManager, authContext, SessionManager));
|
RegisterSingleInstance<ISessionContext>(new SessionContext(UserManager, authContext, SessionManager));
|
||||||
RegisterSingleInstance<IAuthService>(new AuthService(UserManager, SessionManager, authContext, ServerConfigurationManager));
|
RegisterSingleInstance<IAuthService>(new AuthService(UserManager, SessionManager, authContext, ServerConfigurationManager));
|
||||||
|
|
||||||
RegisterSingleInstance<ISubtitleEncoder>(new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder));
|
RegisterSingleInstance<ISubtitleEncoder>(new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer));
|
||||||
|
|
||||||
var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));
|
var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));
|
||||||
var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false));
|
var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false));
|
||||||
|
|
Loading…
Reference in New Issue