update live tv images

This commit is contained in:
Luke Pulverenti 2017-06-11 17:58:49 -04:00
parent 27d9ace404
commit 3e335c70bb
3 changed files with 40 additions and 54 deletions

View File

@ -172,13 +172,14 @@ namespace Emby.Server.Implementations.LiveTv.Listings
var allImages = (images[imageIndex].data ?? new List<ScheduleDirect.ImageData>()).ToList();
var imagesWithText = allImages.Where(i => string.Equals(i.text, "yes", StringComparison.OrdinalIgnoreCase)).ToList();
var imagesWithoutText = allImages.Where(i => string.Equals(i.text, "no", StringComparison.OrdinalIgnoreCase)).ToList();
double desiredAspect = IsMovie(programEntry) ? 0.666666667 : wideAspect;
programEntry.primaryImage = GetProgramImage(ApiUrl, imagesWithText, null, true, desiredAspect) ??
GetProgramImage(ApiUrl, allImages, null, true, desiredAspect);
programEntry.primaryImage = GetProgramImage(ApiUrl, imagesWithText, true, desiredAspect) ??
GetProgramImage(ApiUrl, allImages, true, desiredAspect);
programEntry.thumbImage = GetProgramImage(ApiUrl, imagesWithText, null, true, wideAspect);
programEntry.thumbImage = GetProgramImage(ApiUrl, imagesWithText, true, wideAspect);
// Don't supply the same image twice
if (string.Equals(programEntry.primaryImage, programEntry.thumbImage, StringComparison.Ordinal))
@ -186,6 +187,8 @@ namespace Emby.Server.Implementations.LiveTv.Listings
programEntry.thumbImage = null;
}
programEntry.backdropImage = GetProgramImage(ApiUrl, imagesWithoutText, true, wideAspect);
//programEntry.bannerImage = GetProgramImage(ApiUrl, data, "Banner", false) ??
// GetProgramImage(ApiUrl, data, "Banner-L1", false) ??
// GetProgramImage(ApiUrl, data, "Banner-LO", false) ??
@ -396,62 +399,19 @@ namespace Emby.Server.Implementations.LiveTv.Listings
return date;
}
private string GetProgramImage(string apiUrl, List<ScheduleDirect.ImageData> images, string category, bool returnDefaultImage, double desiredAspect)
private string GetProgramImage(string apiUrl, List<ScheduleDirect.ImageData> images, bool returnDefaultImage, double desiredAspect)
{
string url = null;
var matches = images;
if (!string.IsNullOrWhiteSpace(category))
{
matches = images
.Where(i => string.Equals(i.category, category, StringComparison.OrdinalIgnoreCase))
.ToList();
if (matches.Count == 0)
{
if (!returnDefaultImage)
{
return null;
}
matches = images;
}
}
matches = matches
.OrderBy(i => Math.Abs(desiredAspect - GetApsectRatio(i)))
.ThenByDescending(GetSizeOrder)
.ToList();
//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)
{
// Get the second lowest quality image, when possible
if (matches.Count > 1)
{
match = matches[matches.Count - 2];
}
else
{
match = matches.FirstOrDefault();
}
}
if (match == null)
{
return null;
@ -1243,6 +1203,7 @@ namespace Emby.Server.Implementations.LiveTv.Listings
public bool hasImageArtwork { get; set; }
public string primaryImage { get; set; }
public string thumbImage { get; set; }
public string backdropImage { get; set; }
public string bannerImage { get; set; }
public string imageID { get; set; }
public string md5 { get; set; }

View File

@ -679,8 +679,7 @@ namespace Emby.Server.Implementations.LiveTv
item.SetImage(new ItemImageInfo
{
Path = info.ImagePath,
Type = ImageType.Primary,
IsPlaceholder = true
Type = ImageType.Primary
}, 0);
}
else if (!string.IsNullOrWhiteSpace(info.ImageUrl))
@ -688,8 +687,7 @@ namespace Emby.Server.Implementations.LiveTv
item.SetImage(new ItemImageInfo
{
Path = info.ImageUrl,
Type = ImageType.Primary,
IsPlaceholder = true
Type = ImageType.Primary
}, 0);
}
}
@ -700,9 +698,34 @@ namespace Emby.Server.Implementations.LiveTv
{
item.SetImage(new ItemImageInfo
{
Path = info.ImageUrl,
Type = ImageType.Thumb,
IsPlaceholder = true
Path = info.ThumbImageUrl,
Type = ImageType.Thumb
}, 0);
}
}
if (!item.HasImage(ImageType.Logo))
{
if (!string.IsNullOrWhiteSpace(info.LogoImageUrl))
{
item.SetImage(new ItemImageInfo
{
Path = info.LogoImageUrl,
Type = ImageType.Logo
}, 0);
}
}
if (!item.HasImage(ImageType.Backdrop))
{
if (!string.IsNullOrWhiteSpace(info.BackdropImageUrl))
{
item.SetImage(new ItemImageInfo
{
Path = info.BackdropImageUrl,
Type = ImageType.Backdrop
}, 0);
}

View File

@ -111,6 +111,8 @@ namespace MediaBrowser.Controller.LiveTv
public string LogoImageUrl { get; set; }
public string BackdropImageUrl { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance has image.
/// </summary>