You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/NzbDrone.Core/MediaFiles/MediaInfoFormatter.cs

77 lines
2.3 KiB

using System.Collections.Generic;
using NLog;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Core.Parser;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles
{
public static class MediaInfoFormatter
{
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(MediaInfoFormatter));
public static string FormatAudioBitrate(MediaInfoModel mediaInfo)
{
return mediaInfo.AudioBitrate + " kbps";
}
public static string FormatAudioBitsPerSample(MediaInfoModel mediaInfo)
{
if (mediaInfo.AudioBits == 0)
{
return string.Empty;
}
return mediaInfo.AudioBits + "bit";
}
public static string FormatAudioSampleRate(MediaInfoModel mediaInfo)
{
return $"{(double)mediaInfo.AudioSampleRate / 1000:0.#}kHz";
}
public static decimal FormatAudioChannels(MediaInfoModel mediaInfo)
{
return mediaInfo.AudioChannels;
}
public static readonly Dictionary<Codec, string> CodecNames = new Dictionary<Codec, string>
{
{ Codec.MP1, "MP1" },
{ Codec.MP2, "MP2" },
{ Codec.AAC, "AAC" },
{ Codec.AACVBR, "AAC" },
{ Codec.ALAC, "ALAC" },
{ Codec.APE, "APE" },
{ Codec.FLAC, "FLAC" },
{ Codec.MP3CBR, "MP3" },
{ Codec.MP3VBR, "MP3" },
{ Codec.OGG, "OGG" },
{ Codec.OPUS, "OPUS" },
{ Codec.WAV, "PCM" },
{ Codec.WAVPACK, "WavPack" },
{ Codec.WMA, "WMA" }
};
public static string FormatAudioCodec(MediaInfoModel mediaInfo)
{
var codec = QualityParser.ParseCodec(mediaInfo.AudioFormat);
if (CodecNames.ContainsKey(codec))
{
return CodecNames[codec];
}
else
{
Logger.ForDebugEvent()
.Message("Unknown audio format: '{0}'.", string.Join(", ", mediaInfo.AudioFormat))
.WriteSentryWarn("UnknownAudioFormat", mediaInfo.AudioFormat)
.Log();
return "Unknown";
}
}
}
}