MusicVideo.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #nullable disable
  2. #pragma warning disable CS1591
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text.Json.Serialization;
  6. using Jellyfin.Data.Enums;
  7. using MediaBrowser.Controller.Entities.Audio;
  8. using MediaBrowser.Controller.Providers;
  9. namespace MediaBrowser.Controller.Entities
  10. {
  11. public class MusicVideo : Video, IHasArtist, IHasMusicGenres, IHasLookupInfo<MusicVideoInfo>
  12. {
  13. public MusicVideo()
  14. {
  15. Artists = Array.Empty<string>();
  16. }
  17. /// <inheritdoc />
  18. [JsonIgnore]
  19. public IReadOnlyList<string> Artists { get; set; }
  20. public override UnratedItem GetBlockUnratedType()
  21. {
  22. return UnratedItem.Music;
  23. }
  24. public MusicVideoInfo GetLookupInfo()
  25. {
  26. var info = GetItemLookupInfo<MusicVideoInfo>();
  27. info.Artists = Artists;
  28. return info;
  29. }
  30. public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
  31. {
  32. var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
  33. if (!ProductionYear.HasValue)
  34. {
  35. var info = LibraryManager.ParseName(Name);
  36. var yearInName = info.Year;
  37. if (yearInName.HasValue)
  38. {
  39. ProductionYear = yearInName;
  40. hasChanges = true;
  41. }
  42. else
  43. {
  44. // Try to get the year from the folder name
  45. if (!IsInMixedFolder)
  46. {
  47. info = LibraryManager.ParseName(System.IO.Path.GetFileName(ContainingFolderPath));
  48. yearInName = info.Year;
  49. if (yearInName.HasValue)
  50. {
  51. ProductionYear = yearInName;
  52. hasChanges = true;
  53. }
  54. }
  55. }
  56. }
  57. return hasChanges;
  58. }
  59. }
  60. }