MusicVideo.cs 3.8 KB

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