Studio.cs 3.6 KB

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