MusicVideo.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /// Determines whether the specified name has artist.
  46. /// </summary>
  47. /// <param name="name">The name.</param>
  48. /// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
  49. public bool HasArtist(string name)
  50. {
  51. return AllArtists.Contains(name, StringComparer.OrdinalIgnoreCase);
  52. }
  53. /// <summary>
  54. /// Gets the user data key.
  55. /// </summary>
  56. /// <returns>System.String.</returns>
  57. protected override string CreateUserDataKey()
  58. {
  59. return this.GetProviderId(MetadataProviders.Tmdb) ?? this.GetProviderId(MetadataProviders.Imdb) ?? base.CreateUserDataKey();
  60. }
  61. protected override bool GetBlockUnratedValue(UserPolicy config)
  62. {
  63. return config.BlockUnratedItems.Contains(UnratedItem.Music);
  64. }
  65. public MusicVideoInfo GetLookupInfo()
  66. {
  67. return GetItemLookupInfo<MusicVideoInfo>();
  68. }
  69. public override bool BeforeMetadataRefresh()
  70. {
  71. var hasChanges = base.BeforeMetadataRefresh();
  72. if (!ProductionYear.HasValue)
  73. {
  74. var info = LibraryManager.ParseName(Name);
  75. var yearInName = info.Year;
  76. if (yearInName.HasValue)
  77. {
  78. ProductionYear = yearInName;
  79. hasChanges = true;
  80. }
  81. else
  82. {
  83. // Try to get the year from the folder name
  84. if (!IsInMixedFolder)
  85. {
  86. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  87. yearInName = info.Year;
  88. if (yearInName.HasValue)
  89. {
  90. ProductionYear = yearInName;
  91. hasChanges = true;
  92. }
  93. }
  94. }
  95. }
  96. return hasChanges;
  97. }
  98. }
  99. }