Studio.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.Data.Enums;
  7. using Jellyfin.Extensions;
  8. using Microsoft.Extensions.Logging;
  9. namespace MediaBrowser.Controller.Entities
  10. {
  11. /// <summary>
  12. /// Class Studio.
  13. /// </summary>
  14. [Common.RequiresSourceSerialisation]
  15. public class Studio : BaseItem, IItemByName
  16. {
  17. /// <summary>
  18. /// Gets the folder containing the item.
  19. /// If the item is a folder, it returns the folder itself.
  20. /// </summary>
  21. /// <value>The containing folder path.</value>
  22. [JsonIgnore]
  23. public override string ContainingFolderPath => Path;
  24. [JsonIgnore]
  25. public override bool IsDisplayedAsFolder => true;
  26. [JsonIgnore]
  27. public override bool SupportsAncestors => false;
  28. [JsonIgnore]
  29. public override bool SupportsPeople => false;
  30. public override List<string> GetUserDataKeys()
  31. {
  32. var list = base.GetUserDataKeys();
  33. list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics());
  34. return list;
  35. }
  36. public override string CreatePresentationUniqueKey()
  37. {
  38. return GetUserDataKeys()[0];
  39. }
  40. public override double GetDefaultPrimaryImageAspectRatio()
  41. {
  42. double value = 16;
  43. value /= 9;
  44. return value;
  45. }
  46. public override bool CanDelete()
  47. {
  48. return false;
  49. }
  50. public override bool IsSaveLocalMetadataEnabled()
  51. {
  52. return true;
  53. }
  54. public IReadOnlyList<BaseItem> GetTaggedItems(InternalItemsQuery query)
  55. {
  56. query.StudioIds = new[] { Id };
  57. return LibraryManager.GetItemList(query);
  58. }
  59. public TaggedItemCounts GetTaggedItemCounts(InternalItemsQuery query)
  60. {
  61. query.StudioIds = [Id];
  62. var counts = new TaggedItemCounts();
  63. query.IncludeItemTypes = [BaseItemKind.MusicAlbum];
  64. counts.AlbumCount = LibraryManager.GetCount(query);
  65. query.IncludeItemTypes = [BaseItemKind.MusicArtist];
  66. counts.ArtistCount = LibraryManager.GetCount(query);
  67. query.IncludeItemTypes = [BaseItemKind.Episode];
  68. counts.EpisodeCount = LibraryManager.GetCount(query);
  69. query.IncludeItemTypes = [BaseItemKind.Movie];
  70. counts.MovieCount = LibraryManager.GetCount(query);
  71. query.IncludeItemTypes = [BaseItemKind.MusicVideo];
  72. counts.MusicVideoCount = LibraryManager.GetCount(query);
  73. query.IncludeItemTypes = [BaseItemKind.LiveTvProgram];
  74. counts.ProgramCount = LibraryManager.GetCount(query);
  75. query.IncludeItemTypes = [BaseItemKind.Series];
  76. counts.SeriesCount = LibraryManager.GetCount(query);
  77. query.IncludeItemTypes = [BaseItemKind.Audio];
  78. counts.SongCount = LibraryManager.GetCount(query);
  79. query.IncludeItemTypes = [BaseItemKind.Trailer];
  80. counts.TrailerCount = LibraryManager.GetCount(query);
  81. return counts;
  82. }
  83. public static string GetPath(string name)
  84. {
  85. return GetPath(name, true);
  86. }
  87. public static string GetPath(string name, bool normalizeName)
  88. {
  89. // Trim the period at the end because windows will have a hard time with that
  90. var validName = normalizeName ?
  91. FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
  92. name;
  93. return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.StudioPath, validName);
  94. }
  95. private string GetRebasedPath()
  96. {
  97. return GetPath(System.IO.Path.GetFileName(Path), false);
  98. }
  99. public override bool RequiresRefresh()
  100. {
  101. var newPath = GetRebasedPath();
  102. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  103. {
  104. Logger.LogDebug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
  105. return true;
  106. }
  107. return base.RequiresRefresh();
  108. }
  109. /// <summary>
  110. /// This is called before any metadata refresh and returns true or false indicating if changes were made.
  111. /// </summary>
  112. /// <param name="replaceAllMetadata"><c>true</c> to replace all metadata, <c>false</c> to not.</param>
  113. /// <returns><c>true</c> if changes were made, <c>false</c> if not.</returns>
  114. public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
  115. {
  116. var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
  117. var newPath = GetRebasedPath();
  118. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  119. {
  120. Path = newPath;
  121. hasChanges = true;
  122. }
  123. return hasChanges;
  124. }
  125. }
  126. }