ContainerProfile.cs 2.3 KB

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