improve live tv images

pull/1154/head
Luke Pulverenti 7 years ago
parent e56ef95283
commit 65e8cf0726

@ -176,7 +176,9 @@ namespace Emby.Server.Implementations.Channels
var internalResult = await GetChannelsInternal(query, cancellationToken).ConfigureAwait(false);
var dtoOptions = new DtoOptions();
var dtoOptions = new DtoOptions()
{
};
var returnItems = (await _dtoService.GetBaseItemDtos(internalResult.Items, dtoOptions, user).ConfigureAwait(false))
.ToArray();
@ -558,7 +560,10 @@ namespace Emby.Server.Implementations.Channels
totalRecordCount = items.Length;
}
var dtoOptions = new DtoOptions();
var dtoOptions = new DtoOptions()
{
Fields = query.Fields.ToList()
};
var returnItems = (await _dtoService.GetBaseItemDtos(items, dtoOptions, user).ConfigureAwait(false))
.ToArray();
@ -825,7 +830,10 @@ namespace Emby.Server.Implementations.Channels
RefreshIfNeeded(internalResult.Items);
var dtoOptions = new DtoOptions();
var dtoOptions = new DtoOptions()
{
Fields = query.Fields.ToList()
};
var returnItems = (await _dtoService.GetBaseItemDtos(internalResult.Items, dtoOptions, user).ConfigureAwait(false))
.ToArray();
@ -974,7 +982,10 @@ namespace Emby.Server.Implementations.Channels
var internalResult = await GetChannelItemsInternal(query, new Progress<double>(), cancellationToken).ConfigureAwait(false);
var dtoOptions = new DtoOptions();
var dtoOptions = new DtoOptions()
{
Fields = query.Fields.ToList()
};
var returnItems = (await _dtoService.GetBaseItemDtos(internalResult.Items, dtoOptions, user).ConfigureAwait(false))
.ToArray();

