mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-01 17:15:07 +02:00
remove more ActiveService usage
This commit is contained in:
parent
f91c30a407
commit
aa181c8b25
1 changed files with 43 additions and 20 deletions
|
@ -1289,36 +1289,47 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||||
|
|
||||||
public async Task<QueryResult<TimerInfoDto>> GetTimers(TimerQuery query, CancellationToken cancellationToken)
|
public async Task<QueryResult<TimerInfoDto>> GetTimers(TimerQuery query, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var service = ActiveService;
|
var tasks = _services.Select(async i =>
|
||||||
var timers = await service.GetTimersAsync(cancellationToken).ConfigureAwait(false);
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var recs = await i.GetTimersAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
return recs.Select(r => new Tuple<TimerInfo, ILiveTvService>(r, i));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error getting recordings", ex);
|
||||||
|
return new List<Tuple<TimerInfo, ILiveTvService>>();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var results = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||||
|
var timers = results.SelectMany(i => i.ToList());
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(query.ChannelId))
|
if (!string.IsNullOrEmpty(query.ChannelId))
|
||||||
{
|
{
|
||||||
var guid = new Guid(query.ChannelId);
|
var guid = new Guid(query.ChannelId);
|
||||||
timers = timers.Where(i => guid == _tvDtoService.GetInternalChannelId(service.Name, i.ChannelId));
|
timers = timers.Where(i => guid == _tvDtoService.GetInternalChannelId(i.Item2.Name, i.Item1.ChannelId));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(query.SeriesTimerId))
|
if (!string.IsNullOrEmpty(query.SeriesTimerId))
|
||||||
{
|
{
|
||||||
var guid = new Guid(query.SeriesTimerId);
|
var guid = new Guid(query.SeriesTimerId);
|
||||||
|
|
||||||
var currentServiceName = service.Name;
|
|
||||||
|
|
||||||
timers = timers
|
timers = timers
|
||||||
.Where(i => _tvDtoService.GetInternalSeriesTimerId(currentServiceName, i.SeriesTimerId) == guid);
|
.Where(i => _tvDtoService.GetInternalSeriesTimerId(i.Item2.Name, i.Item1.SeriesTimerId) == guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
var returnList = new List<TimerInfoDto>();
|
var returnList = new List<TimerInfoDto>();
|
||||||
|
|
||||||
foreach (var i in timers)
|
foreach (var i in timers)
|
||||||
{
|
{
|
||||||
var program = string.IsNullOrEmpty(i.ProgramId) ?
|
var program = string.IsNullOrEmpty(i.Item1.ProgramId) ?
|
||||||
null :
|
null :
|
||||||
GetInternalProgram(_tvDtoService.GetInternalProgramId(service.Name, i.ProgramId).ToString("N"));
|
GetInternalProgram(_tvDtoService.GetInternalProgramId(i.Item2.Name, i.Item1.ProgramId).ToString("N"));
|
||||||
|
|
||||||
var channel = string.IsNullOrEmpty(i.ChannelId) ? null : GetInternalChannel(_tvDtoService.GetInternalChannelId(service.Name, i.ChannelId));
|
var channel = string.IsNullOrEmpty(i.Item1.ChannelId) ? null : GetInternalChannel(_tvDtoService.GetInternalChannelId(i.Item2.Name, i.Item1.ChannelId));
|
||||||
|
|
||||||
returnList.Add(_tvDtoService.GetTimerInfoDto(i, service, program, channel));
|
returnList.Add(_tvDtoService.GetTimerInfoDto(i.Item1, i.Item2, program, channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
var returnArray = returnList
|
var returnArray = returnList
|
||||||
|
@ -1402,21 +1413,33 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||||
|
|
||||||
public async Task<QueryResult<SeriesTimerInfoDto>> GetSeriesTimers(SeriesTimerQuery query, CancellationToken cancellationToken)
|
public async Task<QueryResult<SeriesTimerInfoDto>> GetSeriesTimers(SeriesTimerQuery query, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var service = ActiveService;
|
var tasks = _services.Select(async i =>
|
||||||
|
{
|
||||||
var timers = await service.GetSeriesTimersAsync(cancellationToken).ConfigureAwait(false);
|
try
|
||||||
|
{
|
||||||
|
var recs = await i.GetSeriesTimersAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
return recs.Select(r => new Tuple<SeriesTimerInfo, ILiveTvService>(r, i));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error getting recordings", ex);
|
||||||
|
return new List<Tuple<SeriesTimerInfo, ILiveTvService>>();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var results = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||||
|
var timers = results.SelectMany(i => i.ToList());
|
||||||
|
|
||||||
if (string.Equals(query.SortBy, "Priority", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(query.SortBy, "Priority", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
timers = query.SortOrder == SortOrder.Descending ?
|
timers = query.SortOrder == SortOrder.Descending ?
|
||||||
timers.OrderBy(i => i.Priority).ThenByStringDescending(i => i.Name) :
|
timers.OrderBy(i => i.Item1.Priority).ThenByStringDescending(i => i.Item1.Name) :
|
||||||
timers.OrderByDescending(i => i.Priority).ThenByString(i => i.Name);
|
timers.OrderByDescending(i => i.Item1.Priority).ThenByString(i => i.Item1.Name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
timers = query.SortOrder == SortOrder.Descending ?
|
timers = query.SortOrder == SortOrder.Descending ?
|
||||||
timers.OrderByStringDescending(i => i.Name) :
|
timers.OrderByStringDescending(i => i.Item1.Name) :
|
||||||
timers.OrderByString(i => i.Name);
|
timers.OrderByString(i => i.Item1.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
var returnArray = timers
|
var returnArray = timers
|
||||||
|
@ -1424,14 +1447,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||||
{
|
{
|
||||||
string channelName = null;
|
string channelName = null;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(i.ChannelId))
|
if (!string.IsNullOrEmpty(i.Item1.ChannelId))
|
||||||
{
|
{
|
||||||
var internalChannelId = _tvDtoService.GetInternalChannelId(service.Name, i.ChannelId);
|
var internalChannelId = _tvDtoService.GetInternalChannelId(i.Item2.Name, i.Item1.ChannelId);
|
||||||
var channel = GetInternalChannel(internalChannelId);
|
var channel = GetInternalChannel(internalChannelId);
|
||||||
channelName = channel == null ? null : channel.Name;
|
channelName = channel == null ? null : channel.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _tvDtoService.GetSeriesTimerInfoDto(i, service, channelName);
|
return _tvDtoService.GetSeriesTimerInfoDto(i.Item1, i.Item2, channelName);
|
||||||
|
|
||||||
})
|
})
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
Loading…
Reference in a new issue