From b786cca9da42b6caa1e2b1f2d4fa7ac0c0c0a984 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 4 Aug 2017 02:34:46 -0400 Subject: [PATCH] consolidate methods --- MediaBrowser.Model/Dlna/CodecProfile.cs | 9 +---- MediaBrowser.Model/Dlna/ContainerProfile.cs | 36 ++++++++++++++++++-- MediaBrowser.Model/Dlna/DirectPlayProfile.cs | 20 +---------- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/MediaBrowser.Model/Dlna/CodecProfile.cs b/MediaBrowser.Model/Dlna/CodecProfile.cs index e04e04d21..979cd343f 100644 --- a/MediaBrowser.Model/Dlna/CodecProfile.cs +++ b/MediaBrowser.Model/Dlna/CodecProfile.cs @@ -42,16 +42,9 @@ namespace MediaBrowser.Model.Dlna return SplitValue(Codec); } - public List GetContainers() - { - return SplitValue(Container); - } - private bool ContainsContainer(string container) { - List containers = GetContainers(); - - return containers.Count == 0 || ListHelper.ContainsIgnoreCase(containers, container ?? string.Empty); + return ContainerProfile.ContainsContainer(Container, container); } public bool ContainsCodec(string codec, string container) diff --git a/MediaBrowser.Model/Dlna/ContainerProfile.cs b/MediaBrowser.Model/Dlna/ContainerProfile.cs index 35d7ada6b..a8f203e22 100644 --- a/MediaBrowser.Model/Dlna/ContainerProfile.cs +++ b/MediaBrowser.Model/Dlna/ContainerProfile.cs @@ -20,11 +20,16 @@ namespace MediaBrowser.Model.Dlna } public List GetContainers() + { + return SplitValue(Container); + } + + private static List SplitValue(string value) { List list = new List(); - foreach (string i in (Container ?? string.Empty).Split(',')) + foreach (string i in (value ?? string.Empty).Split(',')) { - if (!string.IsNullOrEmpty(i)) list.Add(i); + if (!string.IsNullOrWhiteSpace(i)) list.Add(i); } return list; } @@ -33,7 +38,32 @@ namespace MediaBrowser.Model.Dlna { List containers = GetContainers(); - return containers.Count == 0 || ListHelper.ContainsIgnoreCase(containers, container ?? string.Empty); + return ContainsContainer(containers, container); + } + + public static bool ContainsContainer(string profileContainers, string inputContainer) + { + return ContainsContainer(SplitValue(profileContainers), inputContainer); + } + + public static bool ContainsContainer(List profileContainers, string inputContainer) + { + if (profileContainers.Count == 0) + { + return true; + } + + var allInputContainers = SplitValue(inputContainer); + + foreach (var container in allInputContainers) + { + if (ListHelper.ContainsIgnoreCase(profileContainers, container)) + { + return true; + } + } + + return false; } } } diff --git a/MediaBrowser.Model/Dlna/DirectPlayProfile.cs b/MediaBrowser.Model/Dlna/DirectPlayProfile.cs index df511b0da..d99501875 100644 --- a/MediaBrowser.Model/Dlna/DirectPlayProfile.cs +++ b/MediaBrowser.Model/Dlna/DirectPlayProfile.cs @@ -19,27 +19,9 @@ namespace MediaBrowser.Model.Dlna [XmlAttribute("type")] public DlnaProfileType Type { get; set; } - public List GetContainers() - { - List list = new List(); - foreach (string i in (Container ?? string.Empty).Split(',')) - { - if (!string.IsNullOrEmpty(i)) list.Add(i); - } - return list; - } - public bool SupportsContainer(string container) { - var all = GetContainers(); - - // Only allow unknown container if the profile is all inclusive - if (string.IsNullOrWhiteSpace(container)) - { - return all.Count == 0; - } - - return all.Count == 0 || all.Contains(container, StringComparer.OrdinalIgnoreCase); + return ContainerProfile.ContainsContainer(Container, container); } public List GetAudioCodecs()