aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2023-10-11 23:05:28 +0200
committerGitHub <noreply@github.com>2023-10-11 23:05:28 +0200
commit456d9dc0a62b6011b884f660ae641a942e27149b (patch)
treea2d52f6add9c5745ee29f1884e245dd483ce8df9
parentc02f2d4791be47e2075cf864c14288d5df3cff79 (diff)
parent35d63ec540ced98e9f1eebf9a786714abc9ec82e (diff)
StreamingHelpers.GetOutputFileExtension should never return null (#10387)
-rw-r--r--Jellyfin.Api/Helpers/StreamingHelpers.cs20
1 files changed, 9 insertions, 11 deletions
diff --git a/Jellyfin.Api/Helpers/StreamingHelpers.cs b/Jellyfin.Api/Helpers/StreamingHelpers.cs
index a653c5795..11f6bcf6b 100644
--- a/Jellyfin.Api/Helpers/StreamingHelpers.cs
+++ b/Jellyfin.Api/Helpers/StreamingHelpers.cs
@@ -421,13 +421,12 @@ public static class StreamingHelpers
/// <param name="state">The state.</param>
/// <param name="mediaSource">The mediaSource.</param>
/// <returns>System.String.</returns>
- private static string? GetOutputFileExtension(StreamState state, MediaSourceInfo? mediaSource)
+ private static string GetOutputFileExtension(StreamState state, MediaSourceInfo? mediaSource)
{
- var ext = Path.GetExtension(state.RequestedUrl.AsSpan());
-
- if (ext.IsEmpty)
+ var ext = Path.GetExtension(state.RequestedUrl);
+ if (!string.IsNullOrEmpty(ext))
{
- return null;
+ return ext;
}
// Try to infer based on the desired video codec
@@ -463,10 +462,9 @@ public static class StreamingHelpers
return ".asf";
}
}
-
- // Try to infer based on the desired audio codec
- if (!state.IsVideoRequest)
+ else
{
+ // Try to infer based on the desired audio codec
var audioCodec = state.Request.AudioCodec;
if (string.Equals("aac", audioCodec, StringComparison.OrdinalIgnoreCase))
@@ -497,7 +495,7 @@ public static class StreamingHelpers
return '.' + (idx == -1 ? mediaSource.Container : mediaSource.Container[..idx]).Trim();
}
- return null;
+ throw new InvalidOperationException("Failed to find an appropriate file extension");
}
/// <summary>
@@ -509,12 +507,12 @@ public static class StreamingHelpers
/// <param name="deviceId">The device id.</param>
/// <param name="playSessionId">The play session id.</param>
/// <returns>The complete file path, including the folder, for the transcoding file.</returns>
- private static string GetOutputFilePath(StreamState state, string? outputFileExtension, IServerConfigurationManager serverConfigurationManager, string? deviceId, string? playSessionId)
+ private static string GetOutputFilePath(StreamState state, string outputFileExtension, IServerConfigurationManager serverConfigurationManager, string? deviceId, string? playSessionId)
{
var data = $"{state.MediaPath}-{state.UserAgent}-{deviceId!}-{playSessionId!}";
var filename = data.GetMD5().ToString("N", CultureInfo.InvariantCulture);
- var ext = outputFileExtension?.ToLowerInvariant();
+ var ext = outputFileExtension.ToLowerInvariant();
var folder = serverConfigurationManager.GetTranscodePath();
return Path.Combine(folder, filename + ext);