From 3e335c70bb87379677c189f64e890f4d9f501ff2 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 11 Jun 2017 17:58:49 -0400 Subject: [PATCH] update live tv images --- .../LiveTv/Listings/SchedulesDirect.cs | 55 +++---------------- .../LiveTv/LiveTvManager.cs | 37 ++++++++++--- MediaBrowser.Controller/LiveTv/ProgramInfo.cs | 2 + 3 files changed, 40 insertions(+), 54 deletions(-) diff --git a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs index 930499fe2..bba625cd1 100644 --- a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs +++ b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs @@ -172,13 +172,14 @@ namespace Emby.Server.Implementations.LiveTv.Listings var allImages = (images[imageIndex].data ?? new List()).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 images, string category, bool returnDefaultImage, double desiredAspect) + private string GetProgramImage(string apiUrl, List 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; } diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs index 44a9bd1f5..4ad411c19 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs @@ -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); } diff --git a/MediaBrowser.Controller/LiveTv/ProgramInfo.cs b/MediaBrowser.Controller/LiveTv/ProgramInfo.cs index f41df6f8a..b0e636d77 100644 --- a/MediaBrowser.Controller/LiveTv/ProgramInfo.cs +++ b/MediaBrowser.Controller/LiveTv/ProgramInfo.cs @@ -111,6 +111,8 @@ namespace MediaBrowser.Controller.LiveTv public string LogoImageUrl { get; set; } + public string BackdropImageUrl { get; set; } + /// /// Gets or sets a value indicating whether this instance has image. ///