浏览代码

Added more image api methods

LukePulverenti Luke Pulverenti luke pulverenti 12 年之前
父节点
当前提交
c124672636
共有 2 个文件被更改,包括 204 次插入1 次删除
  1. 9 1
      MediaBrowser.Api/HttpHandlers/ImageHandler.cs
  2. 195 0
      MediaBrowser.ApiInteraction/ApiClient.cs

+ 9 - 1
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"];

+ 195 - 0
MediaBrowser.ApiInteraction/ApiClient.cs

@@ -94,6 +94,201 @@ namespace MediaBrowser.ApiInteraction
             return url;
         }
 
+        /// <summary>
+        /// Gets an image url that can be used to download an image from the api
+        /// </summary>
+        /// <param name="userId">The Id of the user</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 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;
+        }
+
+        /// <summary>
+        /// Gets an image url that can be used to download an image from the api
+        /// </summary>
+        /// <param name="name">The name of the person</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 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;
+        }
+
+        /// <summary>
+        /// Gets an image url that can be used to download an image from the api
+        /// </summary>
+        /// <param name="year">The year</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 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;
+        }
+
+        /// <summary>
+        /// Gets an image url that can be used to download an image from the api
+        /// </summary>
+        /// <param name="name">The name of the genre</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 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;
+        }
+
+        /// <summary>
+        /// Gets an image url that can be used to download an image from the api
+        /// </summary>
+        /// <param name="name">The name of the studio</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 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;
+        }
+        
         /// <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>