1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-19 17:32:38 +01:00

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 @@ private void RemoveMovieFromCollection(TraktSettings settings, Movie movie)
private string MapMediaType(QualitySource source) private string MapMediaType(QualitySource source)
{ {
var traktSource = string.Empty; var traktSource = source switch
switch (source)
{ {
case QualitySource.BLURAY: QualitySource.BLURAY => "bluray",
traktSource = "bluray"; QualitySource.WEBDL => "digital",
break; QualitySource.WEBRIP => "digital",
case QualitySource.WEBDL: QualitySource.DVD => "dvd",
traktSource = "digital"; QualitySource.TV => "dvd",
break; _ => string.Empty
case QualitySource.WEBRIP: };
traktSource = "digital";
break;
case QualitySource.DVD:
traktSource = "dvd";
break;
case QualitySource.TV:
traktSource = "dvd";
break;
}
return traktSource; return traktSource;
} }
private string MapResolution(int resolution, string scanType) 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"; var traktResolution = resolution switch
switch (resolution)
{ {
case 2160: 2160 => "uhd_4k",
traktResolution = "uhd_4k"; 1080 => $"hd_1080{scanIdentifier}",
break; 720 => "hd_720p",
case 1080: 576 => $"sd_576{scanIdentifier}",
traktResolution = $"hd_1080{scanIdentifier}"; 480 => $"sd_480{scanIdentifier}",
break; _ => string.Empty
case 720: };
traktResolution = "hd_720p";
break;
case 576:
traktResolution = $"sd_576{scanIdentifier}";
break;
case 480:
traktResolution = $"sd_480{scanIdentifier}";
break;
}
return traktResolution; return traktResolution;
} }
private string MapAudio(MovieFile movieFile) private string MapAudio(MovieFile movieFile)
{ {
var traktAudioFormat = string.Empty;
var audioCodec = movieFile.MediaInfo != null ? MediaInfoFormatter.FormatAudioCodec(movieFile.MediaInfo, movieFile.SceneName) : string.Empty; var audioCodec = movieFile.MediaInfo != null ? MediaInfoFormatter.FormatAudioCodec(movieFile.MediaInfo, movieFile.SceneName) : string.Empty;
switch (audioCodec) var traktAudioFormat = audioCodec switch
{ {
case "AC3": "AC3" => "dolby_digital",
traktAudioFormat = "dolby_digital"; "EAC3" => "dolby_digital_plus",
break; "TrueHD" => "dolby_truehd",
case "EAC3": "EAC3 Atmos" => "dolby_digital_plus_atmos",
traktAudioFormat = "dolby_digital_plus"; "TrueHD Atmos" => "dolby_atmos",
break; "DTS" => "dts",
case "TrueHD": "DTS-ES" => "dts",
traktAudioFormat = "dolby_truehd"; "DTS-HD MA" => "dts_ma",
break; "DTS-HD HRA" => "dts_hr",
case "EAC3 Atmos": "DTS-X" => "dts_x",
traktAudioFormat = "dolby_digital_plus_atmos"; "MP3" => "mp3",
break; "MP2" => "mp2",
case "TrueHD Atmos": "Vorbis" => "ogg",
traktAudioFormat = "dolby_atmos"; "WMA" => "wma",
break; "AAC" => "aac",
case "DTS": "PCM" => "lpcm",
case "DTS-ES": "FLAC" => "flac",
traktAudioFormat = "dts"; "Opus" => "ogg_opus",
break; _ => string.Empty
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;
}
return traktAudioFormat; return traktAudioFormat;
} }

View File

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