IHasTrailers.cs 2.7 KB

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