consolidate methods

This commit is contained in:
Luke Pulverenti 2017-08-04 02:34:46 -04:00
parent d50ffcbfb2
commit b786cca9da
3 changed files with 35 additions and 30 deletions

View File

@ -42,16 +42,9 @@ namespace MediaBrowser.Model.Dlna
return SplitValue(Codec); return SplitValue(Codec);
} }
public List<string> GetContainers()
{
return SplitValue(Container);
}
private bool ContainsContainer(string container) private bool ContainsContainer(string container)
{ {
List<string> containers = GetContainers(); return ContainerProfile.ContainsContainer(Container, container);
return containers.Count == 0 || ListHelper.ContainsIgnoreCase(containers, container ?? string.Empty);
} }
public bool ContainsCodec(string codec, string container) public bool ContainsCodec(string codec, string container)

View File

@ -20,11 +20,16 @@ namespace MediaBrowser.Model.Dlna
} }
public List<string> GetContainers() public List<string> GetContainers()
{
return SplitValue(Container);
}
private static List<string> SplitValue(string value)
{ {
List<string> list = new List<string>(); List<string> list = new List<string>();
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; return list;
} }
@ -33,7 +38,32 @@ namespace MediaBrowser.Model.Dlna
{ {
List<string> containers = GetContainers(); List<string> 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<string> 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;
} }
} }
} }

View File

@ -19,27 +19,9 @@ namespace MediaBrowser.Model.Dlna
[XmlAttribute("type")] [XmlAttribute("type")]
public DlnaProfileType Type { get; set; } public DlnaProfileType Type { get; set; }
public List<string> GetContainers()
{
List<string> list = new List<string>();
foreach (string i in (Container ?? string.Empty).Split(','))
{
if (!string.IsNullOrEmpty(i)) list.Add(i);
}
return list;
}
public bool SupportsContainer(string container) public bool SupportsContainer(string container)
{ {
var all = GetContainers(); return ContainerProfile.ContainsContainer(Container, container);
// 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);
} }
public List<string> GetAudioCodecs() public List<string> GetAudioCodecs()