Genre.cs 4.1 KB

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