diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-06-11 16:41:27 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-11 16:41:27 -0400 |
| commit | 24975638f9772fbec4005f97ff954e01ce22a41f (patch) | |
| tree | 3b99c916799efa86005601b63076ae33f530c98a /Emby.Server.Implementations/LiveTv | |
| parent | 4fa170ab080b59ff3e5d8f913a42dfd7d21dbaa3 (diff) | |
| parent | 27d9ace40442aa50c0d27c318a8719a00796e950 (diff) | |
Merge pull request #2700 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Server.Implementations/LiveTv')
| -rw-r--r-- | Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs | 105 | ||||
| -rw-r--r-- | Emby.Server.Implementations/LiveTv/LiveTvManager.cs | 14 |
2 files changed, 94 insertions, 25 deletions
diff --git a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs index da6759b34..930499fe2 100644 --- a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs +++ b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs @@ -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, diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs index c2f057560..44a9bd1f5 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs @@ -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) { |
