IHasTrailers.cs 2.9 KB

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