Skip to content

Commit

Permalink
StreamingHelpers.GetOutputFileExtension should never return null (jel…
Browse files Browse the repository at this point in the history
  • Loading branch information
Bond-009 authored Oct 11, 2023
2 parents c02f2d4 + 35d63ec commit 456d9dc
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions Jellyfin.Api/Helpers/StreamingHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,12 @@ private static void AddTimeSeekResponseHeaders(StreamState state, IHeaderDiction
/// <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
Expand Down Expand Up @@ -463,10 +462,9 @@ private static void AddTimeSeekResponseHeaders(StreamState state, IHeaderDiction
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))
Expand Down Expand Up @@ -497,7 +495,7 @@ private static void AddTimeSeekResponseHeaders(StreamState state, IHeaderDiction
return '.' + (idx == -1 ? mediaSource.Container : mediaSource.Container[..idx]).Trim();
}

return null;
throw new InvalidOperationException("Failed to find an appropriate file extension");
}

/// <summary>
Expand All @@ -509,12 +507,12 @@ private static void AddTimeSeekResponseHeaders(StreamState state, IHeaderDiction
/// <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);
Expand Down

0 comments on commit 456d9dc

Please sign in to comment.