aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MediaBrowser.Api/ApiService.cs52
-rw-r--r--MediaBrowser.ApiInteraction/ApiClient.cs62
-rw-r--r--MediaBrowser.ApiInteraction/BaseClient.cs10
-rw-r--r--MediaBrowser.Model/Entities/ApiBaseItem.cs4
4 files changed, 113 insertions, 15 deletions
diff --git a/MediaBrowser.Api/ApiService.cs b/MediaBrowser.Api/ApiService.cs
index bb2427574..382d236ae 100644
--- a/MediaBrowser.Api/ApiService.cs
+++ b/MediaBrowser.Api/ApiService.cs
@@ -30,10 +30,21 @@ namespace MediaBrowser.Api
Item = item,
UserItemData = Kernel.Instance.GetUserItemData(userId, item.Id),
Type = item.GetType().Name,
- IsFolder = (item is Folder),
- ParentLogoItemId = GetParentLogoItemId(item)
+ IsFolder = (item is Folder)
};
+ if (string.IsNullOrEmpty(item.LogoImagePath))
+ {
+ wrapper.ParentLogoItemId = GetParentLogoItemId(item);
+ }
+
+ if (item.BackdropImagePaths == null || !item.BackdropImagePaths.Any())
+ {
+ int backdropCount;
+ wrapper.ParentBackdropItemId = GetParentBackdropItemId(item, out backdropCount);
+ wrapper.ParentBackdropCount = backdropCount;
+ }
+
if (item.Parent != null)
{
wrapper.ParentId = item.Parent.Id;
@@ -52,21 +63,38 @@ namespace MediaBrowser.Api
return wrapper;
}
- private static Guid? GetParentLogoItemId(BaseItem item)
+ private static Guid? GetParentBackdropItemId(BaseItem item, out int backdropCount)
{
- if (string.IsNullOrEmpty(item.LogoImagePath))
- {
- var parent = item.Parent;
+ backdropCount = 0;
+
+ var parent = item.Parent;
- while (parent != null)
+ while (parent != null)
+ {
+ if (parent.BackdropImagePaths != null && parent.BackdropImagePaths.Any())
{
- if (!string.IsNullOrEmpty(parent.LogoImagePath))
- {
- return parent.Id;
- }
+ backdropCount = parent.BackdropImagePaths.Count();
+ return parent.Id;
+ }
+
+ parent = parent.Parent;
+ }
+
+ return null;
+ }
- parent = parent.Parent;
+ private static Guid? GetParentLogoItemId(BaseItem item)
+ {
+ var parent = item.Parent;
+
+ while (parent != null)
+ {
+ if (!string.IsNullOrEmpty(parent.LogoImagePath))
+ {
+ return parent.Id;
}
+
+ parent = parent.Parent;
}
return null;
diff --git a/MediaBrowser.ApiInteraction/ApiClient.cs b/MediaBrowser.ApiInteraction/ApiClient.cs
index 16effcde0..813d984f6 100644
--- a/MediaBrowser.ApiInteraction/ApiClient.cs
+++ b/MediaBrowser.ApiInteraction/ApiClient.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using MediaBrowser.Model.Configuration;
@@ -70,6 +71,67 @@ namespace MediaBrowser.ApiInteraction
}
/// <summary>
+ /// This is a helper to get a list of backdrop url's from a given ApiBaseItemWrapper. If the actual item does not have any backdrops it will return backdrops from the first parent that does.
+ /// </summary>
+ /// <param name="itemWrapper">A given item.</param>
+ /// <param name="width">Use if a fixed width is required. Aspect ratio will be preserved.</param>
+ /// <param name="height">Use if a fixed height is required. Aspect ratio will be preserved.</param>
+ /// <param name="maxWidth">Use if a max width is required. Aspect ratio will be preserved.</param>
+ /// <param name="maxHeight">Use if a max height is required. Aspect ratio will be preserved.</param>
+ /// <param name="quality">Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.</param>
+ public IEnumerable<string> GetBackdropImageUrls(ApiBaseItemWrapper<ApiBaseItem> itemWrapper, int? width, int? height, int? maxWidth, int? maxHeight, int? quality)
+ {
+ Guid? backdropItemId = null;
+ int backdropCount = 0;
+
+ if (itemWrapper.Item.BackdropImagePaths == null || !itemWrapper.Item.BackdropImagePaths.Any())
+ {
+ backdropItemId = itemWrapper.ParentBackdropItemId;
+ backdropCount = itemWrapper.ParentBackdropCount ?? 0;
+ }
+ else
+ {
+ backdropItemId = itemWrapper.Item.Id;
+ backdropCount = itemWrapper.Item.BackdropImagePaths.Count();
+ }
+
+ if (backdropItemId == null)
+ {
+ return new string[] { };
+ }
+
+ List<string> files = new List<string>();
+
+ for (int i = 0; i < backdropCount; i++)
+ {
+ files.Add(GetImageUrl(backdropItemId.Value, ImageType.Backdrop, i, width, height, maxWidth, maxHeight, quality));
+ }
+
+ return files;
+ }
+
+ /// <summary>
+ /// This is a helper to get the logo image url from a given ApiBaseItemWrapper. If the actual item does not have a logo, it will return the logo from the first parent that does, or null.
+ /// </summary>
+ /// <param name="itemWrapper">A given item.</param>
+ /// <param name="width">Use if a fixed width is required. Aspect ratio will be preserved.</param>
+ /// <param name="height">Use if a fixed height is required. Aspect ratio will be preserved.</param>
+ /// <param name="maxWidth">Use if a max width is required. Aspect ratio will be preserved.</param>
+ /// <param name="maxHeight">Use if a max height is required. Aspect ratio will be preserved.</param>
+ /// <param name="quality">Quality level, from 0-100. Currently only applies to JPG. The default value should suffice.</param>
+ public string GetLogoImageUrl(ApiBaseItemWrapper<ApiBaseItem> itemWrapper, int? width, int? height, int? maxWidth, int? maxHeight, int? quality)
+ {
+ Guid? logoItemId = !string.IsNullOrEmpty(itemWrapper.Item.LogoImagePath) ? itemWrapper.Item.Id : itemWrapper.ParentLogoItemId;
+
+ if (logoItemId.HasValue)
+ {
+ return GetImageUrl(logoItemId.Value, ImageType.Logo, null, width, height, maxWidth, maxHeight, quality);
+ }
+
+ return null;
+ }
+
+ /// <summary>
/// Gets an image stream based on a url
/// </summary>
public async Task<Stream> GetImageStreamAsync(string url)
diff --git a/MediaBrowser.ApiInteraction/BaseClient.cs b/MediaBrowser.ApiInteraction/BaseClient.cs
index 887c1779f..b552bf32f 100644
--- a/MediaBrowser.ApiInteraction/BaseClient.cs
+++ b/MediaBrowser.ApiInteraction/BaseClient.cs
@@ -1,4 +1,5 @@
using System;
+using System.Net;
using System.Net.Http;
namespace MediaBrowser.ApiInteraction
@@ -16,13 +17,16 @@ namespace MediaBrowser.ApiInteraction
/// <summary>
/// Gets or sets the port number used by the API
/// </summary>
- public int ApiPort { get; set; }
+ public int ServerApiPort { get; set; }
+ /// <summary>
+ /// Gets the current api url based on hostname and port.
+ /// </summary>
protected string ApiUrl
{
get
{
- return string.Format("http://{0}:{1}/mediabrowser/api", ServerHostName, ApiPort);
+ return string.Format("http://{0}:{1}/mediabrowser/api", ServerHostName, ServerApiPort);
}
}
@@ -35,7 +39,7 @@ namespace MediaBrowser.ApiInteraction
public BaseClient(HttpClientHandler clientHandler)
{
- clientHandler.AutomaticDecompression = System.Net.DecompressionMethods.GZip;
+ clientHandler.AutomaticDecompression = DecompressionMethods.GZip;
HttpClient = new HttpClient(clientHandler);
}
diff --git a/MediaBrowser.Model/Entities/ApiBaseItem.cs b/MediaBrowser.Model/Entities/ApiBaseItem.cs
index 0ec9ed7c6..ff4d13c0b 100644
--- a/MediaBrowser.Model/Entities/ApiBaseItem.cs
+++ b/MediaBrowser.Model/Entities/ApiBaseItem.cs
@@ -44,5 +44,9 @@ namespace MediaBrowser.Model.Entities
/// If the item does not have a logo, this will hold the Id of the Parent that has one.
/// </summary>
public Guid? ParentLogoItemId { get; set; }
+
+ public Guid? ParentBackdropItemId { get; set; }
+
+ public int? ParentBackdropCount { get; set; }
}
}