From 73fe9d3f696e5d144047e173553b1d1dba03c5d1 Mon Sep 17 00:00:00 2001 From: crobibero Date: Thu, 25 Mar 2021 18:06:25 -0600 Subject: [PATCH] Allow subtitle format to be set from query parameter. --- Jellyfin.Api/Controllers/SubtitleController.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Jellyfin.Api/Controllers/SubtitleController.cs b/Jellyfin.Api/Controllers/SubtitleController.cs index 16a47f2d8..e260efc9a 100644 --- a/Jellyfin.Api/Controllers/SubtitleController.cs +++ b/Jellyfin.Api/Controllers/SubtitleController.cs @@ -185,6 +185,7 @@ namespace Jellyfin.Api.Controllers /// The item id. /// The media source id. /// The subtitle stream index. + /// The (route) format of the returned subtitle. /// The format of the returned subtitle. /// Optional. The end position of the subtitle in ticks. /// Optional. Whether to copy the timestamps. @@ -192,19 +193,25 @@ namespace Jellyfin.Api.Controllers /// Optional. The start position of the subtitle in ticks. /// File returned. /// A with the subtitle file. - [HttpGet("Videos/{itemId}/{mediaSourceId}/Subtitles/{index}/Stream.{format}")] + [HttpGet("Videos/{itemId}/{mediaSourceId}/Subtitles/{index}/Stream.{routeFormat}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesFile("text/*")] public async Task GetSubtitle( [FromRoute, Required] Guid itemId, [FromRoute, Required] string mediaSourceId, [FromRoute, Required] int index, - [FromRoute, Required] string format, + [FromRoute, Required] string routeFormat, + [FromQuery] string? format, [FromQuery] long? endPositionTicks, [FromQuery] bool copyTimestamps = false, [FromQuery] bool addVttTimeMap = false, [FromQuery] long startPositionTicks = 0) { + if (string.IsNullOrEmpty(format)) + { + format = routeFormat; + } + if (string.Equals(format, "js", StringComparison.OrdinalIgnoreCase)) { format = "json"; @@ -255,13 +262,14 @@ namespace Jellyfin.Api.Controllers /// The media source id. /// The subtitle stream index. /// Optional. The start position of the subtitle in ticks. + /// The (route) format of the returned subtitle. /// The format of the returned subtitle. /// Optional. The end position of the subtitle in ticks. /// Optional. Whether to copy the timestamps. /// Optional. Whether to add a VTT time map. /// File returned. /// A with the subtitle file. - [HttpGet("Videos/{itemId}/{mediaSourceId}/Subtitles/{index}/{startPositionTicks}/Stream.{format}")] + [HttpGet("Videos/{itemId}/{mediaSourceId}/Subtitles/{index}/{startPositionTicks}/Stream.{routeFormat}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesFile("text/*")] public Task GetSubtitleWithTicks( @@ -269,7 +277,8 @@ namespace Jellyfin.Api.Controllers [FromRoute, Required] string mediaSourceId, [FromRoute, Required] int index, [FromRoute, Required] long startPositionTicks, - [FromRoute, Required] string format, + [FromRoute, Required] string routeFormat, + [FromQuery] string? format, [FromQuery] long? endPositionTicks, [FromQuery] bool copyTimestamps = false, [FromQuery] bool addVttTimeMap = false) @@ -278,6 +287,7 @@ namespace Jellyfin.Api.Controllers itemId, mediaSourceId, index, + routeFormat, format, endPositionTicks, copyTimestamps,