IHasTrailers.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using MediaBrowser.Model.Entities;
  5. namespace MediaBrowser.Controller.Entities
  6. {
  7. public interface IHasTrailers : IHasProviderIds
  8. {
  9. /// <summary>
  10. /// Gets or sets the remote trailers.
  11. /// </summary>
  12. /// <value>The remote trailers.</value>
  13. IReadOnlyList<MediaUrl> RemoteTrailers { get; set; }
  14. /// <summary>
  15. /// Gets or sets the local trailer ids.
  16. /// </summary>
  17. /// <value>The local trailer ids.</value>
  18. IReadOnlyList<Guid> LocalTrailerIds { get; set; }
  19. /// <summary>
  20. /// Gets or sets the remote trailer ids.
  21. /// </summary>
  22. /// <value>The remote trailer ids.</value>
  23. IReadOnlyList<Guid> RemoteTrailerIds { get; set; }
  24. Guid Id { get; set; }
  25. }
  26. /// <summary>
  27. /// Class providing extension methods for working with <see cref="IHasTrailers" />.
  28. /// </summary>
  29. public static class HasTrailerExtensions
  30. {
  31. /// <summary>
  32. /// Gets the trailer count.
  33. /// </summary>
  34. /// <returns><see cref="IReadOnlyList{Guid}" />.</returns>
  35. public static int GetTrailerCount(this IHasTrailers item)
  36. => item.LocalTrailerIds.Count + item.RemoteTrailerIds.Count;
  37. /// <summary>
  38. /// Gets the trailer ids.
  39. /// </summary>
  40. /// <returns><see cref="IReadOnlyList{Guid}" />.</returns>
  41. public static IReadOnlyList<Guid> GetTrailerIds(this IHasTrailers item)
  42. {
  43. var localIds = item.LocalTrailerIds;
  44. var remoteIds = item.RemoteTrailerIds;
  45. var all = new Guid[localIds.Count + remoteIds.Count];
  46. var index = 0;
  47. foreach (var id in localIds)
  48. {
  49. all[index++] = id;
  50. }
  51. foreach (var id in remoteIds)
  52. {
  53. all[index++] = id;
  54. }
  55. return all;
  56. }
  57. /// <summary>
  58. /// Gets the trailers.
  59. /// </summary>
  60. /// <returns><see cref="IReadOnlyList{BaseItem}" />.</returns>
  61. public static IReadOnlyList<BaseItem> GetTrailers(this IHasTrailers item)
  62. {
  63. var localIds = item.LocalTrailerIds;
  64. var remoteIds = item.RemoteTrailerIds;
  65. var libraryManager = BaseItem.LibraryManager;
  66. var all = new BaseItem[localIds.Count + remoteIds.Count];
  67. var index = 0;
  68. foreach (var id in localIds)
  69. {
  70. all[index++] = libraryManager.GetItemById(id);
  71. }
  72. foreach (var id in remoteIds)
  73. {
  74. all[index++] = libraryManager.GetItemById(id);
  75. }
  76. return all;
  77. }
  78. }
  79. }