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.
jellyfin/MediaBrowser.Model/Dlna/ContainerProfile.cs

75 lines
2.3 KiB

#pragma warning disable CS1591
using System;
6 years ago
using System.Xml.Serialization;
using Jellyfin.Extensions;
6 years ago
namespace MediaBrowser.Model.Dlna
{
public class ContainerProfile
{
[XmlAttribute("type")]
public DlnaProfileType Type { get; set; }
public ProfileCondition[]? Conditions { get; set; } = Array.Empty<ProfileCondition>();
6 years ago
[XmlAttribute("container")]
public string Container { get; set; } = string.Empty;
6 years ago
public static string[] SplitValue(string? value)
6 years ago
{
if (string.IsNullOrEmpty(value))
{
6 years ago
return Array.Empty<string>();
6 years ago
}
return value.Split(',', StringSplitOptions.RemoveEmptyEntries);
6 years ago
}
public bool ContainsContainer(string? container)
6 years ago
{
var containers = SplitValue(Container);
6 years ago
return ContainsContainer(containers, container);
}
public static bool ContainsContainer(string? profileContainers, string? inputContainer)
6 years ago
{
var isNegativeList = false;
if (profileContainers != null && profileContainers.StartsWith('-'))
6 years ago
{
isNegativeList = true;
profileContainers = profileContainers.Substring(1);
}
return ContainsContainer(SplitValue(profileContainers), isNegativeList, inputContainer);
}
public static bool ContainsContainer(string[]? profileContainers, string? inputContainer)
6 years ago
{
return ContainsContainer(profileContainers, false, inputContainer);
}
public static bool ContainsContainer(string[]? profileContainers, bool isNegativeList, string? inputContainer)
6 years ago
{
if (profileContainers == null || profileContainers.Length == 0)
6 years ago
{
// Empty profiles always support all containers/codecs
return true;
6 years ago
}
var allInputContainers = SplitValue(inputContainer);
6 years ago
foreach (var container in allInputContainers)
6 years ago
{
if (profileContainers.Contains(container, StringComparison.OrdinalIgnoreCase))
6 years ago
{
return !isNegativeList;
6 years ago
}
}
return isNegativeList;
6 years ago
}
}
}