Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions Trakt/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,12 @@ public static int GetSeasonNumber(this Episode episode)
/// <returns>string.</returns>
public static string GetAudioChannels(this MediaStream audioStream)
{
if (audioStream == null || string.IsNullOrEmpty(audioStream.ChannelLayout))
if (audioStream == null)
{
return null;
}

var channels = audioStream.ChannelLayout;
switch (channels)
switch (audioStream.ChannelLayout)
{
case "22.2":
case "hexadecagonal":
Expand Down Expand Up @@ -357,10 +356,30 @@ public static string GetAudioChannels(this MediaStream audioStream)
case "mono":
return "1.0";
default:
return null;
// Missing or unknown layout, e.g. "6 channels"
return GetAudioChannelsFromCount(audioStream.Channels);
}
}

/// <summary>
/// Gets the most common trakt.tv audio channels value for a channel count.
/// </summary>
/// <param name="channelCount">The number of audio channels.</param>
/// <returns>string.</returns>
private static string GetAudioChannelsFromCount(int? channelCount)
=> channelCount switch
{
1 => "1.0",
2 => "2.0",
3 => "2.1",
4 => "4.0",
5 => "5.0",
6 => "5.1",
7 => "6.1",
8 => "7.1",
_ => null
};

/// <summary>
/// Gets a watched match for a series.
/// </summary>
Expand Down