From c124672636e0027ed557b6e24ce54c605312f65c Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Sat, 25 Aug 2012 16:02:53 -0400 Subject: [PATCH] Added more image api methods --- MediaBrowser.Api/HttpHandlers/ImageHandler.cs | 10 +- MediaBrowser.ApiInteraction/ApiClient.cs | 195 ++++++++++++++++++ 2 files changed, 204 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs index 48c67eeef2..470e39cd23 100644 --- a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs @@ -52,7 +52,15 @@ namespace MediaBrowser.Api.HttpHandlers { return (await Kernel.Instance.ItemController.GetStudio(studio).ConfigureAwait(false)).PrimaryImagePath; } - + + string userId = QueryString["userid"]; + + if (!string.IsNullOrEmpty(userId)) + { + Guid userIdGuid = new Guid(userId); + return Kernel.Instance.Users.First(u => u.Id == userIdGuid).PrimaryImagePath; + } + BaseItem item = ApiService.GetItemById(QueryString["id"]); string imageIndex = QueryString["index"]; diff --git a/MediaBrowser.ApiInteraction/ApiClient.cs b/MediaBrowser.ApiInteraction/ApiClient.cs index 2e7684cb03..1f7f653df1 100644 --- a/MediaBrowser.ApiInteraction/ApiClient.cs +++ b/MediaBrowser.ApiInteraction/ApiClient.cs @@ -94,6 +94,201 @@ namespace MediaBrowser.ApiInteraction return url; } + /// + /// Gets an image url that can be used to download an image from the api + /// + /// The Id of the user + /// Use if a fixed width is required. Aspect ratio will be preserved. + /// Use if a fixed height is required. Aspect ratio will be preserved. + /// Use if a max width is required. Aspect ratio will be preserved. + /// Use if a max height is required. Aspect ratio will be preserved. + /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice. + public string GetUserImageUrl(Guid userId, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) + { + string url = ApiUrl + "/image"; + + url += "?userId=" + userId.ToString(); + + if (width.HasValue) + { + url += "&width=" + width; + } + if (height.HasValue) + { + url += "&height=" + height; + } + if (maxWidth.HasValue) + { + url += "&maxWidth=" + maxWidth; + } + if (maxHeight.HasValue) + { + url += "&maxHeight=" + maxHeight; + } + if (quality.HasValue) + { + url += "&quality=" + quality; + } + + return url; + } + + /// + /// Gets an image url that can be used to download an image from the api + /// + /// The name of the person + /// Use if a fixed width is required. Aspect ratio will be preserved. + /// Use if a fixed height is required. Aspect ratio will be preserved. + /// Use if a max width is required. Aspect ratio will be preserved. + /// Use if a max height is required. Aspect ratio will be preserved. + /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice. + public string GetPersonImageUrl(string name, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) + { + string url = ApiUrl + "/image"; + + url += "?personname=" + name; + + if (width.HasValue) + { + url += "&width=" + width; + } + if (height.HasValue) + { + url += "&height=" + height; + } + if (maxWidth.HasValue) + { + url += "&maxWidth=" + maxWidth; + } + if (maxHeight.HasValue) + { + url += "&maxHeight=" + maxHeight; + } + if (quality.HasValue) + { + url += "&quality=" + quality; + } + + return url; + } + + /// + /// Gets an image url that can be used to download an image from the api + /// + /// The year + /// Use if a fixed width is required. Aspect ratio will be preserved. + /// Use if a fixed height is required. Aspect ratio will be preserved. + /// Use if a max width is required. Aspect ratio will be preserved. + /// Use if a max height is required. Aspect ratio will be preserved. + /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice. + public string GetYearImageUrl(int year, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) + { + string url = ApiUrl + "/image"; + + url += "?year=" + year; + + if (width.HasValue) + { + url += "&width=" + width; + } + if (height.HasValue) + { + url += "&height=" + height; + } + if (maxWidth.HasValue) + { + url += "&maxWidth=" + maxWidth; + } + if (maxHeight.HasValue) + { + url += "&maxHeight=" + maxHeight; + } + if (quality.HasValue) + { + url += "&quality=" + quality; + } + + return url; + } + + /// + /// Gets an image url that can be used to download an image from the api + /// + /// The name of the genre + /// Use if a fixed width is required. Aspect ratio will be preserved. + /// Use if a fixed height is required. Aspect ratio will be preserved. + /// Use if a max width is required. Aspect ratio will be preserved. + /// Use if a max height is required. Aspect ratio will be preserved. + /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice. + public string GetGenreImageUrl(string name, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) + { + string url = ApiUrl + "/image"; + + url += "?genre=" + name; + + if (width.HasValue) + { + url += "&width=" + width; + } + if (height.HasValue) + { + url += "&height=" + height; + } + if (maxWidth.HasValue) + { + url += "&maxWidth=" + maxWidth; + } + if (maxHeight.HasValue) + { + url += "&maxHeight=" + maxHeight; + } + if (quality.HasValue) + { + url += "&quality=" + quality; + } + + return url; + } + + /// + /// Gets an image url that can be used to download an image from the api + /// + /// The name of the studio + /// Use if a fixed width is required. Aspect ratio will be preserved. + /// Use if a fixed height is required. Aspect ratio will be preserved. + /// Use if a max width is required. Aspect ratio will be preserved. + /// Use if a max height is required. Aspect ratio will be preserved. + /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice. + public string GetStudioImageUrl(string name, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) + { + string url = ApiUrl + "/image"; + + url += "?studio=" + name; + + if (width.HasValue) + { + url += "&width=" + width; + } + if (height.HasValue) + { + url += "&height=" + height; + } + if (maxWidth.HasValue) + { + url += "&maxWidth=" + maxWidth; + } + if (maxHeight.HasValue) + { + url += "&maxHeight=" + maxHeight; + } + if (quality.HasValue) + { + url += "&quality=" + quality; + } + + return url; + } + /// /// 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. ///