Extensions.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. /// <param name="item">Media item.</param>
  17. /// <param name="url">Trailer URL.</param>
  18. public static void AddTrailerUrl(this BaseItem item, string url)
  19. {
  20. if (string.IsNullOrEmpty(url))
  21. {
  22. throw new ArgumentNullException(nameof(url));
  23. }
  24. var current = item.RemoteTrailers.FirstOrDefault(i => string.Equals(i.Url, url, StringComparison.OrdinalIgnoreCase));
  25. if (current == null)
  26. {
  27. var mediaUrl = new MediaUrl
  28. {
  29. Url = url
  30. };
  31. if (item.RemoteTrailers.Count == 0)
  32. {
  33. item.RemoteTrailers = new[] { mediaUrl };
  34. }
  35. else
  36. {
  37. var oldIds = item.RemoteTrailers;
  38. var newIds = new MediaUrl[oldIds.Count + 1];
  39. oldIds.CopyTo(newIds);
  40. newIds[oldIds.Count] = mediaUrl;
  41. item.RemoteTrailers = newIds;
  42. }
  43. }
  44. }
  45. }
  46. }