From c8a111867908333a1dab1ae52cddb0e3453a3eac Mon Sep 17 00:00:00 2001 From: Bogdan Date: Mon, 11 Dec 2023 20:47:20 +0200 Subject: [PATCH] Simplify mapping in Trakt connection --- .../Notifications/Trakt/Trakt.cs | 136 ++++++------------ .../Trakt/TraktInterlacedTypes.cs | 13 +- 2 files changed, 43 insertions(+), 106 deletions(-) diff --git a/src/NzbDrone.Core/Notifications/Trakt/Trakt.cs b/src/NzbDrone.Core/Notifications/Trakt/Trakt.cs index 86d03b5ab..af5e2f2d4 100644 --- a/src/NzbDrone.Core/Notifications/Trakt/Trakt.cs +++ b/src/NzbDrone.Core/Notifications/Trakt/Trakt.cs @@ -284,120 +284,64 @@ namespace NzbDrone.Core.Notifications.Trakt private string MapMediaType(QualitySource source) { - var traktSource = string.Empty; - - switch (source) + var traktSource = source switch { - case QualitySource.Web: - case QualitySource.WebRip: - traktSource = "digital"; - break; - case QualitySource.BlurayRaw: - case QualitySource.Bluray: - traktSource = "bluray"; - break; - case QualitySource.Television: - case QualitySource.TelevisionRaw: - traktSource = "vhs"; - break; - case QualitySource.DVD: - traktSource = "dvd"; - break; - } + QualitySource.Web => "digital", + QualitySource.WebRip => "digital", + QualitySource.BlurayRaw => "bluray", + QualitySource.Bluray => "bluray", + QualitySource.Television => "vhs", + QualitySource.TelevisionRaw => "vhs", + QualitySource.DVD => "dvd", + _ => string.Empty + }; return traktSource; } private string MapResolution(int resolution, string scanType) { - var traktResolution = string.Empty; + var scanIdentifier = scanType.IsNotNullOrWhiteSpace() && TraktInterlacedTypes.InterlacedTypes.Contains(scanType) ? "i" : "p"; - // var interlacedTypes = new string[] { "Interlaced", "MBAFF", "PAFF" }; - var scanIdentifier = scanType.IsNotNullOrWhiteSpace() && TraktInterlacedTypes.interlacedTypes.Contains(scanType) ? "i" : "p"; - - switch (resolution) + var traktResolution = resolution switch { - case 2160: - traktResolution = "uhd_4k"; - break; - case 1080: - traktResolution = $"hd_1080{scanIdentifier}"; - break; - case 720: - traktResolution = "hd_720p"; - break; - case 576: - traktResolution = $"sd_576{scanIdentifier}"; - break; - case 480: - traktResolution = $"sd_480{scanIdentifier}"; - break; - } + 2160 => "uhd_4k", + 1080 => $"hd_1080{scanIdentifier}", + 720 => "hd_720p", + 576 => $"sd_576{scanIdentifier}", + 480 => $"sd_480{scanIdentifier}", + _ => string.Empty + }; return traktResolution; } private string MapAudio(EpisodeFile episodeFile) { - var traktAudioFormat = string.Empty; - var audioCodec = episodeFile.MediaInfo != null ? MediaInfoFormatter.FormatAudioCodec(episodeFile.MediaInfo, episodeFile.SceneName) : string.Empty; - switch (audioCodec) + var traktAudioFormat = audioCodec switch { - case "AC3": - traktAudioFormat = "dolby_digital"; - break; - case "EAC3": - traktAudioFormat = "dolby_digital_plus"; - break; - case "TrueHD": - traktAudioFormat = "dolby_truehd"; - break; - case "EAC3 Atmos": - traktAudioFormat = "dolby_digital_plus_atmos"; - break; - case "TrueHD Atmos": - traktAudioFormat = "dolby_atmos"; - break; - case "DTS": - case "DTS-ES": - traktAudioFormat = "dts"; - break; - case "DTS-HD MA": - traktAudioFormat = "dts_ma"; - break; - case "DTS-HD HRA": - traktAudioFormat = "dts_hr"; - break; - case "DTS-X": - traktAudioFormat = "dts_x"; - break; - case "MP3": - traktAudioFormat = "mp3"; - break; - case "MP2": - traktAudioFormat = "mp2"; - break; - case "Vorbis": - traktAudioFormat = "ogg"; - break; - case "WMA": - traktAudioFormat = "wma"; - break; - case "AAC": - traktAudioFormat = "aac"; - break; - case "PCM": - traktAudioFormat = "lpcm"; - break; - case "FLAC": - traktAudioFormat = "flac"; - break; - case "Opus": - traktAudioFormat = "ogg_opus"; - break; - } + "AC3" => "dolby_digital", + "EAC3" => "dolby_digital_plus", + "TrueHD" => "dolby_truehd", + "EAC3 Atmos" => "dolby_digital_plus_atmos", + "TrueHD Atmos" => "dolby_atmos", + "DTS" => "dts", + "DTS-ES" => "dts", + "DTS-HD MA" => "dts_ma", + "DTS-HD HRA" => "dts_hr", + "DTS-X" => "dts_x", + "MP3" => "mp3", + "MP2" => "mp2", + "Vorbis" => "ogg", + "WMA" => "wma", + "AAC" => "aac", + "PCM" => "lpcm", + "FLAC" => "flac", + "Opus" => "ogg_opus", + _ => string.Empty + }; return traktAudioFormat; } diff --git a/src/NzbDrone.Core/Notifications/Trakt/TraktInterlacedTypes.cs b/src/NzbDrone.Core/Notifications/Trakt/TraktInterlacedTypes.cs index 7459a83d9..458ef4382 100644 --- a/src/NzbDrone.Core/Notifications/Trakt/TraktInterlacedTypes.cs +++ b/src/NzbDrone.Core/Notifications/Trakt/TraktInterlacedTypes.cs @@ -5,16 +5,9 @@ namespace NzbDrone.Core.Notifications.Trakt { public static class TraktInterlacedTypes { - private static HashSet _interlacedTypes; - - static TraktInterlacedTypes() + public static readonly HashSet InterlacedTypes = new (StringComparer.OrdinalIgnoreCase) { - _interlacedTypes = new HashSet(StringComparer.OrdinalIgnoreCase) - { - "Interlaced", "MBAFF", "PAFF" - }; - } - - public static HashSet interlacedTypes => _interlacedTypes; + "Interlaced", "MBAFF", "PAFF" + }; } }