aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/LiveTv
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-12-17 15:02:12 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-12-17 15:02:12 -0500
commit533a7b218d27683d1db42e57ff971fba190a1f08 (patch)
treeceed803642f38791d09a005d6301bccc746c9b0b /MediaBrowser.Server.Implementations/LiveTv
parentdf1576c0393747cf84a4a4d3f4a93a8c032f5105 (diff)
add ability to create timer
Diffstat (limited to 'MediaBrowser.Server.Implementations/LiveTv')
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs76
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs76
2 files changed, 118 insertions, 34 deletions
diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs
index ab9833662..ea8523887 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs
@@ -1,4 +1,6 @@
-using MediaBrowser.Common.Extensions;
+using System.Threading;
+using System.Threading.Tasks;
+using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
@@ -186,7 +188,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv
Number = info.ChannelNumber,
Type = info.GetType().Name,
Id = info.Id.ToString("N"),
- MediaType = info.MediaType
+ MediaType = info.MediaType,
+ ExternalId = info.ChannelId
};
if (user != null)
@@ -292,50 +295,99 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return name.ToLower().GetMD5();
}
- public TimerInfo GetTimerInfo(TimerInfoDto dto)
+ public async Task<TimerInfo> GetTimerInfo(TimerInfoDto dto, bool isNew, ILiveTvManager liveTv, CancellationToken cancellationToken)
{
- return new TimerInfo
+ var info = new TimerInfo
{
- Id = dto.ExternalId,
ChannelName = dto.ChannelName,
Overview = dto.Overview,
EndDate = dto.EndDate,
Name = dto.Name,
StartDate = dto.StartDate,
- ChannelId = dto.ExternalChannelId,
Status = dto.Status,
SeriesTimerId = dto.ExternalSeriesTimerId,
RequestedPostPaddingSeconds = dto.RequestedPostPaddingSeconds,
RequestedPrePaddingSeconds = dto.RequestedPrePaddingSeconds,
RequiredPostPaddingSeconds = dto.RequiredPostPaddingSeconds,
RequiredPrePaddingSeconds = dto.RequiredPrePaddingSeconds,
- ProgramId = dto.ExternalProgramId,
Priority = dto.Priority
};
+
+ // Convert internal server id's to external tv provider id's
+ if (!isNew && !string.IsNullOrEmpty(dto.Id))
+ {
+ var timer = await liveTv.GetTimer(dto.Id, cancellationToken).ConfigureAwait(false);
+
+ info.Id = timer.ExternalId;
+ }
+
+ if (!string.IsNullOrEmpty(dto.SeriesTimerId))
+ {
+ var timer = await liveTv.GetSeriesTimer(dto.SeriesTimerId, cancellationToken).ConfigureAwait(false);
+
+ info.SeriesTimerId = timer.ExternalId;
+ }
+
+ if (!string.IsNullOrEmpty(dto.ChannelId))
+ {
+ var channel = await liveTv.GetChannel(dto.ChannelId, cancellationToken).ConfigureAwait(false);
+
+ info.ChannelId = channel.ExternalId;
+ }
+
+ if (!string.IsNullOrEmpty(dto.ProgramId))
+ {
+ var program = await liveTv.GetProgram(dto.ProgramId, cancellationToken).ConfigureAwait(false);
+
+ info.ProgramId = program.ExternalId;
+ }
+
+ return info;
}
- public SeriesTimerInfo GetSeriesTimerInfo(SeriesTimerInfoDto dto)
+ public async Task<SeriesTimerInfo> GetSeriesTimerInfo(SeriesTimerInfoDto dto, bool isNew, ILiveTvManager liveTv, CancellationToken cancellationToken)
{
- return new SeriesTimerInfo
+ var info = new SeriesTimerInfo
{
- Id = dto.ExternalId,
ChannelName = dto.ChannelName,
Overview = dto.Overview,
EndDate = dto.EndDate,
Name = dto.Name,
StartDate = dto.StartDate,
- ChannelId = dto.ExternalChannelId,
RequestedPostPaddingSeconds = dto.RequestedPostPaddingSeconds,
RequestedPrePaddingSeconds = dto.RequestedPrePaddingSeconds,
RequiredPostPaddingSeconds = dto.RequiredPostPaddingSeconds,
RequiredPrePaddingSeconds = dto.RequiredPrePaddingSeconds,
Days = dto.Days,
Priority = dto.Priority,
- ProgramId = dto.ExternalProgramId,
RecordAnyChannel = dto.RecordAnyChannel,
RecordAnyTime = dto.RecordAnyTime,
RecordNewOnly = dto.RecordNewOnly
};
+
+ // Convert internal server id's to external tv provider id's
+ if (!isNew && !string.IsNullOrEmpty(dto.Id))
+ {
+ var timer = await liveTv.GetSeriesTimer(dto.Id, cancellationToken).ConfigureAwait(false);
+
+ info.Id = timer.ExternalId;
+ }
+
+ if (!string.IsNullOrEmpty(dto.ChannelId))
+ {
+ var channel = await liveTv.GetChannel(dto.ChannelId, cancellationToken).ConfigureAwait(false);
+
+ info.ChannelId = channel.ExternalId;
+ }
+
+ if (!string.IsNullOrEmpty(dto.ProgramId))
+ {
+ var program = await liveTv.GetProgram(dto.ProgramId, cancellationToken).ConfigureAwait(false);
+
+ info.ProgramId = program.ExternalId;
+ }
+
+ return info;
}
}
}
diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
index b56f94a36..b9dfc1b48 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
@@ -178,7 +178,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return item;
}
- public async Task<QueryResult<ProgramInfoDto>> GetPrograms(ProgramQuery query, CancellationToken cancellationToken)
+ public Task<ProgramInfoDto> GetProgram(string id, CancellationToken cancellationToken, User user = null)
+ {
+ var program = _programs.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.OrdinalIgnoreCase));
+
+ return Task.FromResult(program);
+ }
+
+ public Task<QueryResult<ProgramInfoDto>> GetPrograms(ProgramQuery query, CancellationToken cancellationToken)
{
IEnumerable<ProgramInfoDto> programs = _programs
.OrderBy(i => i.StartDate)
@@ -193,11 +200,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var returnArray = programs.ToArray();
- return new QueryResult<ProgramInfoDto>
+ var result = new QueryResult<ProgramInfoDto>
{
Items = returnArray,
TotalRecordCount = returnArray.Length
};
+
+ return Task.FromResult(result);
}
internal async Task RefreshChannels(IProgress<double> progress, CancellationToken cancellationToken)
@@ -416,26 +425,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return results.Items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.CurrentCulture));
}
- public Task UpdateTimer(TimerInfoDto timer, CancellationToken cancellationToken)
- {
- var info = _tvDtoService.GetTimerInfo(timer);
-
- var service = GetServices(timer.ServiceName, null)
- .First();
-
- return service.UpdateTimerAsync(info, cancellationToken);
- }
-
- public Task UpdateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken)
- {
- var info = _tvDtoService.GetSeriesTimerInfo(timer);
-
- var service = GetServices(timer.ServiceName, null)
- .First();
-
- return service.UpdateSeriesTimerAsync(info, cancellationToken);
- }
-
public async Task<QueryResult<SeriesTimerInfoDto>> GetSeriesTimers(SeriesTimerQuery query, CancellationToken cancellationToken)
{
var list = new List<SeriesTimerInfoDto>();
@@ -469,5 +458,48 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return results.Items.FirstOrDefault(i => string.Equals(i.Id, id, StringComparison.CurrentCulture));
}
+
+ public async Task<TimerInfoDto> GetNewTimerDefaults(CancellationToken cancellationToken)
+ {
+ var info = await ActiveService.GetNewTimerDefaultsAsync(cancellationToken).ConfigureAwait(false);
+
+ return _tvDtoService.GetTimerInfoDto(info, ActiveService);
+ }
+
+ public async Task CreateTimer(TimerInfoDto timer, CancellationToken cancellationToken)
+ {
+ var service = string.IsNullOrEmpty(timer.ServiceName) ? ActiveService : GetServices(timer.ServiceName, null).First();
+
+ var info = await _tvDtoService.GetTimerInfo(timer, true, this, cancellationToken).ConfigureAwait(false);
+
+ await service.CreateTimerAsync(info, cancellationToken).ConfigureAwait(false);
+ }
+
+ public async Task CreateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken)
+ {
+ var service = string.IsNullOrEmpty(timer.ServiceName) ? ActiveService : GetServices(timer.ServiceName, null).First();
+
+ var info = await _tvDtoService.GetSeriesTimerInfo(timer, true, this, cancellationToken).ConfigureAwait(false);
+
+ await service.CreateSeriesTimerAsync(info, cancellationToken).ConfigureAwait(false);
+ }
+
+ public async Task UpdateTimer(TimerInfoDto timer, CancellationToken cancellationToken)
+ {
+ var info = await _tvDtoService.GetTimerInfo(timer, false, this, cancellationToken).ConfigureAwait(false);
+
+ var service = string.IsNullOrEmpty(timer.ServiceName) ? ActiveService : GetServices(timer.ServiceName, null).First();
+
+ await service.UpdateTimerAsync(info, cancellationToken).ConfigureAwait(false);
+ }
+
+ public async Task UpdateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken)
+ {
+ var info = await _tvDtoService.GetSeriesTimerInfo(timer, false, this, cancellationToken).ConfigureAwait(false);
+
+ var service = string.IsNullOrEmpty(timer.ServiceName) ? ActiveService : GetServices(timer.ServiceName, null).First();
+
+ await service.UpdateSeriesTimerAsync(info, cancellationToken).ConfigureAwait(false);
+ }
}
}