Genre.cs 4.2 KB

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