MetadataResult.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #nullable disable
  2. #pragma warning disable CA1002, CA2227, CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using MediaBrowser.Controller.Entities;
  7. using MediaBrowser.Model.Entities;
  8. namespace MediaBrowser.Controller.Providers
  9. {
  10. public class MetadataResult<T>
  11. {
  12. // Images aren't always used so the allocation is a waste a lot of the time
  13. private List<LocalImageInfo> _images;
  14. private List<(string Url, ImageType Type)> _remoteImages;
  15. public MetadataResult()
  16. {
  17. ResultLanguage = "en";
  18. }
  19. public List<LocalImageInfo> Images
  20. {
  21. get => _images ??= new List<LocalImageInfo>();
  22. set => _images = value;
  23. }
  24. public List<(string Url, ImageType Type)> RemoteImages
  25. {
  26. get => _remoteImages ??= new List<(string Url, ImageType Type)>();
  27. set => _remoteImages = value;
  28. }
  29. public List<UserItemData> UserDataList { get; set; }
  30. public List<PersonInfo> People { get; set; }
  31. public bool HasMetadata { get; set; }
  32. public T Item { get; set; }
  33. public string ResultLanguage { get; set; }
  34. public string Provider { get; set; }
  35. public bool QueriedById { get; set; }
  36. public void AddPerson(PersonInfo p)
  37. {
  38. People ??= new List<PersonInfo>();
  39. PeopleHelper.AddPerson(People, p);
  40. }
  41. /// <summary>
  42. /// Not only does this clear, but initializes the list so that services can differentiate between a null list and zero people.
  43. /// </summary>
  44. public void ResetPeople()
  45. {
  46. if (People is null)
  47. {
  48. People = new List<PersonInfo>();
  49. }
  50. else
  51. {
  52. People.Clear();
  53. }
  54. }
  55. public UserItemData GetOrAddUserData(string userId)
  56. {
  57. UserDataList ??= new List<UserItemData>();
  58. UserItemData userData = null;
  59. foreach (var i in UserDataList)
  60. {
  61. if (string.Equals(userId, i.UserId.ToString("N", CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase))
  62. {
  63. userData = i;
  64. }
  65. }
  66. if (userData is null)
  67. {
  68. userData = new UserItemData()
  69. {
  70. UserId = new Guid(userId)
  71. };
  72. UserDataList.Add(userData);
  73. }
  74. return userData;
  75. }
  76. }
  77. }