Explorar o código

Allow subtitle format to be set from query parameter.

crobibero %!s(int64=4) %!d(string=hai) anos
pai
achega
73fe9d3f69
Modificáronse 1 ficheiros con 14 adicións e 4 borrados
  1. 14 4
      Jellyfin.Api/Controllers/SubtitleController.cs

+ 14 - 4
Jellyfin.Api/Controllers/SubtitleController.cs

@@ -185,6 +185,7 @@ namespace Jellyfin.Api.Controllers
         /// <param name="itemId">The item id.</param>
         /// <param name="mediaSourceId">The media source id.</param>
         /// <param name="index">The subtitle stream index.</param>
+        /// <param name="routeFormat">The (route) format of the returned subtitle.</param>
         /// <param name="format">The format of the returned subtitle.</param>
         /// <param name="endPositionTicks">Optional. The end position of the subtitle in ticks.</param>
         /// <param name="copyTimestamps">Optional. Whether to copy the timestamps.</param>
@@ -192,19 +193,25 @@ namespace Jellyfin.Api.Controllers
         /// <param name="startPositionTicks">Optional. The start position of the subtitle in ticks.</param>
         /// <response code="200">File returned.</response>
         /// <returns>A <see cref="FileContentResult"/> with the subtitle file.</returns>
-        [HttpGet("Videos/{itemId}/{mediaSourceId}/Subtitles/{index}/Stream.{format}")]
+        [HttpGet("Videos/{itemId}/{mediaSourceId}/Subtitles/{index}/Stream.{routeFormat}")]
         [ProducesResponseType(StatusCodes.Status200OK)]
         [ProducesFile("text/*")]
         public async Task<ActionResult> 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
         /// <param name="mediaSourceId">The media source id.</param>
         /// <param name="index">The subtitle stream index.</param>
         /// <param name="startPositionTicks">Optional. The start position of the subtitle in ticks.</param>
+        /// <param name="routeFormat">The (route) format of the returned subtitle.</param>
         /// <param name="format">The format of the returned subtitle.</param>
         /// <param name="endPositionTicks">Optional. The end position of the subtitle in ticks.</param>
         /// <param name="copyTimestamps">Optional. Whether to copy the timestamps.</param>
         /// <param name="addVttTimeMap">Optional. Whether to add a VTT time map.</param>
         /// <response code="200">File returned.</response>
         /// <returns>A <see cref="FileContentResult"/> with the subtitle file.</returns>
-        [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<ActionResult> 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,