From e62b663ae049548b5f2169a9fbf984f1fa539183 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 12 Mar 2015 11:51:48 -0400 Subject: [PATCH] remove more reliance on ActiveService --- MediaBrowser.Controller/LiveTv/ILiveTvItem.cs | 8 ++ .../LiveTv/ILiveTvRecording.cs | 4 +- .../LiveTv/LiveTvChannel.cs | 6 +- .../LiveTv/LiveTvProgram.cs | 2 +- .../LiveTv/RecordingGroup.cs | 1 - .../MediaBrowser.Controller.csproj | 1 + MediaBrowser.Model/LiveTv/LiveTvInfo.cs | 18 --- MediaBrowser.Model/LiveTv/LiveTvOptions.cs | 1 - .../LiveTv/LiveTvManager.cs | 112 +++++------------- .../Localization/JavaScript/javascript.json | 1 + .../Localization/Server/server.json | 3 +- 11 files changed, 50 insertions(+), 107 deletions(-) create mode 100644 MediaBrowser.Controller/LiveTv/ILiveTvItem.cs diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvItem.cs b/MediaBrowser.Controller/LiveTv/ILiveTvItem.cs new file mode 100644 index 0000000000..d3334e8ea0 --- /dev/null +++ b/MediaBrowser.Controller/LiveTv/ILiveTvItem.cs @@ -0,0 +1,8 @@ + +namespace MediaBrowser.Controller.LiveTv +{ + public interface ILiveTvItem + { + string ServiceName { get; set; } + } +} diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvRecording.cs b/MediaBrowser.Controller/LiveTv/ILiveTvRecording.cs index 3a0045f4b4..93e1e576ac 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvRecording.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvRecording.cs @@ -7,10 +7,8 @@ using System.Threading.Tasks; namespace MediaBrowser.Controller.LiveTv { - public interface ILiveTvRecording : IHasImages, IHasMediaSources, IHasUserData + public interface ILiveTvRecording : IHasImages, IHasMediaSources, IHasUserData, ILiveTvItem { - string ServiceName { get; set; } - string MediaType { get; } string Container { get; } diff --git a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs index eaea6cfa45..75e418bcc9 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs @@ -11,7 +11,7 @@ using System.Runtime.Serialization; namespace MediaBrowser.Controller.LiveTv { - public class LiveTvChannel : BaseItem, IHasMediaSources + public class LiveTvChannel : BaseItem, IHasMediaSources, ILiveTvItem { /// /// Gets the user data key. @@ -58,6 +58,10 @@ namespace MediaBrowser.Controller.LiveTv /// The type of the channel. public ChannelType ChannelType { get; set; } + /// + /// Gets or sets the name of the service. + /// + /// The name of the service. public string ServiceName { get; set; } /// diff --git a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs index ee85ce20b0..2f9673db20 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace MediaBrowser.Controller.LiveTv { - public class LiveTvProgram : BaseItem + public class LiveTvProgram : BaseItem, ILiveTvItem { /// /// Gets the user data key. diff --git a/MediaBrowser.Controller/LiveTv/RecordingGroup.cs b/MediaBrowser.Controller/LiveTv/RecordingGroup.cs index d7250d9d2f..175cf162b4 100644 --- a/MediaBrowser.Controller/LiveTv/RecordingGroup.cs +++ b/MediaBrowser.Controller/LiveTv/RecordingGroup.cs @@ -1,5 +1,4 @@ using MediaBrowser.Controller.Entities; -using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Users; namespace MediaBrowser.Controller.LiveTv diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 314b981d52..f046c76fc9 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -185,6 +185,7 @@ + diff --git a/MediaBrowser.Model/LiveTv/LiveTvInfo.cs b/MediaBrowser.Model/LiveTv/LiveTvInfo.cs index dd31c5a6bd..f4d3e21d98 100644 --- a/MediaBrowser.Model/LiveTv/LiveTvInfo.cs +++ b/MediaBrowser.Model/LiveTv/LiveTvInfo.cs @@ -10,12 +10,6 @@ namespace MediaBrowser.Model.LiveTv /// The services. public List Services { get; set; } - /// - /// Gets or sets the name of the active service. - /// - /// The name of the active service. - public string ActiveServiceName { get; set; } - /// /// Gets or sets a value indicating whether this instance is enabled. /// @@ -28,18 +22,6 @@ namespace MediaBrowser.Model.LiveTv /// The enabled users. public List EnabledUsers { get; set; } - /// - /// Gets or sets the status. - /// - /// The status. - public LiveTvServiceStatus Status { get; set; } - - /// - /// Gets or sets the status message. - /// - /// The status message. - public string StatusMessage { get; set; } - public LiveTvInfo() { Services = new List(); diff --git a/MediaBrowser.Model/LiveTv/LiveTvOptions.cs b/MediaBrowser.Model/LiveTv/LiveTvOptions.cs index 05fdc00b12..32a9c8d12b 100644 --- a/MediaBrowser.Model/LiveTv/LiveTvOptions.cs +++ b/MediaBrowser.Model/LiveTv/LiveTvOptions.cs @@ -3,6 +3,5 @@ public class LiveTvOptions { public int? GuideDays { get; set; } - public string ActiveService { get; set; } } } \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 14a2b08a76..ec5ac3caea 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -103,27 +103,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv { _services.AddRange(services); - SetActiveService(GetConfiguration().ActiveService); - } + ActiveService = _services.FirstOrDefault(); - private void SetActiveService(string name) - { - var service = _services.FirstOrDefault(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase)) ?? - _services.FirstOrDefault(); - - SetActiveService(service); - } - - private void SetActiveService(ILiveTvService service) - { - if (ActiveService != null) - { - ActiveService.DataSourceChanged -= service_DataSourceChanged; - } - - ActiveService = service; - - if (service != null) + foreach (var service in _services) { service.DataSourceChanged += service_DataSourceChanged; } @@ -324,13 +306,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv public async Task GetInternalRecording(string id, CancellationToken cancellationToken) { - var service = ActiveService; + var result = await GetInternalRecordings(new RecordingQuery + { + Id = id - var recordings = await service.GetRecordingsAsync(cancellationToken).ConfigureAwait(false); + }, cancellationToken).ConfigureAwait(false); - var recording = recordings.FirstOrDefault(i => _tvDtoService.GetInternalRecordingId(service.Name, i.Id) == new Guid(id)); - - return await GetRecording(recording, service.Name, cancellationToken).ConfigureAwait(false); + return result.Items.FirstOrDefault() as ILiveTvRecording; } private readonly SemaphoreSlim _liveStreamSemaphore = new SemaphoreSlim(1, 1); @@ -345,29 +327,38 @@ namespace MediaBrowser.Server.Implementations.LiveTv return await GetLiveStream(id, true, cancellationToken).ConfigureAwait(false); } + private ILiveTvService GetService(ILiveTvItem item) + { + return GetService(item.ServiceName); + } + + private ILiveTvService GetService(string name) + { + return _services.FirstOrDefault(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase)); + } + private async Task GetLiveStream(string id, bool isChannel, CancellationToken cancellationToken) { await _liveStreamSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); try { - var service = ActiveService; ChannelMediaInfo info; if (isChannel) { var channel = GetInternalChannel(id); + var service = GetService(channel); _logger.Info("Opening channel stream from {0}, external channel Id: {1}", service.Name, channel.ExternalId); - info = await service.GetChannelStream(channel.ExternalId, cancellationToken).ConfigureAwait(false); } else { - var recordings = await service.GetRecordingsAsync(cancellationToken).ConfigureAwait(false); - var recording = recordings.First(i => _tvDtoService.GetInternalRecordingId(service.Name, i.Id) == new Guid(id)); + var recording = await GetInternalRecording(id, cancellationToken).ConfigureAwait(false); + var service = GetService(recording); - _logger.Info("Opening recording stream from {0}, external recording Id: {1}", service.Name, recording.Id); - info = await service.GetRecordingStream(recording.Id, cancellationToken).ConfigureAwait(false); + _logger.Info("Opening recording stream from {0}, external recording Id: {1}", service.Name, recording.RecordingInfo.Id); + info = await service.GetRecordingStream(recording.RecordingInfo.Id, cancellationToken).ConfigureAwait(false); } _logger.Info("Live stream info: {0}", _jsonSerializer.SerializeToString(info)); @@ -668,13 +659,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv if (query.ChannelIdList.Length > 0) { var guids = query.ChannelIdList.Select(i => new Guid(i)).ToList(); - var serviceName = ActiveService.Name; programs = programs.Where(i => { var programChannelId = i.ExternalChannelId; - var internalProgramChannelId = _tvDtoService.GetInternalChannelId(serviceName, programChannelId); + var service = GetService(i); + var internalProgramChannelId = _tvDtoService.GetInternalChannelId(service.Name, programChannelId); return guids.Contains(internalProgramChannelId); }); @@ -1030,14 +1021,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv private async Task DeleteOldPrograms(List currentIdList, IProgress progress, CancellationToken cancellationToken) { - var service = ActiveService; - - if (service == null) - { - progress.Report(100); - return; - } - var list = _itemRepo.GetItemsOfType(typeof(LiveTvProgram)).ToList(); var numComplete = 0; @@ -1223,28 +1206,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv return Task.WhenAll(tasks); } - private IEnumerable GetServices(string serviceName, string channelId) - { - IEnumerable services = _services; - - if (string.IsNullOrEmpty(serviceName) && !string.IsNullOrEmpty(channelId)) - { - var channel = GetInternalChannel(channelId); - - if (channel != null) - { - serviceName = channel.ServiceName; - } - } - - if (!string.IsNullOrEmpty(serviceName)) - { - services = services.Where(i => string.Equals(i.Name, serviceName, StringComparison.OrdinalIgnoreCase)); - } - - return services; - } - public async Task> GetTimers(TimerQuery query, CancellationToken cancellationToken) { var service = ActiveService; @@ -1299,8 +1260,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv throw new ResourceNotFoundException(string.Format("Recording with Id {0} not found", recordingId)); } - var service = GetServices(recording.ServiceName, null) - .First(); + var service = GetService(recording.ServiceName); await service.DeleteRecordingAsync(recording.ExternalId, CancellationToken.None).ConfigureAwait(false); } @@ -1314,8 +1274,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv throw new ResourceNotFoundException(string.Format("Timer with Id {0} not found", id)); } - var service = GetServices(timer.ServiceName, null) - .First(); + var service = GetService(timer.ServiceName); await service.CancelTimerAsync(timer.ExternalId, CancellationToken.None).ConfigureAwait(false); } @@ -1329,8 +1288,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv throw new ResourceNotFoundException(string.Format("Timer with Id {0} not found", id)); } - var service = GetServices(timer.ServiceName, null) - .First(); + var service = GetService(timer.ServiceName); await service.CancelSeriesTimerAsync(timer.ExternalId, CancellationToken.None).ConfigureAwait(false); } @@ -1518,7 +1476,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv public async Task CreateTimer(TimerInfoDto timer, CancellationToken cancellationToken) { - var service = string.IsNullOrEmpty(timer.ServiceName) ? ActiveService : GetServices(timer.ServiceName, null).First(); + var service = GetService(timer.ServiceName); var info = await _tvDtoService.GetTimerInfo(timer, true, this, cancellationToken).ConfigureAwait(false); @@ -1531,7 +1489,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv public async Task CreateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken) { - var service = string.IsNullOrEmpty(timer.ServiceName) ? ActiveService : GetServices(timer.ServiceName, null).First(); + var service = GetService(timer.ServiceName); var info = await _tvDtoService.GetSeriesTimerInfo(timer, true, this, cancellationToken).ConfigureAwait(false); @@ -1546,7 +1504,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv { var info = await _tvDtoService.GetTimerInfo(timer, false, this, cancellationToken).ConfigureAwait(false); - var service = string.IsNullOrEmpty(timer.ServiceName) ? ActiveService : GetServices(timer.ServiceName, null).First(); + var service = GetService(timer.ServiceName); await service.UpdateTimerAsync(info, cancellationToken).ConfigureAwait(false); } @@ -1555,7 +1513,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv { var info = await _tvDtoService.GetSeriesTimerInfo(timer, false, this, cancellationToken).ConfigureAwait(false); - var service = string.IsNullOrEmpty(timer.ServiceName) ? ActiveService : GetServices(timer.ServiceName, null).First(); + var service = GetService(timer.ServiceName); await service.UpdateSeriesTimerAsync(info, cancellationToken).ConfigureAwait(false); } @@ -1821,16 +1779,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv var services = await GetServiceInfos(CancellationToken.None).ConfigureAwait(false); var servicesList = services.ToList(); - var activeServiceInfo = ActiveService == null ? null : - servicesList.FirstOrDefault(i => string.Equals(i.Name, ActiveService.Name, StringComparison.OrdinalIgnoreCase)); - var info = new LiveTvInfo { Services = servicesList.ToList(), - ActiveServiceName = activeServiceInfo == null ? null : activeServiceInfo.Name, - IsEnabled = ActiveService != null, - Status = activeServiceInfo == null ? LiveTvServiceStatus.Unavailable : activeServiceInfo.Status, - StatusMessage = activeServiceInfo == null ? null : activeServiceInfo.StatusMessage + IsEnabled = servicesList.Count > 0 }; info.EnabledUsers = _userManager.Users diff --git a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json index 616f8863cb..0c890e6261 100644 --- a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json +++ b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json @@ -586,6 +586,7 @@ "ValuePremieres": "Premieres {0}", "ValueStudio": "Studio: {0}", "ValueStudios": "Studios: {0}", + "ValueStatus": "Status: {0}", "ValueSpecialEpisodeName": "Special - {0}", "LabelLimit": "Limit:", "ValueLinks": "Links: {0}", diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index d6fe5bb974..9464309b70 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -415,9 +415,8 @@ "TitleLiveTV": "Live TV", "LabelNumberOfGuideDays": "Number of days of guide data to download:", "LabelNumberOfGuideDaysHelp": "Downloading more days worth of guide data provides the ability to schedule out further in advance and view more listings, but it will also take longer to download. Auto will choose based on the number of channels.", - "LabelActiveService": "Active Service:", - "LabelActiveServiceHelp": "Multiple tv plugins can be installed but only one can be active at a time.", "OptionAutomatic": "Auto", + "HeaderServices": "Services", "LiveTvPluginRequired": "A Live TV service provider plugin is required in order to continue.", "LiveTvPluginRequiredHelp": "Please install one of our available plugins, such as Next Pvr or ServerWmc.", "LabelCustomizeOptionsPerMediaType": "Customize for media type:",