update tv queries

This commit is contained in:
Luke Pulverenti
2016-03-22 02:49:36 -04:00
parent 49c678037a
commit 4f025c8e4a
6 changed files with 64 additions and 168 deletions

View File

@@ -94,12 +94,18 @@ namespace MediaBrowser.Server.Implementations.Dto
var list = new List<BaseItemDto>();
var programTuples = new List<Tuple<BaseItem, BaseItemDto>> { };
var channelTuples = new List<Tuple<BaseItemDto, LiveTvChannel>> { };
foreach (var item in items)
{
var dto = GetBaseItemDtoInternal(item, options, syncDictionary, user, owner);
if (item is LiveTvProgram)
var tvChannel = item as LiveTvChannel;
if (tvChannel != null)
{
channelTuples.Add(new Tuple<BaseItemDto, LiveTvChannel>(dto, tvChannel));
}
else if (item is LiveTvProgram)
{
programTuples.Add(new Tuple<BaseItem, BaseItemDto>(item, dto));
}
@@ -131,6 +137,11 @@ namespace MediaBrowser.Server.Implementations.Dto
Task.WaitAll(task);
}
if (channelTuples.Count > 0)
{
_livetvManager().AddChannelInfo(channelTuples, options, user);
}
return list;
}
@@ -151,8 +162,13 @@ namespace MediaBrowser.Server.Implementations.Dto
var syncProgress = GetSyncedItemProgress(options);
var dto = GetBaseItemDtoInternal(item, options, GetSyncedItemProgressDictionary(syncProgress), user, owner);
if (item is LiveTvProgram)
var tvChannel = item as LiveTvChannel;
if (tvChannel != null)
{
var list = new List<Tuple<BaseItemDto, LiveTvChannel>> { new Tuple<BaseItemDto, LiveTvChannel>(dto, tvChannel) };
_livetvManager().AddChannelInfo(list, options, user);
}
else if (item is LiveTvProgram)
{
var list = new List<Tuple<BaseItem, BaseItemDto>> { new Tuple<BaseItem, BaseItemDto>(item, dto) };
var task = _livetvManager().AddInfoToProgramDto(list, options.Fields, user);
@@ -372,12 +388,6 @@ namespace MediaBrowser.Server.Implementations.Dto
AttachBasicFields(dto, item, owner, options);
var tvChannel = item as LiveTvChannel;
if (tvChannel != null)
{
_livetvManager().AddChannelInfo(dto, tvChannel, options, user);
}
var collectionFolder = item as ICollectionFolder;
if (collectionFolder != null)
{

View File

@@ -152,21 +152,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return pattern;
}
/// <summary>
/// Convert the provider 0-5 scale to our 0-10 scale
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
private float? GetClientCommunityRating(float? val)
{
if (!val.HasValue)
{
return null;
}
return val.Value;
}
public LiveTvTunerInfoDto GetTunerInfoDto(string serviceName, LiveTvTunerInfo info, string channelName)
{
var dto = new LiveTvTunerInfoDto
@@ -195,54 +180,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return dto;
}
/// <summary>
/// Gets the channel info dto.
/// </summary>
/// <param name="info">The info.</param>
/// <param name="options">The options.</param>
/// <param name="currentProgram">The current program.</param>
/// <param name="user">The user.</param>
/// <returns>ChannelInfoDto.</returns>
public ChannelInfoDto GetChannelInfoDto(LiveTvChannel info, DtoOptions options, LiveTvProgram currentProgram, User user = null)
{
var dto = new ChannelInfoDto
{
Name = info.Name,
ServiceName = info.ServiceName,
ChannelType = info.ChannelType,
Number = info.Number,
Type = info.GetClientTypeName(),
Id = info.Id.ToString("N"),
MediaType = info.MediaType,
ExternalId = info.ExternalId,
MediaSources = info.GetMediaSources(true).ToList(),
ServerId = _appHost.SystemId
};
if (user != null)
{
dto.UserData = _userDataManager.GetUserDataDto(info, user);
dto.PlayAccess = info.GetPlayAccess(user);
}
var imageTag = GetImageTag(info);
if (imageTag != null)
{
dto.ImageTags[ImageType.Primary] = imageTag;
_dtoService.AttachPrimaryImageAspectRatio(dto, info);
}
if (currentProgram != null)
{
dto.CurrentProgram = _dtoService.GetBaseItemDto(currentProgram, options, user);
}
return dto;
}
internal string GetImageTag(IHasImages info)
{
try
@@ -324,7 +261,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
if (!string.IsNullOrEmpty(dto.ChannelId) && string.IsNullOrEmpty(info.ChannelId))
{
var channel = await liveTv.GetChannel(dto.ChannelId, cancellationToken).ConfigureAwait(false);
var channel = liveTv.GetInternalChannel(dto.ChannelId);
if (channel != null)
{
@@ -387,7 +324,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
if (!string.IsNullOrEmpty(dto.ChannelId) && string.IsNullOrEmpty(info.ChannelId))
{
var channel = await liveTv.GetChannel(dto.ChannelId, cancellationToken).ConfigureAwait(false);
var channel = liveTv.GetInternalChannel(dto.ChannelId);
if (channel != null)
{

View File

@@ -244,42 +244,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return result;
}
public async Task<QueryResult<ChannelInfoDto>> GetChannels(LiveTvChannelQuery query, DtoOptions options, CancellationToken cancellationToken)
{
var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(query.UserId);
var internalResult = await GetInternalChannels(query, cancellationToken).ConfigureAwait(false);
var returnList = new List<ChannelInfoDto>();
var now = DateTime.UtcNow;
var programs = query.AddCurrentProgram ? _libraryManager.QueryItems(new InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(LiveTvProgram).Name },
MaxStartDate = now,
MinEndDate = now,
ChannelIds = internalResult.Items.Select(i => i.Id.ToString("N")).ToArray()
}).Items.Cast<LiveTvProgram>().OrderBy(i => i.StartDate).ToList() : new List<LiveTvProgram>();
foreach (var channel in internalResult.Items)
{
var channelIdString = channel.Id.ToString("N");
var currentProgram = programs.FirstOrDefault(i => string.Equals(i.ChannelId, channelIdString, StringComparison.OrdinalIgnoreCase));
returnList.Add(_tvDtoService.GetChannelInfoDto(channel, options, currentProgram, user));
}
var result = new QueryResult<ChannelInfoDto>
{
Items = returnList.ToArray(),
TotalRecordCount = internalResult.TotalRecordCount
};
return result;
}
public LiveTvChannel GetInternalChannel(string id)
{
return GetInternalChannel(new Guid(id));
@@ -1859,52 +1823,37 @@ namespace MediaBrowser.Server.Implementations.LiveTv
};
}
public async Task<ChannelInfoDto> GetChannel(string id, CancellationToken cancellationToken, User user = null)
public void AddChannelInfo(List<Tuple<BaseItemDto, LiveTvChannel>> tuples, DtoOptions options, User user)
{
var channel = GetInternalChannel(id);
var now = DateTime.UtcNow;
var channelIds = tuples.Select(i => i.Item2.Id.ToString("N")).Distinct().ToArray();
var programs = _libraryManager.GetItemList(new InternalItemsQuery(user)
{
IncludeItemTypes = new[] { typeof(LiveTvProgram).Name },
ChannelIds = new[] { id },
ChannelIds = channelIds,
MaxStartDate = now,
MinEndDate = now,
Limit = 1,
Limit = channelIds.Length,
SortBy = new[] { "StartDate" }
}, new string[] { }).Cast<LiveTvProgram>();
}, new string[] { }).ToList();
var currentProgram = programs.FirstOrDefault();
var dto = _tvDtoService.GetChannelInfoDto(channel, new DtoOptions(), currentProgram, user);
return dto;
}
public void AddChannelInfo(BaseItemDto dto, LiveTvChannel channel, DtoOptions options, User user)
{
dto.MediaSources = channel.GetMediaSources(true).ToList();
var now = DateTime.UtcNow;
var programs = _libraryManager.GetItemList(new InternalItemsQuery(user)
foreach (var tuple in tuples)
{
IncludeItemTypes = new[] { typeof(LiveTvProgram).Name },
ChannelIds = new[] { channel.Id.ToString("N") },
MaxStartDate = now,
MinEndDate = now,
Limit = 1,
SortBy = new[] { "StartDate" }
var dto = tuple.Item1;
var channel = tuple.Item2;
}, new string[] { }).Cast<LiveTvProgram>();
dto.MediaSources = channel.GetMediaSources(true).ToList();
var currentProgram = programs.FirstOrDefault();
var channelIdString = channel.Id.ToString("N");
var currentProgram = programs.FirstOrDefault(i => string.Equals(i.ChannelId, channelIdString));
if (currentProgram != null)
{
dto.CurrentProgram = _dtoService.GetBaseItemDto(currentProgram, options, user);
if (currentProgram != null)
{
dto.CurrentProgram = _dtoService.GetBaseItemDto(currentProgram, options, user);
}
}
}