MusicVideo.cs 1.9 KB

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