diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index 319470554..9d827226c 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -106,6 +106,14 @@ namespace MediaBrowser.Api.LiveTv public string UserId { get; set; } } + [Route("/LiveTv/Tuners/{Id}/Reset", "POST")] + [Api(Description = "Resets a tv tuner")] + public class ResetTuner : IReturnVoid + { + [ApiMember(Name = "Id", Description = "Tuner Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string Id { get; set; } + } + [Route("/LiveTv/Timers/{Id}", "GET")] [Api(Description = "Gets a live tv timer")] public class GetTimer : IReturn @@ -294,25 +302,7 @@ namespace MediaBrowser.Api.LiveTv public object Get(GetLiveTvInfo request) { - var services = _liveTvManager.GetServiceInfos(CancellationToken.None).Result; - var servicesList = services.ToList(); - - var activeServiceInfo = _liveTvManager.ActiveService == null ? null : - servicesList.FirstOrDefault(i => string.Equals(i.Name, _liveTvManager.ActiveService.Name, StringComparison.OrdinalIgnoreCase)); - - var info = new LiveTvInfo - { - Services = servicesList.ToList(), - ActiveServiceName = activeServiceInfo == null ? null : activeServiceInfo.Name, - IsEnabled = _liveTvManager.ActiveService != null, - Status = activeServiceInfo == null ? LiveTvServiceStatus.Unavailable : activeServiceInfo.Status, - StatusMessage = activeServiceInfo == null ? null : activeServiceInfo.StatusMessage - }; - - info.EnabledUsers = _userManager.Users - .Where(i => i.Configuration.EnableLiveTvAccess && info.IsEnabled) - .Select(i => i.Id.ToString("N")) - .ToList(); + var info = _liveTvManager.GetLiveTvInfo(CancellationToken.None).Result; return ToOptimizedResult(info); } @@ -573,5 +563,14 @@ namespace MediaBrowser.Api.LiveTv { return ToOptimizedResult(_liveTvManager.GetGuideInfo()); } + + public void Post(ResetTuner request) + { + AssertUserCanManageLiveTv(); + + var task = _liveTvManager.ResetTuner(request.Id, CancellationToken.None); + + Task.WaitAll(task); + } } } \ No newline at end of file diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index 88e2c9b4e..ad42c5091 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -24,13 +24,6 @@ namespace MediaBrowser.Controller.LiveTv /// The services. IReadOnlyList Services { get; } - /// - /// Gets the service infos. - /// - /// The cancellation token. - /// Task{IEnumerable{LiveTvServiceInfo}}. - Task> GetServiceInfos(CancellationToken cancellationToken); - /// /// Gets the new timer defaults asynchronous. /// @@ -256,5 +249,20 @@ namespace MediaBrowser.Controller.LiveTv /// Task{QueryResult{ProgramInfoDto}}. Task> GetRecommendedPrograms(RecommendedProgramQuery query, CancellationToken cancellationToken); + + /// + /// Gets the live tv information. + /// + /// The cancellation token. + /// Task{LiveTvInfo}. + Task GetLiveTvInfo(CancellationToken cancellationToken); + + /// + /// Resets the tuner. + /// + /// The identifier. + /// The cancellation token. + /// Task. + Task ResetTuner(string id, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.cs b/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.cs index 38ce50a1b..e764e679b 100644 --- a/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.cs +++ b/MediaBrowser.Model/LiveTv/LiveTvServiceInfo.cs @@ -43,6 +43,13 @@ namespace MediaBrowser.Model.LiveTv /// /// true if this instance has update available; otherwise, false. public bool HasUpdateAvailable { get; set; } + + public List Tuners { get; set; } + + public LiveTvServiceInfo() + { + Tuners = new List(); + } } public class GuideInfo @@ -105,6 +112,62 @@ namespace MediaBrowser.Model.LiveTv } } + public class LiveTvTunerInfoDto + { + /// + /// Gets or sets the type of the source. + /// + /// The type of the source. + public string SourceType { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + + /// + /// Gets or sets the identifier. + /// + /// The identifier. + public string Id { get; set; } + + /// + /// Gets or sets the status. + /// + /// The status. + public LiveTvTunerStatus Status { get; set; } + + /// + /// Gets or sets the channel identifier. + /// + /// The channel identifier. + public string ChannelId { get; set; } + + /// + /// Gets or sets the recording identifier. + /// + /// The recording identifier. + public string RecordingId { get; set; } + + /// + /// Gets or sets the name of the program. + /// + /// The name of the program. + public string ProgramName { get; set; } + + /// + /// Gets or sets the clients. + /// + /// The clients. + public List Clients { get; set; } + + public LiveTvTunerInfoDto() + { + Clients = new List(); + } + } + public enum LiveTvServiceStatus { Ok = 0, diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs index 094506199..5b25e259a 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs @@ -224,7 +224,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery { - ItemId = recording.Id + ItemId = recording.Id }).ToList() }; @@ -271,6 +271,31 @@ namespace MediaBrowser.Server.Implementations.LiveTv return dto; } + public LiveTvTunerInfoDto GetTunerInfoDto(string serviceName, LiveTvTunerInfo info) + { + var dto = new LiveTvTunerInfoDto + { + Name = info.Name, + Id = info.Id, + Clients = info.Clients, + ProgramName = info.ProgramName, + SourceType = info.SourceType, + Status = info.Status + }; + + if (!string.IsNullOrEmpty(info.ChannelId)) + { + dto.ChannelId = GetInternalChannelId(serviceName, info.ChannelId).ToString("N"); + } + + if (!string.IsNullOrEmpty(info.RecordingId)) + { + dto.RecordingId = GetInternalRecordingId(serviceName, info.RecordingId).ToString("N"); + } + + return dto; + } + /// /// Gets the channel info dto. /// diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 92df78fb9..0d2f323b4 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1,7 +1,6 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Common.ScheduledTasks; -using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; @@ -1412,7 +1411,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv } } - public async Task> GetServiceInfos(CancellationToken cancellationToken) + private async Task> GetServiceInfos(CancellationToken cancellationToken) { var tasks = Services.Select(i => GetServiceInfo(i, cancellationToken)); @@ -1435,6 +1434,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv info.Version = statusInfo.Version; info.HasUpdateAvailable = statusInfo.HasUpdateAvailable; info.HomePageUrl = service.HomePageUrl; + + info.Tuners = statusInfo.Tuners.Select(i => _tvDtoService.GetTunerInfoDto(service.Name, i)).ToList(); } catch (Exception ex) { @@ -1446,5 +1447,41 @@ namespace MediaBrowser.Server.Implementations.LiveTv return info; } + + public async Task GetLiveTvInfo(CancellationToken cancellationToken) + { + 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 + }; + + info.EnabledUsers = _userManager.Users + .Where(i => i.Configuration.EnableLiveTvAccess && info.IsEnabled) + .Select(i => i.Id.ToString("N")) + .ToList(); + + return info; + } + + /// + /// Resets the tuner. + /// + /// The identifier. + /// The cancellation token. + /// Task. + public Task ResetTuner(string id, CancellationToken cancellationToken) + { + return ActiveService.ResetTuner(id, cancellationToken); + } } } diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js index 7a90b12c9..375aacbce 100644 --- a/MediaBrowser.WebDashboard/ApiClient.js +++ b/MediaBrowser.WebDashboard/ApiClient.js @@ -655,6 +655,20 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi }); }; + self.resetLiveTvTuner = function (id) { + + if (!id) { + throw new Error("null id"); + } + + var url = self.getUrl("LiveTv/Tuners/" + id + "/Reset"); + + return self.ajax({ + type: "POST", + url: url + }); + }; + self.getLiveTvSeriesTimers = function (options) { var url = self.getUrl("LiveTv/SeriesTimers", options || {}); diff --git a/MediaBrowser.WebDashboard/packages.config b/MediaBrowser.WebDashboard/packages.config index d1427603d..4957f3563 100644 --- a/MediaBrowser.WebDashboard/packages.config +++ b/MediaBrowser.WebDashboard/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index d239c4348..175ca99c4 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.307 + 3.0.308 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 329ae9ec9..f4cafce40 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.307 + 3.0.308 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 62323d1b3..dea375326 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.307 + 3.0.308 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +