Studio.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text.Json.Serialization;
  5. using MediaBrowser.Controller.Extensions;
  6. using Microsoft.Extensions.Logging;
  7. namespace MediaBrowser.Controller.Entities
  8. {
  9. /// <summary>
  10. /// Class Studio.
  11. /// </summary>
  12. public class Studio : BaseItem, IItemByName
  13. {
  14. public override List<string> GetUserDataKeys()
  15. {
  16. var list = base.GetUserDataKeys();
  17. list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics());
  18. return list;
  19. }
  20. public override string CreatePresentationUniqueKey()
  21. {
  22. return GetUserDataKeys()[0];
  23. }
  24. /// <summary>
  25. /// Returns the folder containing the item.
  26. /// If the item is a folder, it returns the folder itself.
  27. /// </summary>
  28. /// <value>The containing folder path.</value>
  29. [JsonIgnore]
  30. public override string ContainingFolderPath => Path;
  31. [JsonIgnore]
  32. public override bool IsDisplayedAsFolder => true;
  33. [JsonIgnore]
  34. public override bool SupportsAncestors => false;
  35. public override double GetDefaultPrimaryImageAspectRatio()
  36. {
  37. double value = 16;
  38. value /= 9;
  39. return value;
  40. }
  41. public override bool CanDelete()
  42. {
  43. return false;
  44. }
  45. public override bool IsSaveLocalMetadataEnabled()
  46. {
  47. return true;
  48. }
  49. public IList<BaseItem> GetTaggedItems(InternalItemsQuery query)
  50. {
  51. query.StudioIds = new[] { Id };
  52. return LibraryManager.GetItemList(query);
  53. }
  54. [JsonIgnore]
  55. public override bool SupportsPeople => false;
  56. public static string GetPath(string name)
  57. {
  58. return GetPath(name, true);
  59. }
  60. public static string GetPath(string name, bool normalizeName)
  61. {
  62. // Trim the period at the end because windows will have a hard time with that
  63. var validName = normalizeName ?
  64. FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
  65. name;
  66. return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.StudioPath, validName);
  67. }
  68. private string GetRebasedPath()
  69. {
  70. return GetPath(System.IO.Path.GetFileName(Path), false);
  71. }
  72. public override bool RequiresRefresh()
  73. {
  74. var newPath = GetRebasedPath();
  75. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  76. {
  77. Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
  78. return true;
  79. }
  80. return base.RequiresRefresh();
  81. }
  82. /// <summary>
  83. /// This is called before any metadata refresh and returns true or false indicating if changes were made.
  84. /// </summary>
  85. public override bool BeforeMetadataRefresh(bool replaceAllMetdata)
  86. {
  87. var hasChanges = base.BeforeMetadataRefresh(replaceAllMetdata);
  88. var newPath = GetRebasedPath();
  89. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  90. {
  91. Path = newPath;
  92. hasChanges = true;
  93. }
  94. return hasChanges;
  95. }
  96. }
  97. }