From 2363ad544979adf32207fa927f106fadb784f1fb Mon Sep 17 00:00:00 2001
From: redSpoutnik <15638041+redSpoutnik@users.noreply.github.com>
Date: Fri, 8 May 2020 21:53:38 +0200
Subject: [PATCH 001/103] Add Post subtitle in API
---
MediaBrowser.Api/Subtitles/SubtitleService.cs | 55 +++++++++++++++
.../Subtitles/ISubtitleManager.cs | 6 ++
.../Subtitles/SubtitleManager.cs | 70 ++++++++++++-------
3 files changed, 104 insertions(+), 27 deletions(-)
diff --git a/MediaBrowser.Api/Subtitles/SubtitleService.cs b/MediaBrowser.Api/Subtitles/SubtitleService.cs
index f2968c6b5..ed2533f6d 100644
--- a/MediaBrowser.Api/Subtitles/SubtitleService.cs
+++ b/MediaBrowser.Api/Subtitles/SubtitleService.cs
@@ -37,6 +37,31 @@ namespace MediaBrowser.Api.Subtitles
public int Index { get; set; }
}
+ [Route("/Videos/{Id}/Subtitles", "POST", Summary = "Upload an external subtitle file")]
+ [Authenticated(Roles = "admin")]
+ public class PostSubtitle : IReturnVoid
+ {
+ ///
+ /// Gets or sets the id.
+ ///
+ /// The id.
+ [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
+ public string Id { get; set; }
+
+ [ApiMember(Name = "Language", Description = "Language", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
+ public string Language { get; set; }
+
+ [ApiMember(Name = "Format", Description = "Format", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
+ public string Format { get; set; }
+
+ [ApiMember(Name = "IsForced", Description = "IsForced", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
+ public string IsForced { get; set; }
+
+ [ApiMember(Name = "Data", Description = "Data", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
+ public string Data { get; set; }
+
+ }
+
[Route("/Items/{Id}/RemoteSearch/Subtitles/{Language}", "GET")]
[Authenticated]
public class SearchRemoteSubtitles : IReturn
@@ -270,6 +295,36 @@ namespace MediaBrowser.Api.Subtitles
return _subtitleManager.DeleteSubtitles(item, request.Index);
}
+ public void Post(PostSubtitle request)
+ {
+ var video = (Video)_libraryManager.GetItemById(request.Id);
+
+ var bytes = Convert.FromBase64String(request.Data);
+ var memoryStream = new MemoryStream(bytes)
+ {
+ Position = 0
+ };
+
+ Task.Run(async () =>
+ {
+ try
+ {
+ await _subtitleManager.UploadSubtitle(video, new SubtitleResponse {
+ Format = request.Format,
+ Language = request.Language,
+ IsForced = Convert.ToBoolean(request.IsForced),
+ Stream = memoryStream
+ }).ConfigureAwait(false);
+
+ _providerManager.QueueRefresh(video.Id, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), RefreshPriority.High);
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex, "Error uploading subtitle");
+ }
+ });
+ }
+
public async Task