2
0

Extensions.cs 1.2 KB

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