mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-24 19:16:32 +00:00
add ability to create timer
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user