Simplify mapping in Trakt connection

This commit is contained in:
Bogdan 2023-12-11 20:47:20 +02:00
parent 6cb9a46cd4
commit c9e977baea
2 changed files with 41 additions and 105 deletions

View File

@ -200,119 +200,62 @@ namespace NzbDrone.Core.Notifications.Trakt
private string MapMediaType(QualitySource source)
{
var traktSource = string.Empty;
switch (source)
var traktSource = source switch
{
case QualitySource.BLURAY:
traktSource = "bluray";
break;
case QualitySource.WEBDL:
traktSource = "digital";
break;
case QualitySource.WEBRIP:
traktSource = "digital";
break;
case QualitySource.DVD:
traktSource = "dvd";
break;
case QualitySource.TV:
traktSource = "dvd";
break;
}
QualitySource.BLURAY => "bluray",
QualitySource.WEBDL => "digital",
QualitySource.WEBRIP => "digital",
QualitySource.DVD => "dvd",
QualitySource.TV => "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 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(MovieFile movieFile)
{
var traktAudioFormat = string.Empty;
var audioCodec = movieFile.MediaInfo != null ? MediaInfoFormatter.FormatAudioCodec(movieFile.MediaInfo, movieFile.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"
};
}
}