ChannelVideoItem.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Model.Channels;
  3. using MediaBrowser.Model.Configuration;
  4. using MediaBrowser.Model.Dto;
  5. using MediaBrowser.Model.Entities;
  6. using System.Collections.Generic;
  7. using System.Globalization;
  8. using System.Linq;
  9. using System.Runtime.Serialization;
  10. using System.Threading;
  11. namespace MediaBrowser.Controller.Channels
  12. {
  13. public class ChannelVideoItem : Video
  14. {
  15. public ChannelMediaContentType ContentType { get; set; }
  16. public List<ChannelMediaInfo> ChannelMediaSources { get; set; }
  17. protected override string CreateUserDataKey()
  18. {
  19. if (ContentType == ChannelMediaContentType.MovieExtra)
  20. {
  21. var key = this.GetProviderId(MetadataProviders.Imdb) ?? this.GetProviderId(MetadataProviders.Tmdb);
  22. if (!string.IsNullOrWhiteSpace(key))
  23. {
  24. key = key + "-" + ExtraType.ToString().ToLower();
  25. // Make sure different trailers have their own data.
  26. if (RunTimeTicks.HasValue)
  27. {
  28. key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
  29. }
  30. return key;
  31. }
  32. }
  33. return ExternalId;
  34. }
  35. public override UnratedItem GetBlockUnratedType()
  36. {
  37. return UnratedItem.ChannelContent;
  38. }
  39. [IgnoreDataMember]
  40. public override bool SupportsLocalMetadata
  41. {
  42. get
  43. {
  44. return false;
  45. }
  46. }
  47. public override bool IsSaveLocalMetadataEnabled()
  48. {
  49. return false;
  50. }
  51. public ChannelVideoItem()
  52. {
  53. ChannelMediaSources = new List<ChannelMediaInfo>();
  54. }
  55. [IgnoreDataMember]
  56. public override LocationType LocationType
  57. {
  58. get
  59. {
  60. if (string.IsNullOrEmpty(Path))
  61. {
  62. return LocationType.Remote;
  63. }
  64. return base.LocationType;
  65. }
  66. }
  67. public override IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  68. {
  69. var sources = ChannelManager.GetStaticMediaSources(this, false, CancellationToken.None)
  70. .Result.ToList();
  71. if (sources.Count > 0)
  72. {
  73. return sources;
  74. }
  75. var list = base.GetMediaSources(enablePathSubstitution).ToList();
  76. foreach (var mediaSource in list)
  77. {
  78. if (string.IsNullOrWhiteSpace(mediaSource.Path))
  79. {
  80. mediaSource.Type = MediaSourceType.Placeholder;
  81. }
  82. }
  83. return list;
  84. }
  85. protected override string GetInternalMetadataPath(string basePath)
  86. {
  87. return System.IO.Path.Combine(basePath, "channels", ChannelId, Id.ToString("N"));
  88. }
  89. public override bool CanDelete()
  90. {
  91. return false;
  92. }
  93. public override bool IsVisibleStandalone(User user)
  94. {
  95. return IsVisibleStandaloneInternal(user, false) && IsChannelVisible(this, user);
  96. }
  97. internal static bool IsChannelVisible(BaseItem item, User user)
  98. {
  99. var channel = ChannelManager.GetChannel(item.ChannelId);
  100. return channel.IsVisible(user);
  101. }
  102. }
  103. }