Studio.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using MediaBrowser.Common.Extensions;
  6. namespace MediaBrowser.Controller.Entities
  7. {
  8. /// <summary>
  9. /// Class Studio
  10. /// </summary>
  11. public class Studio : BaseItem, IItemByName
  12. {
  13. public override List<string> GetUserDataKeys()
  14. {
  15. var list = base.GetUserDataKeys();
  16. list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics());
  17. return list;
  18. }
  19. public override string CreatePresentationUniqueKey()
  20. {
  21. return GetUserDataKeys()[0];
  22. }
  23. /// <summary>
  24. /// Returns the folder containing the item.
  25. /// If the item is a folder, it returns the folder itself
  26. /// </summary>
  27. /// <value>The containing folder path.</value>
  28. [IgnoreDataMember]
  29. public override string ContainingFolderPath
  30. {
  31. get
  32. {
  33. return Path;
  34. }
  35. }
  36. public override bool CanDelete()
  37. {
  38. return false;
  39. }
  40. public override bool IsSaveLocalMetadataEnabled()
  41. {
  42. return true;
  43. }
  44. /// <summary>
  45. /// Gets a value indicating whether this instance is owned item.
  46. /// </summary>
  47. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  48. [IgnoreDataMember]
  49. public override bool IsOwnedItem
  50. {
  51. get
  52. {
  53. return false;
  54. }
  55. }
  56. public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems)
  57. {
  58. return inputItems.Where(GetItemFilter());
  59. }
  60. public Func<BaseItem, bool> GetItemFilter()
  61. {
  62. return i => i.Studios.Contains(Name, StringComparer.OrdinalIgnoreCase);
  63. }
  64. public IEnumerable<BaseItem> GetTaggedItems(InternalItemsQuery query)
  65. {
  66. query.Studios = new[] { Name };
  67. return LibraryManager.GetItemList(query);
  68. }
  69. [IgnoreDataMember]
  70. public override bool SupportsPeople
  71. {
  72. get
  73. {
  74. return false;
  75. }
  76. }
  77. public static string GetPath(string name, bool normalizeName = true)
  78. {
  79. // Trim the period at the end because windows will have a hard time with that
  80. var validName = normalizeName ?
  81. FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
  82. name;
  83. return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.StudioPath, validName);
  84. }
  85. private string GetRebasedPath()
  86. {
  87. return GetPath(System.IO.Path.GetFileName(Path), false);
  88. }
  89. public override bool RequiresRefresh()
  90. {
  91. var newPath = GetRebasedPath();
  92. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  93. {
  94. Logger.Debug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
  95. return true;
  96. }
  97. return base.RequiresRefresh();
  98. }
  99. /// <summary>
  100. /// This is called before any metadata refresh and returns true or false indicating if changes were made
  101. /// </summary>
  102. public override bool BeforeMetadataRefresh()
  103. {
  104. var hasChanges = base.BeforeMetadataRefresh();
  105. var newPath = GetRebasedPath();
  106. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  107. {
  108. Path = newPath;
  109. hasChanges = true;
  110. }
  111. return hasChanges;
  112. }
  113. }
  114. }