MusicVideo.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using MediaBrowser.Controller.Entities.Audio;
  2. using MediaBrowser.Controller.Providers;
  3. using MediaBrowser.Model.Configuration;
  4. using MediaBrowser.Model.Entities;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Runtime.Serialization;
  9. using MediaBrowser.Model.Users;
  10. namespace MediaBrowser.Controller.Entities
  11. {
  12. public class MusicVideo : Video, IHasArtist, IHasMusicGenres, IHasProductionLocations, IHasBudget, IHasLookupInfo<MusicVideoInfo>
  13. {
  14. /// <summary>
  15. /// Gets or sets the album.
  16. /// </summary>
  17. /// <value>The album.</value>
  18. public string Album { get; set; }
  19. /// <summary>
  20. /// Gets or sets the budget.
  21. /// </summary>
  22. /// <value>The budget.</value>
  23. public double? Budget { get; set; }
  24. /// <summary>
  25. /// Gets or sets the revenue.
  26. /// </summary>
  27. /// <value>The revenue.</value>
  28. public double? Revenue { get; set; }
  29. public List<string> ProductionLocations { get; set; }
  30. public List<string> Artists { get; set; }
  31. public MusicVideo()
  32. {
  33. ProductionLocations = new List<string>();
  34. Artists = new List<string>();
  35. }
  36. [IgnoreDataMember]
  37. public List<string> AllArtists
  38. {
  39. get
  40. {
  41. return Artists;
  42. }
  43. }
  44. /// <summary>
  45. /// TODO: Remove
  46. /// </summary>
  47. public string Artist
  48. {
  49. get { return Artists.FirstOrDefault(); }
  50. set
  51. {
  52. if (!string.IsNullOrEmpty(value) && !Artists.Contains(value, StringComparer.OrdinalIgnoreCase))
  53. {
  54. Artists.Add(value);
  55. }
  56. }
  57. }
  58. /// <summary>
  59. /// Determines whether the specified name has artist.
  60. /// </summary>
  61. /// <param name="name">The name.</param>
  62. /// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
  63. public bool HasArtist(string name)
  64. {
  65. return AllArtists.Contains(name, StringComparer.OrdinalIgnoreCase);
  66. }
  67. /// <summary>
  68. /// Gets the user data key.
  69. /// </summary>
  70. /// <returns>System.String.</returns>
  71. public override string GetUserDataKey()
  72. {
  73. return this.GetProviderId(MetadataProviders.Tmdb) ?? this.GetProviderId(MetadataProviders.Imdb) ?? base.GetUserDataKey();
  74. }
  75. protected override bool GetBlockUnratedValue(UserPolicy config)
  76. {
  77. return config.BlockUnratedItems.Contains(UnratedItem.Music);
  78. }
  79. public MusicVideoInfo GetLookupInfo()
  80. {
  81. return GetItemLookupInfo<MusicVideoInfo>();
  82. }
  83. public override bool BeforeMetadataRefresh()
  84. {
  85. var hasChanges = base.BeforeMetadataRefresh();
  86. if (!ProductionYear.HasValue)
  87. {
  88. var info = LibraryManager.ParseName(Name);
  89. var yearInName = info.Year;
  90. if (yearInName.HasValue)
  91. {
  92. ProductionYear = yearInName;
  93. hasChanges = true;
  94. }
  95. else
  96. {
  97. // Try to get the year from the folder name
  98. if (!IsInMixedFolder)
  99. {
  100. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  101. yearInName = info.Year;
  102. if (yearInName.HasValue)
  103. {
  104. ProductionYear = yearInName;
  105. hasChanges = true;
  106. }
  107. }
  108. }
  109. }
  110. return hasChanges;
  111. }
  112. }
  113. }