MusicGenre.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.Audio
  7. {
  8. /// <summary>
  9. /// Class MusicGenre
  10. /// </summary>
  11. public class MusicGenre : 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. [IgnoreDataMember]
  24. public override bool SupportsAddingToPlaylist
  25. {
  26. get { return true; }
  27. }
  28. [IgnoreDataMember]
  29. public override bool SupportsAncestors
  30. {
  31. get
  32. {
  33. return false;
  34. }
  35. }
  36. [IgnoreDataMember]
  37. public override bool IsDisplayedAsFolder
  38. {
  39. get
  40. {
  41. return true;
  42. }
  43. }
  44. /// <summary>
  45. /// Returns the folder containing the item.
  46. /// If the item is a folder, it returns the folder itself
  47. /// </summary>
  48. /// <value>The containing folder path.</value>
  49. [IgnoreDataMember]
  50. public override string ContainingFolderPath
  51. {
  52. get
  53. {
  54. return Path;
  55. }
  56. }
  57. public override double GetDefaultPrimaryImageAspectRatio()
  58. {
  59. return 1;
  60. }
  61. public override bool CanDelete()
  62. {
  63. return false;
  64. }
  65. public override bool IsSaveLocalMetadataEnabled()
  66. {
  67. return true;
  68. }
  69. [IgnoreDataMember]
  70. public override bool SupportsPeople
  71. {
  72. get
  73. {
  74. return false;
  75. }
  76. }
  77. public IList<BaseItem> GetTaggedItems(InternalItemsQuery query)
  78. {
  79. query.GenreIds = new[] { Id };
  80. query.IncludeItemTypes = new[] { typeof(MusicVideo).Name, typeof(Audio).Name, typeof(MusicAlbum).Name, typeof(MusicArtist).Name };
  81. return LibraryManager.GetItemList(query);
  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.MusicGenrePath, 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. public override bool BeforeMetadataRefresh(bool replaceAllMetdata)
  113. {
  114. var hasChanges = base.BeforeMetadataRefresh(replaceAllMetdata);
  115. var newPath = GetRebasedPath();
  116. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  117. {
  118. Path = newPath;
  119. hasChanges = true;
  120. }
  121. return hasChanges;
  122. }
  123. }
  124. }