IHasTrailers.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /// <returns><see cref="IReadOnlyList{Guid}" />.</returns>
  36. public static int GetTrailerCount(this IHasTrailers item)
  37. => item.LocalTrailerIds.Count + item.RemoteTrailerIds.Count;
  38. /// <summary>
  39. /// Gets the trailer ids.
  40. /// </summary>
  41. /// <returns><see cref="IReadOnlyList{Guid}" />.</returns>
  42. public static IReadOnlyList<Guid> GetTrailerIds(this IHasTrailers item)
  43. {
  44. var localIds = item.LocalTrailerIds;
  45. var remoteIds = item.RemoteTrailerIds;
  46. var all = new Guid[localIds.Count + remoteIds.Count];
  47. var index = 0;
  48. foreach (var id in localIds)
  49. {
  50. all[index++] = id;
  51. }
  52. foreach (var id in remoteIds)
  53. {
  54. all[index++] = id;
  55. }
  56. return all;
  57. }
  58. /// <summary>
  59. /// Gets the trailers.
  60. /// </summary>
  61. /// <returns><see cref="IReadOnlyList{BaseItem}" />.</returns>
  62. public static IReadOnlyList<BaseItem> GetTrailers(this IHasTrailers item)
  63. {
  64. var localIds = item.LocalTrailerIds;
  65. var remoteIds = item.RemoteTrailerIds;
  66. var libraryManager = BaseItem.LibraryManager;
  67. var all = new BaseItem[localIds.Count + remoteIds.Count];
  68. var index = 0;
  69. foreach (var id in localIds)
  70. {
  71. all[index++] = libraryManager.GetItemById(id);
  72. }
  73. foreach (var id in remoteIds)
  74. {
  75. all[index++] = libraryManager.GetItemById(id);
  76. }
  77. return all;
  78. }
  79. }
  80. }