ProviderUtils.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Model.Entities;
  3. using System.Collections.Generic;
  4. namespace MediaBrowser.Providers
  5. {
  6. public static class ProviderUtils
  7. {
  8. public static void MergeBaseItemData(BaseItem source, BaseItem target, List<MetadataFields> lockedFields, bool replaceData, bool mergeMetadataSettings)
  9. {
  10. if (!lockedFields.Contains(MetadataFields.Name))
  11. {
  12. if (replaceData || string.IsNullOrEmpty(target.Name))
  13. {
  14. target.Name = source.Name;
  15. }
  16. }
  17. if (replaceData || !target.CommunityRating.HasValue)
  18. {
  19. target.CommunityRating = source.CommunityRating;
  20. }
  21. if (replaceData || !target.EndDate.HasValue)
  22. {
  23. target.EndDate = source.EndDate;
  24. }
  25. if (!lockedFields.Contains(MetadataFields.Genres))
  26. {
  27. if (replaceData || target.Genres.Count == 0)
  28. {
  29. target.Genres = source.Genres;
  30. }
  31. }
  32. if (replaceData || string.IsNullOrEmpty(target.HomePageUrl))
  33. {
  34. target.HomePageUrl = source.HomePageUrl;
  35. }
  36. if (replaceData || !target.IndexNumber.HasValue)
  37. {
  38. target.IndexNumber = source.IndexNumber;
  39. }
  40. if (!lockedFields.Contains(MetadataFields.OfficialRating))
  41. {
  42. if (replaceData || string.IsNullOrEmpty(target.OfficialRating))
  43. {
  44. target.OfficialRating = source.OfficialRating;
  45. }
  46. }
  47. if (replaceData || string.IsNullOrEmpty(target.OfficialRatingDescription))
  48. {
  49. target.OfficialRatingDescription = source.OfficialRatingDescription;
  50. }
  51. if (!lockedFields.Contains(MetadataFields.Overview))
  52. {
  53. if (replaceData || string.IsNullOrEmpty(target.Overview))
  54. {
  55. target.Overview = source.Overview;
  56. }
  57. }
  58. if (replaceData || !target.ParentIndexNumber.HasValue)
  59. {
  60. target.ParentIndexNumber = source.ParentIndexNumber;
  61. }
  62. if (!lockedFields.Contains(MetadataFields.Cast))
  63. {
  64. if (replaceData || target.People.Count == 0)
  65. {
  66. target.People = source.People;
  67. }
  68. }
  69. if (replaceData || !target.PremiereDate.HasValue)
  70. {
  71. target.PremiereDate = source.PremiereDate;
  72. }
  73. if (replaceData || !target.ProductionYear.HasValue)
  74. {
  75. target.ProductionYear = source.ProductionYear;
  76. }
  77. if (!lockedFields.Contains(MetadataFields.Runtime))
  78. {
  79. if (replaceData || !target.RunTimeTicks.HasValue)
  80. {
  81. target.RunTimeTicks = source.RunTimeTicks;
  82. }
  83. }
  84. if (!lockedFields.Contains(MetadataFields.Studios))
  85. {
  86. if (replaceData || target.Studios.Count == 0)
  87. {
  88. target.Studios = source.Studios;
  89. }
  90. }
  91. if (replaceData || !target.VoteCount.HasValue)
  92. {
  93. target.VoteCount = source.VoteCount;
  94. }
  95. foreach (var id in source.ProviderIds)
  96. {
  97. target.ProviderIds[id.Key] = id.Value;
  98. }
  99. if (mergeMetadataSettings)
  100. {
  101. target.ForcedSortName = source.ForcedSortName;
  102. target.LockedFields = source.LockedFields;
  103. target.DontFetchMeta = source.DontFetchMeta;
  104. target.DisplayMediaType = source.DisplayMediaType;
  105. }
  106. }
  107. }
  108. }