From 1ed03b0bb328e4d5c48c560c06aab55b4c75cd46 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 Jan 2014 01:08:22 -0500 Subject: [PATCH] added more images to search output --- MediaBrowser.Api/SearchService.cs | 52 +++++++++++++++++++- MediaBrowser.Api/SessionsService.cs | 2 +- MediaBrowser.Controller/Entities/BaseItem.cs | 5 +- MediaBrowser.Model/Search/SearchHint.cs | 24 +++++++++ 4 files changed, 78 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Api/SearchService.cs b/MediaBrowser.Api/SearchService.cs index a497ba001..f83c0a771 100644 --- a/MediaBrowser.Api/SearchService.cs +++ b/MediaBrowser.Api/SearchService.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Controller; -using MediaBrowser.Controller.Drawing; +using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; @@ -157,6 +156,9 @@ namespace MediaBrowser.Api result.PrimaryImageTag = _imageProcessor.GetImageCacheTag(item, ImageType.Primary, item.GetImagePath(ImageType.Primary)); } + SetThumbImageInfo(result, item); + SetBackdropImageInfo(result, item); + var episode = item as Episode; if (episode != null) @@ -205,5 +207,51 @@ namespace MediaBrowser.Api return result; } + + private void SetThumbImageInfo(SearchHint hint, BaseItem item) + { + var itemWithImage = item.HasImage(ImageType.Thumb) ? item : null; + + if (itemWithImage == null) + { + if (item is Episode) + { + itemWithImage = GetParentWithImage(item, ImageType.Thumb); + } + } + + if (itemWithImage == null) + { + itemWithImage = GetParentWithImage(item, ImageType.Thumb); + } + + if (itemWithImage != null) + { + hint.ThumbImageTag = _imageProcessor.GetImageCacheTag(itemWithImage, ImageType.Thumb, itemWithImage.GetImagePath(ImageType.Thumb)); + hint.ThumbImageItemId = itemWithImage.Id.ToString("N"); + } + } + + private void SetBackdropImageInfo(SearchHint hint, BaseItem item) + { + var itemWithImage = item.HasImage(ImageType.Backdrop) ? item : null; + + if (itemWithImage == null) + { + itemWithImage = GetParentWithImage(item, ImageType.Backdrop); + } + + if (itemWithImage != null) + { + hint.BackdropImageTag = _imageProcessor.GetImageCacheTag(itemWithImage, ImageType.Backdrop, itemWithImage.GetImagePath(ImageType.Backdrop, 0)); + hint.BackdropImageItemId = itemWithImage.Id.ToString("N"); + } + } + + private T GetParentWithImage(BaseItem item, ImageType type) + where T : BaseItem + { + return item.Parents.OfType().FirstOrDefault(i => i.HasImage(type)); + } } } diff --git a/MediaBrowser.Api/SessionsService.cs b/MediaBrowser.Api/SessionsService.cs index 5433ecc2e..79de8cc65 100644 --- a/MediaBrowser.Api/SessionsService.cs +++ b/MediaBrowser.Api/SessionsService.cs @@ -205,7 +205,7 @@ namespace MediaBrowser.Api [ApiMember(Name = "Id", Description = "Session Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] public Guid Id { get; set; } - [ApiMember(Name = "PlayableMediaTypes", Description = "A list of playable media types, comma delimited.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] + [ApiMember(Name = "PlayableMediaTypes", Description = "A list of playable media types, comma delimited. Audio, Video, Book, Game, Photo.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] public string PlayableMediaTypes { get; set; } } diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index dbda4a243..dcee4bae7 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1394,11 +1394,12 @@ namespace MediaBrowser.Controller.Entities { if (type == ImageType.Backdrop) { - throw new ArgumentException("Backdrops should be accessed using Item.Backdrops"); + return BackdropImagePaths.Count > imageIndex; } if (type == ImageType.Screenshot) { - throw new ArgumentException("Screenshots should be accessed using Item.Screenshots"); + var hasScreenshots = this as IHasScreenshots; + return hasScreenshots != null && hasScreenshots.ScreenshotImagePaths.Count > imageIndex; } return !string.IsNullOrEmpty(this.GetImagePath(type)); diff --git a/MediaBrowser.Model/Search/SearchHint.cs b/MediaBrowser.Model/Search/SearchHint.cs index bebe23734..002200c0f 100644 --- a/MediaBrowser.Model/Search/SearchHint.cs +++ b/MediaBrowser.Model/Search/SearchHint.cs @@ -49,6 +49,30 @@ namespace MediaBrowser.Model.Search /// The image tag. public Guid? PrimaryImageTag { get; set; } + /// + /// Gets or sets the thumb image tag. + /// + /// The thumb image tag. + public Guid? ThumbImageTag { get; set; } + + /// + /// Gets or sets the thumb image item identifier. + /// + /// The thumb image item identifier. + public string ThumbImageItemId { get; set; } + + /// + /// Gets or sets the backdrop image tag. + /// + /// The backdrop image tag. + public Guid? BackdropImageTag { get; set; } + + /// + /// Gets or sets the backdrop image item identifier. + /// + /// The backdrop image item identifier. + public string BackdropImageItemId { get; set; } + /// /// Gets or sets the type. ///