Extensions.cs 1.1 KB

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