@ -1079,7 +1079,10 @@ namespace Emby.Server.Implementations.Dto
if (audio != null)
{
dto.Album = audio.Album;
dto.ExtraType = audio.ExtraType;
if (audio.ExtraType.HasValue)
{
dto.ExtraType = audio.ExtraType.Value.ToString();
}
var albumParent = audio.AlbumEntity;
@ -1234,7 +1237,10 @@ namespace Emby.Server.Implementations.Dto
dto.Chapters = GetChapterInfoDtos(item);
}
dto.ExtraType = video.ExtraType;
if (video.ExtraType.HasValue)
{
dto.ExtraType = video.ExtraType.Value.ToString();
}
}
if (fields.Contains(ItemFields.MediaStreams))
@ -1390,7 +1396,7 @@ namespace Emby.Server.Implementations.Dto
}
}
if (fields.Contains(ItemFields.SeriesPrimaryImage))
//if (fields.Contains(ItemFields.SeriesPrimaryImage))
{
series = series ?? season.Series;
if (series != null)
@ -1581,7 +1587,7 @@ namespace Emby.Server.Implementations.Dto
{
var imageInfo = item.GetImageInfo(ImageType.Primary, 0);
if (imageInfo == null || !imageInfo.IsLocalFile)
if (imageInfo == null)
{
return null;
}
@ -1605,6 +1611,11 @@ namespace Emby.Server.Implementations.Dto
}
else
{
if (!imageInfo.IsLocalFile)
{
return null;
}
try
{
size = _imageProcessor.GetImageSize(imageInfo);

@ -136,6 +136,9 @@ namespace Emby.Server.Implementations.LiveTv.Listings
var requestBody = "[\"" + string.Join("\", \"", programsID) + "\"]";
httpOptions.RequestContent = requestBody;
double wideAspect = 1.77777778;
var primaryImageCategory = "Logo";
using (var innerResponse = await Post(httpOptions, true, info).ConfigureAwait(false))
{
StreamReader innerReader = new StreamReader(innerResponse.Content);
@ -167,13 +170,22 @@ namespace Emby.Server.Implementations.LiveTv.Listings
{
var programEntry = programDict[schedule.programID];
var allImages = (images[imageIndex].data ?? new List<ScheduleDirect.ImageData>()).OrderByDescending(GetSizeOrder).ToList();
var allImages = (images[imageIndex].data ?? new List<ScheduleDirect.ImageData>()).ToList();
var imagesWithText = allImages.Where(i => string.Equals(i.text, "yes", StringComparison.OrdinalIgnoreCase)).ToList();
programEntry.primaryImage = GetProgramImage(ApiUrl, imagesWithText, "Logo", true, 600) ??
GetProgramImage(ApiUrl, allImages, "Logo", true, 600);
double desiredAspect = IsMovie(programEntry) ? 0.666666667 : wideAspect;
programEntry.primaryImage = GetProgramImage(ApiUrl, imagesWithText, null, true, desiredAspect) ??
GetProgramImage(ApiUrl, allImages, null, true, desiredAspect);
programEntry.thumbImage = GetProgramImage(ApiUrl, imagesWithText, null, true, wideAspect);
// Don't supply the same image twice
if (string.Equals(programEntry.primaryImage, programEntry.thumbImage, StringComparison.Ordinal))
{
programEntry.thumbImage = null;
}
//programEntry.thumbImage = GetProgramImage(ApiUrl, data, "Iconic", false);
//programEntry.bannerImage = GetProgramImage(ApiUrl, data, "Banner", false) ??
// GetProgramImage(ApiUrl, data, "Banner-L1", false) ??
// GetProgramImage(ApiUrl, data, "Banner-LO", false) ??
@ -220,9 +232,14 @@ namespace Emby.Server.Implementations.LiveTv.Listings
return channelNumber;
}
private bool IsMovie(ScheduleDirect.ProgramDetails programInfo)
{
var showType = programInfo.showType ?? string.Empty;
return showType.IndexOf("movie", StringComparison.OrdinalIgnoreCase) != -1 || showType.IndexOf("film", StringComparison.OrdinalIgnoreCase) != -1;
}
private ProgramInfo GetProgram(string channelId, ScheduleDirect.Program programInfo, ScheduleDirect.ProgramDetails details)
{
//_logger.Debug("Show type is: " + (details.showType ?? "No ShowType"));
DateTime startAt = GetDate(programInfo.airDateTime);
DateTime endAt = startAt.AddSeconds(programInfo.duration);
ProgramAudio audioType = ProgramAudio.Stereo;
@ -276,9 +293,10 @@ namespace Emby.Server.Implementations.LiveTv.Listings
IsRepeat = repeat,
IsSeries = showType.IndexOf("series", StringComparison.OrdinalIgnoreCase) != -1,
ImageUrl = details.primaryImage,
ThumbImageUrl = details.thumbImage,
IsKids = string.Equals(details.audience, "children", StringComparison.OrdinalIgnoreCase),
IsSports = showType.IndexOf("sports", StringComparison.OrdinalIgnoreCase) != -1,
IsMovie = showType.IndexOf("movie", StringComparison.OrdinalIgnoreCase) != -1 || showType.IndexOf("film", StringComparison.OrdinalIgnoreCase) != -1,
IsMovie = IsMovie(details),
Etag = programInfo.md5
};
@ -378,36 +396,48 @@ namespace Emby.Server.Implementations.LiveTv.Listings
return date;
}
private string GetProgramImage(string apiUrl, List<ScheduleDirect.ImageData> images, string category, bool returnDefaultImage, int desiredWidth)
private string GetProgramImage(string apiUrl, List<ScheduleDirect.ImageData> images, string category, bool returnDefaultImage, double desiredAspect)
{
string url = null;
var matches = images
.Where(i => string.Equals(i.category, category, StringComparison.OrdinalIgnoreCase))
.ToList();
var matches = images;
if (matches.Count == 0)
if (!string.IsNullOrWhiteSpace(category))
{
if (!returnDefaultImage)
{
return null;
}
matches = images;
}
matches = images
.Where(i => string.Equals(i.category, category, StringComparison.OrdinalIgnoreCase))
.ToList();
var match = matches.FirstOrDefault(i =>
{
if (!string.IsNullOrWhiteSpace(i.width))
if (matches.Count == 0)
{
int value;
if (int.TryParse(i.width, out value))
if (!returnDefaultImage)
{
return value <= desiredWidth;
return null;
}
matches = images;
}
}
matches = matches
.OrderBy(i => Math.Abs(desiredAspect - GetApsectRatio(i)))
.ThenByDescending(GetSizeOrder)
.ToList();
return false;
});
//var match = matches.FirstOrDefault(i =>
//{
// if (!string.IsNullOrWhiteSpace(i.width))
// {
// int value;
// if (int.TryParse(i.width, out value))
// {
// return value <= desiredWidth;
// }
// }
// return false;
//});
var match = matches.FirstOrDefault();
if (match == null)
{
@ -444,6 +474,31 @@ namespace Emby.Server.Implementations.LiveTv.Listings
return url;
}
private double GetApsectRatio(ScheduleDirect.ImageData i)
{
int width = 0;
int height = 0;
if (!string.IsNullOrWhiteSpace(i.width))
{
int.TryParse(i.width, out width);
}
if (!string.IsNullOrWhiteSpace(i.height))
{
int.TryParse(i.height, out height);
}
if (height == 0 || width == 0)
{
return 0;
}
double result = width;
result /= height;
return result;
}
private async Task<List<ScheduleDirect.ShowImages>> GetImageForPrograms(
ListingsProviderInfo info,
List<string> programIds,

@ -694,6 +694,20 @@ namespace Emby.Server.Implementations.LiveTv
}
}
if (!item.HasImage(ImageType.Thumb))
{
if (!string.IsNullOrWhiteSpace(info.ThumbImageUrl))
{
item.SetImage(new ItemImageInfo
{
Path = info.ImageUrl,
Type = ImageType.Thumb,
IsPlaceholder = true
}, 0);
}
}
var isUpdated = false;
if (isNew)
{

@ -27,6 +27,7 @@ using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Services;
using MediaBrowser.Common.Extensions;
namespace MediaBrowser.Api.Library
{
@ -830,6 +831,11 @@ namespace MediaBrowser.Api.Library
: (Folder)_libraryManager.RootFolder)
: _libraryManager.GetItemById(request.Id);
if (item == null)
{
throw new ResourceNotFoundException("Item not found.");
}
while (item.ThemeSongIds.Count == 0 && request.InheritFromParent && item.GetParent() != null)
{
item = item.GetParent();
@ -874,6 +880,11 @@ namespace MediaBrowser.Api.Library
: (Folder)_libraryManager.RootFolder)
: _libraryManager.GetItemById(request.Id);
if (item == null)
{
throw new ResourceNotFoundException("Item not found.");
}
while (item.ThemeVideoIds.Count == 0 && request.InheritFromParent && item.GetParent() != null)
{
item = item.GetParent();

@ -107,6 +107,8 @@ namespace MediaBrowser.Controller.LiveTv
/// <value>The image URL.</value>
public string ImageUrl { get; set; }
public string ThumbImageUrl { get; set; }
public string LogoImageUrl { get; set; }
/// <summary>

@ -52,15 +52,22 @@ namespace MediaBrowser.LocalMetadata.Parsers
{
case "CollectionItem":
{
using (var subReader = reader.ReadSubtree())
if (!reader.IsEmptyElement)
{
var child = GetLinkedChild(subReader);
if (child != null)
using (var subReader = reader.ReadSubtree())
{
list.Add(child);
var child = GetLinkedChild(subReader);
if (child != null)
{
list.Add(child);
}
}
}
else
{
reader.Read();
}
break;
}

@ -64,7 +64,7 @@ namespace MediaBrowser.Model.Dto
public DateTime? DateCreated { get; set; }
public DateTime? DateLastMediaAdded { get; set; }
public ExtraType? ExtraType { get; set; }
public string ExtraType { get; set; }
public int? AirsBeforeSeasonNumber { get; set; }
public int? AirsAfterSeasonNumber { get; set; }

@ -62,13 +62,6 @@ namespace MediaBrowser.Providers.Movies
public bool Supports(IHasImages item)
{
// Supports images for tv movies
var tvProgram = item as LiveTvProgram;
if (tvProgram != null && tvProgram.IsMovie)
{
return true;
}
return item is Movie || item is BoxSet || item is MusicVideo;
}

Loading…
Cancel
Save