Simplify mapping in Trakt connection

This commit is contained in:
Bogdan 2023-12-11 20:47:20 +02:00 committed by Mark McDowall
parent 91053ca51d
commit c8a1118679
2 changed files with 43 additions and 106 deletions

View File

@ -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;
}

View File

@ -5,16 +5,9 @@ namespace NzbDrone.Core.Notifications.Trakt
{
public static class TraktInterlacedTypes
{
private static HashSet<string> _interlacedTypes;
static TraktInterlacedTypes()
public static readonly HashSet<string> InterlacedTypes = new (StringComparer.OrdinalIgnoreCase)
{
_interlacedTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"Interlaced", "MBAFF", "PAFF"
};
}
public static HashSet<string> interlacedTypes => _interlacedTypes;
"Interlaced", "MBAFF", "PAFF"
};
}
}