From ae22d0b7a530c1ae3188c2ec32bd03dc840c1762 Mon Sep 17 00:00:00 2001 From: nyanmisaka Date: Sat, 18 Jun 2022 00:25:55 +0800 Subject: [PATCH 1/2] Fix output extension if user has no transcoding permission --- Jellyfin.Api/Helpers/StreamingHelpers.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Jellyfin.Api/Helpers/StreamingHelpers.cs b/Jellyfin.Api/Helpers/StreamingHelpers.cs index 34dab75b82..54234c56a3 100644 --- a/Jellyfin.Api/Helpers/StreamingHelpers.cs +++ b/Jellyfin.Api/Helpers/StreamingHelpers.cs @@ -179,7 +179,7 @@ namespace Jellyfin.Api.Helpers { containerInternal = streamingRequest.Static ? StreamBuilder.NormalizeMediaSourceFormatIntoSingleContainer(state.InputContainer, null, DlnaProfileType.Audio) - : GetOutputFileExtension(state); + : GetOutputFileExtension(state, mediaSource); } state.OutputContainer = (containerInternal ?? string.Empty).TrimStart('.'); @@ -235,7 +235,7 @@ namespace Jellyfin.Api.Helpers ApplyDeviceProfileSettings(state, dlnaManager, deviceManager, httpRequest, streamingRequest.DeviceProfileId, streamingRequest.Static); var ext = string.IsNullOrWhiteSpace(state.OutputContainer) - ? GetOutputFileExtension(state) + ? GetOutputFileExtension(state, mediaSource) : ("." + state.OutputContainer); state.OutputFilePath = GetOutputFilePath(state, ext!, serverConfigurationManager, streamingRequest.DeviceId, streamingRequest.PlaySessionId); @@ -409,8 +409,9 @@ namespace Jellyfin.Api.Helpers /// Gets the output file extension. /// /// The state. + /// The mediaSource. /// System.String. - private static string? GetOutputFileExtension(StreamState state) + private static string? GetOutputFileExtension(StreamState state, MediaSourceInfo? mediaSource) { var ext = Path.GetExtension(state.RequestedUrl); @@ -425,7 +426,7 @@ namespace Jellyfin.Api.Helpers var videoCodec = state.Request.VideoCodec; if (string.Equals(videoCodec, "h264", StringComparison.OrdinalIgnoreCase) || - string.Equals(videoCodec, "h265", StringComparison.OrdinalIgnoreCase)) + string.Equals(videoCodec, "hevc", StringComparison.OrdinalIgnoreCase)) { return ".ts"; } @@ -474,6 +475,17 @@ namespace Jellyfin.Api.Helpers } } + // Fallback to the container of mediaSource + if (mediaSource != null && !string.IsNullOrEmpty(mediaSource.Container)) + { + var containers = mediaSource.Container.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + + if (containers.Length > 0) + { + return '.' + containers[0]; + } + } + return null; } From 56e135f5e664835a89e52d0ced91b9009b390818 Mon Sep 17 00:00:00 2001 From: nyanmisaka Date: Sat, 18 Jun 2022 01:50:08 +0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Claus Vium --- Jellyfin.Api/Helpers/StreamingHelpers.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Jellyfin.Api/Helpers/StreamingHelpers.cs b/Jellyfin.Api/Helpers/StreamingHelpers.cs index 54234c56a3..87544b3e3e 100644 --- a/Jellyfin.Api/Helpers/StreamingHelpers.cs +++ b/Jellyfin.Api/Helpers/StreamingHelpers.cs @@ -476,14 +476,10 @@ namespace Jellyfin.Api.Helpers } // Fallback to the container of mediaSource - if (mediaSource != null && !string.IsNullOrEmpty(mediaSource.Container)) + if (!string.IsNullOrEmpty(mediaSource?.Container)) { - var containers = mediaSource.Container.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); - - if (containers.Length > 0) - { - return '.' + containers[0]; - } + var idx = mediaSource.Container.IndexOf(',', StringComparison.OrdinalIgnoreCase); + return '.' + (idx == -1 ? mediaSource.Container : mediaSource.Container[..idx]).Trim(); } return null;