From bd2ea703e31522d505407a33089b95f997f6b062 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 28 Mar 2015 16:22:27 -0400 Subject: implement modular media sources --- .../Channels/ChannelAudioItem.cs | 16 ++++++++++----- .../Channels/ChannelVideoItem.cs | 16 ++++++++++----- .../Channels/IChannelManager.cs | 6 +++--- .../Library/IMediaSourceManager.cs | 24 ++++++++++++++++++++++ .../Library/IMediaSourceProvider.cs | 16 +++++++++++++++ MediaBrowser.Controller/LiveTv/ILiveTvItem.cs | 4 +++- .../LiveTv/LiveTvAudioRecording.cs | 21 +++++++++++++++++-- MediaBrowser.Controller/LiveTv/LiveTvChannel.cs | 2 +- .../LiveTv/LiveTvVideoRecording.cs | 23 ++++++++++++++++++--- 9 files changed, 108 insertions(+), 20 deletions(-) (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Channels/ChannelAudioItem.cs b/MediaBrowser.Controller/Channels/ChannelAudioItem.cs index 91b2407be..8d9024676 100644 --- a/MediaBrowser.Controller/Channels/ChannelAudioItem.cs +++ b/MediaBrowser.Controller/Channels/ChannelAudioItem.cs @@ -75,17 +75,23 @@ namespace MediaBrowser.Controller.Channels public override IEnumerable GetMediaSources(bool enablePathSubstitution) { - var list = base.GetMediaSources(enablePathSubstitution).ToList(); - - var sources = ChannelManager.GetChannelItemMediaSources(Id.ToString("N"), false, CancellationToken.None) - .Result.ToList(); + var sources = ChannelManager.GetStaticMediaSources(this, false, CancellationToken.None) + .Result.ToList(); if (sources.Count > 0) { return sources; } - list.InsertRange(0, sources); + var list = base.GetMediaSources(enablePathSubstitution).ToList(); + + foreach (var mediaSource in list) + { + if (string.IsNullOrWhiteSpace(mediaSource.Path)) + { + mediaSource.Type = MediaSourceType.Placeholder; + } + } return list; } diff --git a/MediaBrowser.Controller/Channels/ChannelVideoItem.cs b/MediaBrowser.Controller/Channels/ChannelVideoItem.cs index d7d4483cd..8eec2021b 100644 --- a/MediaBrowser.Controller/Channels/ChannelVideoItem.cs +++ b/MediaBrowser.Controller/Channels/ChannelVideoItem.cs @@ -90,17 +90,23 @@ namespace MediaBrowser.Controller.Channels public override IEnumerable GetMediaSources(bool enablePathSubstitution) { - var list = base.GetMediaSources(enablePathSubstitution).ToList(); - - var sources = ChannelManager.GetChannelItemMediaSources(Id.ToString("N"), false, CancellationToken.None) - .Result.ToList(); + var sources = ChannelManager.GetStaticMediaSources(this, false, CancellationToken.None) + .Result.ToList(); if (sources.Count > 0) { return sources; } - list.InsertRange(0, sources); + var list = base.GetMediaSources(enablePathSubstitution).ToList(); + + foreach (var mediaSource in list) + { + if (string.IsNullOrWhiteSpace(mediaSource.Path)) + { + mediaSource.Type = MediaSourceType.Placeholder; + } + } return list; } diff --git a/MediaBrowser.Controller/Channels/IChannelManager.cs b/MediaBrowser.Controller/Channels/IChannelManager.cs index 05015da37..f5c4ab373 100644 --- a/MediaBrowser.Controller/Channels/IChannelManager.cs +++ b/MediaBrowser.Controller/Channels/IChannelManager.cs @@ -112,11 +112,11 @@ namespace MediaBrowser.Controller.Channels /// /// Gets the channel item media sources. /// - /// The identifier. - /// if set to true [include dynamic sources]. + /// The item. + /// if set to true [include cached versions]. /// The cancellation token. /// Task{IEnumerable{MediaSourceInfo}}. - Task> GetChannelItemMediaSources(string id, bool includeDynamicSources, CancellationToken cancellationToken); + Task> GetStaticMediaSources(IChannelMediaItem item, bool includeCachedVersions, CancellationToken cancellationToken); /// /// Gets the channel folder. diff --git a/MediaBrowser.Controller/Library/IMediaSourceManager.cs b/MediaBrowser.Controller/Library/IMediaSourceManager.cs index c21fed6fc..fda17aa27 100644 --- a/MediaBrowser.Controller/Library/IMediaSourceManager.cs +++ b/MediaBrowser.Controller/Library/IMediaSourceManager.cs @@ -64,6 +64,14 @@ namespace MediaBrowser.Controller.Library /// IEnumerable<MediaSourceInfo>. IEnumerable GetStaticMediaSources(IHasMediaSources item, bool enablePathSubstitution, User user); + /// + /// Gets the static media sources. + /// + /// The item. + /// if set to true [enable path substitution]. + /// IEnumerable<MediaSourceInfo>. + IEnumerable GetStaticMediaSources(IHasMediaSources item, bool enablePathSubstitution); + /// /// Gets the static media source. /// @@ -72,5 +80,21 @@ namespace MediaBrowser.Controller.Library /// if set to true [enable path substitution]. /// MediaSourceInfo. MediaSourceInfo GetStaticMediaSource(IHasMediaSources item, string mediaSourceId, bool enablePathSubstitution); + + /// + /// Opens the media source. + /// + /// The open key. + /// The cancellation token. + /// Task<MediaSourceInfo>. + Task OpenMediaSource(string openKey, CancellationToken cancellationToken); + + /// + /// Closes the media source. + /// + /// The close key. + /// The cancellation token. + /// Task. + Task CloseMediaSource(string closeKey, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Controller/Library/IMediaSourceProvider.cs b/MediaBrowser.Controller/Library/IMediaSourceProvider.cs index 461285d6c..c5f5b5401 100644 --- a/MediaBrowser.Controller/Library/IMediaSourceProvider.cs +++ b/MediaBrowser.Controller/Library/IMediaSourceProvider.cs @@ -15,5 +15,21 @@ namespace MediaBrowser.Controller.Library /// The cancellation token. /// Task<IEnumerable<MediaSourceInfo>>. Task> GetMediaSources(IHasMediaSources item, CancellationToken cancellationToken); + + /// + /// Opens the media source. + /// + /// The open key. + /// The cancellation token. + /// Task<MediaSourceInfo>. + Task OpenMediaSource(string openKey, CancellationToken cancellationToken); + + /// + /// Closes the media source. + /// + /// The close key. + /// The cancellation token. + /// Task. + Task CloseMediaSource(string closeKey, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvItem.cs b/MediaBrowser.Controller/LiveTv/ILiveTvItem.cs index d3334e8ea..6c277a2e1 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvItem.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvItem.cs @@ -1,8 +1,10 @@ - +using System; + namespace MediaBrowser.Controller.LiveTv { public interface ILiveTvItem { + Guid Id { get; } string ServiceName { get; set; } } } diff --git a/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs b/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs index 9815066ef..0dc296d5a 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs @@ -1,10 +1,12 @@ -using System.Runtime.Serialization; -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Users; +using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; namespace MediaBrowser.Controller.LiveTv { @@ -99,5 +101,20 @@ namespace MediaBrowser.Controller.LiveTv { return user.Policy.EnableLiveTvManagement; } + + public override IEnumerable GetMediaSources(bool enablePathSubstitution) + { + var list = base.GetMediaSources(enablePathSubstitution).ToList(); + + foreach (var mediaSource in list) + { + if (string.IsNullOrWhiteSpace(mediaSource.Path)) + { + mediaSource.Type = MediaSourceType.Placeholder; + } + } + + return list; + } } } diff --git a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs index 75e418bcc..1e13d8f3f 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs @@ -127,7 +127,7 @@ namespace MediaBrowser.Controller.LiveTv Name = Name, Path = Path, RunTimeTicks = RunTimeTicks, - Type = MediaSourceType.Default + Type = MediaSourceType.Placeholder }; list.Add(info); diff --git a/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs b/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs index 207684d55..3669f9440 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs @@ -1,9 +1,11 @@ -using System.Runtime.Serialization; -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; -using System.Linq; using MediaBrowser.Model.Users; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; namespace MediaBrowser.Controller.LiveTv { @@ -97,5 +99,20 @@ namespace MediaBrowser.Controller.LiveTv { return user.Policy.EnableLiveTvManagement; } + + public override IEnumerable GetMediaSources(bool enablePathSubstitution) + { + var list = base.GetMediaSources(enablePathSubstitution).ToList(); + + foreach (var mediaSource in list) + { + if (string.IsNullOrWhiteSpace(mediaSource.Path)) + { + mediaSource.Type = MediaSourceType.Placeholder; + } + } + + return list; + } } } -- cgit v1.2.3