Studio.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System;
  2. using System.Collections.Generic;
  3. using MediaBrowser.Model.Serialization;
  4. using MediaBrowser.Controller.Extensions;
  5. using Microsoft.Extensions.Logging;
  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. [IgnoreDataMember]
  37. public override bool IsDisplayedAsFolder
  38. {
  39. get
  40. {
  41. return true;
  42. }
  43. }
  44. [IgnoreDataMember]
  45. public override bool SupportsAncestors
  46. {
  47. get
  48. {
  49. return false;
  50. }
  51. }
  52. public override double GetDefaultPrimaryImageAspectRatio()
  53. {
  54. double value = 16;
  55. value /= 9;
  56. return value;
  57. }
  58. public override bool CanDelete()
  59. {
  60. return false;
  61. }
  62. public override bool IsSaveLocalMetadataEnabled()
  63. {
  64. return true;
  65. }
  66. public IList<BaseItem> GetTaggedItems(InternalItemsQuery query)
  67. {
  68. query.StudioIds = new[] { Id };
  69. return LibraryManager.GetItemList(query);
  70. }
  71. [IgnoreDataMember]
  72. public override bool SupportsPeople
  73. {
  74. get
  75. {
  76. return false;
  77. }
  78. }
  79. public static string GetPath(string name)
  80. {
  81. return GetPath(name, true);
  82. }
  83. public static string GetPath(string name, bool normalizeName)
  84. {
  85. // Trim the period at the end because windows will have a hard time with that
  86. var validName = normalizeName ?
  87. FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
  88. name;
  89. return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.StudioPath, validName);
  90. }
  91. private string GetRebasedPath()
  92. {
  93. return GetPath(System.IO.Path.GetFileName(Path), false);
  94. }
  95. public override bool RequiresRefresh()
  96. {
  97. var newPath = GetRebasedPath();
  98. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  99. {
  100. Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
  101. return true;
  102. }
  103. return base.RequiresRefresh();
  104. }
  105. /// <summary>
  106. /// This is called before any metadata refresh and returns true or false indicating if changes were made
  107. /// </summary>
  108. public override bool BeforeMetadataRefresh(bool replaceAllMetdata)
  109. {
  110. var hasChanges = base.BeforeMetadataRefresh(replaceAllMetdata);
  111. var newPath = GetRebasedPath();
  112. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  113. {
  114. Path = newPath;
  115. hasChanges = true;
  116. }
  117. return hasChanges;
  118. }
  119. }
  120. }