Extensions.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #nullable disable
  2. using System;
  3. using System.Linq;
  4. using Jellyfin.Extensions;
  5. using MediaBrowser.Model.Entities;
  6. namespace MediaBrowser.Controller.Entities
  7. {
  8. /// <summary>
  9. /// Class Extensions.
  10. /// </summary>
  11. public static class Extensions
  12. {
  13. /// <summary>
  14. /// Adds the trailer URL.
  15. /// </summary>
  16. public static void AddTrailerUrl(this BaseItem item, string url)
  17. {
  18. if (string.IsNullOrEmpty(url))
  19. {
  20. throw new ArgumentNullException(nameof(url));
  21. }
  22. var current = item.RemoteTrailers.FirstOrDefault(i => string.Equals(i.Url, url, StringComparison.OrdinalIgnoreCase));
  23. if (current == null)
  24. {
  25. var mediaUrl = new MediaUrl
  26. {
  27. Url = url
  28. };
  29. if (item.RemoteTrailers.Count == 0)
  30. {
  31. item.RemoteTrailers = new[] { mediaUrl };
  32. }
  33. else
  34. {
  35. var oldIds = item.RemoteTrailers;
  36. var newIds = new MediaUrl[oldIds.Count + 1];
  37. oldIds.CopyTo(newIds);
  38. newIds[oldIds.Count] = mediaUrl;
  39. item.RemoteTrailers = newIds;
  40. }
  41. }
  42. }
  43. }
  44. }