瀏覽代碼

add aspect ratio to search results

Luke Pulverenti 9 年之前
父節點
當前提交
e0f47a4c28

+ 1 - 0
MediaBrowser.Api/SearchService.cs

@@ -179,6 +179,7 @@ namespace MediaBrowser.Api
             if (primaryImageTag != null)
             {
                 result.PrimaryImageTag = primaryImageTag;
+                result.PrimaryImageAspectRatio = _dtoService.GetPrimaryImageAspectRatio(item);
             }
 
             SetThumbImageInfo(result, item);

+ 8 - 2
MediaBrowser.Controller/Dto/IDtoService.cs

@@ -22,8 +22,14 @@ namespace MediaBrowser.Controller.Dto
         /// </summary>
         /// <param name="dto">The dto.</param>
         /// <param name="item">The item.</param>
-        /// <param name="fields">The fields.</param>
-        void AttachPrimaryImageAspectRatio(IItemDto dto, IHasImages item, List<ItemFields> fields);
+        void AttachPrimaryImageAspectRatio(IItemDto dto, IHasImages item);
+
+        /// <summary>
+        /// Gets the primary image aspect ratio.
+        /// </summary>
+        /// <param name="item">The item.</param>
+        /// <returns>System.Nullable&lt;System.Double&gt;.</returns>
+        double? GetPrimaryImageAspectRatio(IHasImages item);
 
         /// <summary>
         /// Gets the base item dto.

+ 6 - 0
MediaBrowser.Model/Search/SearchHint.cs

@@ -144,5 +144,11 @@ namespace MediaBrowser.Model.Search
         /// </summary>
         /// <value>The name of the channel.</value>
         public string ChannelName { get; set; }
+
+        /// <summary>
+        /// Gets or sets the primary image aspect ratio.
+        /// </summary>
+        /// <value>The primary image aspect ratio.</value>
+        public double? PrimaryImageAspectRatio { get; set; }
     }
 }

+ 11 - 6
MediaBrowser.Server.Implementations/Dto/DtoService.cs

@@ -305,7 +305,7 @@ namespace MediaBrowser.Server.Implementations.Dto
             {
                 try
                 {
-                    AttachPrimaryImageAspectRatio(dto, item, fields);
+                    AttachPrimaryImageAspectRatio(dto, item);
                 }
                 catch (Exception ex)
                 {
@@ -1745,15 +1745,19 @@ namespace MediaBrowser.Server.Implementations.Dto
         /// </summary>
         /// <param name="dto">The dto.</param>
         /// <param name="item">The item.</param>
-        /// <param name="fields">The fields.</param>
         /// <returns>Task.</returns>
-        public void AttachPrimaryImageAspectRatio(IItemDto dto, IHasImages item, List<ItemFields> fields)
+        public void AttachPrimaryImageAspectRatio(IItemDto dto, IHasImages item)
+        {
+            dto.PrimaryImageAspectRatio = GetPrimaryImageAspectRatio(item);
+        }
+
+        public double? GetPrimaryImageAspectRatio(IHasImages item)
         {
             var imageInfo = item.GetImageInfo(ImageType.Primary, 0);
 
             if (imageInfo == null || !imageInfo.IsLocalFile)
             {
-                return;
+                return null;
             }
 
             ImageSize size;
@@ -1765,7 +1769,7 @@ namespace MediaBrowser.Server.Implementations.Dto
             catch (Exception ex)
             {
                 //_logger.ErrorException("Failed to determine primary image aspect ratio for {0}", ex, path);
-                return;
+                return null;
             }
 
             var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary).ToList();
@@ -1784,8 +1788,9 @@ namespace MediaBrowser.Server.Implementations.Dto
 
             if (size.Width > 0 && size.Height > 0)
             {
-                dto.PrimaryImageAspectRatio = size.Width / size.Height;
+                return size.Width / size.Height;
             }
+            return null;
         }
     }
 }

+ 1 - 4
MediaBrowser.Server.Implementations/Library/UserManager.cs

@@ -403,10 +403,7 @@ namespace MediaBrowser.Server.Implementations.Library
 
                 try
                 {
-                    _dtoServiceFactory().AttachPrimaryImageAspectRatio(dto, user, new List<ItemFields>
-                    {
-                        ItemFields.PrimaryImageAspectRatio
-                    });
+                    _dtoServiceFactory().AttachPrimaryImageAspectRatio(dto, user);
                 }
                 catch (Exception ex)
                 {

+ 1 - 4
MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs

@@ -231,10 +231,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
             {
                 dto.ImageTags[ImageType.Primary] = imageTag;
 
-                _dtoService.AttachPrimaryImageAspectRatio(dto, info, new List<ItemFields>
-                    {
-                        ItemFields.PrimaryImageAspectRatio
-                    });
+                _dtoService.AttachPrimaryImageAspectRatio(dto, info);
             }
 
             if (currentProgram != null)