ContainerProfile.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Linq;
  4. using System.Xml.Serialization;
  5. namespace MediaBrowser.Model.Dlna
  6. {
  7. public class ContainerProfile
  8. {
  9. [XmlAttribute("type")]
  10. public DlnaProfileType Type { get; set; }
  11. public ProfileCondition[]? Conditions { get; set; } = Array.Empty<ProfileCondition>();
  12. [XmlAttribute("container")]
  13. public string Container { get; set; } = string.Empty;
  14. public static string[] SplitValue(string? value)
  15. {
  16. if (string.IsNullOrEmpty(value))
  17. {
  18. return Array.Empty<string>();
  19. }
  20. return value.Split(',', StringSplitOptions.RemoveEmptyEntries);
  21. }
  22. public bool ContainsContainer(string? container)
  23. {
  24. var containers = SplitValue(Container);
  25. return ContainsContainer(containers, container);
  26. }
  27. public static bool ContainsContainer(string? profileContainers, string? inputContainer)
  28. {
  29. var isNegativeList = false;
  30. if (profileContainers != null && profileContainers.StartsWith('-'))
  31. {
  32. isNegativeList = true;
  33. profileContainers = profileContainers.Substring(1);
  34. }
  35. return ContainsContainer(SplitValue(profileContainers), isNegativeList, inputContainer);
  36. }
  37. public static bool ContainsContainer(string[]? profileContainers, string? inputContainer)
  38. {
  39. return ContainsContainer(profileContainers, false, inputContainer);
  40. }
  41. public static bool ContainsContainer(string[]? profileContainers, bool isNegativeList, string? inputContainer)
  42. {
  43. if (profileContainers == null || profileContainers.Length == 0)
  44. {
  45. // Empty profiles always support all containers/codecs
  46. return true;
  47. }
  48. var allInputContainers = SplitValue(inputContainer);
  49. foreach (var container in allInputContainers)
  50. {
  51. if (profileContainers.Contains(container, StringComparer.OrdinalIgnoreCase))
  52. {
  53. return !isNegativeList;
  54. }
  55. }
  56. return isNegativeList;
  57. }
  58. }
  59. }