MusicGenre.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System;
  2. using System.Collections.Generic;
  3. using MediaBrowser.Model.Serialization;
  4. using MediaBrowser.Common.Extensions;
  5. using MediaBrowser.Controller.Extensions;
  6. using MediaBrowser.Model.Extensions;
  7. namespace MediaBrowser.Controller.Entities.Audio
  8. {
  9. /// <summary>
  10. /// Class MusicGenre
  11. /// </summary>
  12. public class MusicGenre : 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. [IgnoreDataMember]
  25. public override bool SupportsAddingToPlaylist
  26. {
  27. get { return true; }
  28. }
  29. [IgnoreDataMember]
  30. public override bool SupportsAncestors
  31. {
  32. get
  33. {
  34. return false;
  35. }
  36. }
  37. [IgnoreDataMember]
  38. public override bool IsDisplayedAsFolder
  39. {
  40. get
  41. {
  42. return true;
  43. }
  44. }
  45. /// <summary>
  46. /// Returns the folder containing the item.
  47. /// If the item is a folder, it returns the folder itself
  48. /// </summary>
  49. /// <value>The containing folder path.</value>
  50. [IgnoreDataMember]
  51. public override string ContainingFolderPath
  52. {
  53. get
  54. {
  55. return Path;
  56. }
  57. }
  58. public override double? GetDefaultPrimaryImageAspectRatio()
  59. {
  60. return 1;
  61. }
  62. public override bool CanDelete()
  63. {
  64. return false;
  65. }
  66. public override bool IsSaveLocalMetadataEnabled()
  67. {
  68. return true;
  69. }
  70. /// <summary>
  71. /// Gets a value indicating whether this instance is owned item.
  72. /// </summary>
  73. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  74. [IgnoreDataMember]
  75. public override bool IsOwnedItem
  76. {
  77. get
  78. {
  79. return false;
  80. }
  81. }
  82. [IgnoreDataMember]
  83. public override bool SupportsPeople
  84. {
  85. get
  86. {
  87. return false;
  88. }
  89. }
  90. public IEnumerable<BaseItem> GetTaggedItems(InternalItemsQuery query)
  91. {
  92. query.GenreIds = new[] { Id.ToString("N") };
  93. query.IncludeItemTypes = new[] { typeof(MusicVideo).Name, typeof(Audio).Name, typeof(MusicAlbum).Name, typeof(MusicArtist).Name };
  94. return LibraryManager.GetItemList(query);
  95. }
  96. public static string GetPath(string name)
  97. {
  98. return GetPath(name, true);
  99. }
  100. public static string GetPath(string name, bool normalizeName)
  101. {
  102. // Trim the period at the end because windows will have a hard time with that
  103. var validName = normalizeName ?
  104. FileSystem.GetValidFilename(name).Trim().TrimEnd('.') :
  105. name;
  106. return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.MusicGenrePath, validName);
  107. }
  108. private string GetRebasedPath()
  109. {
  110. return GetPath(System.IO.Path.GetFileName(Path), false);
  111. }
  112. public override bool RequiresRefresh()
  113. {
  114. var newPath = GetRebasedPath();
  115. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  116. {
  117. Logger.Debug("{0} path has changed from {1} to {2}", GetType().Name, Path, newPath);
  118. return true;
  119. }
  120. return base.RequiresRefresh();
  121. }
  122. /// <summary>
  123. /// This is called before any metadata refresh and returns true or false indicating if changes were made
  124. /// </summary>
  125. public override bool BeforeMetadataRefresh()
  126. {
  127. var hasChanges = base.BeforeMetadataRefresh();
  128. var newPath = GetRebasedPath();
  129. if (!string.Equals(Path, newPath, StringComparison.Ordinal))
  130. {
  131. Path = newPath;
  132. hasChanges = true;
  133. }
  134. return hasChanges;
  135. }
  136. }
  137. }