aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Dto
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2015-04-18 20:05:36 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2015-04-18 20:05:36 -0400
commitd155b78360a2d8a945aded31c361f69ad017e8b3 (patch)
tree2f0750264703cf2a44259be4f531e8dc680f9212 /MediaBrowser.Model/Dto
parentb5218034acb3149b6b5db658120611ba1469d8bb (diff)
update hls timer
Diffstat (limited to 'MediaBrowser.Model/Dto')
-rw-r--r--MediaBrowser.Model/Dto/ItemLayout.cs72
1 files changed, 72 insertions, 0 deletions
diff --git a/MediaBrowser.Model/Dto/ItemLayout.cs b/MediaBrowser.Model/Dto/ItemLayout.cs
new file mode 100644
index 0000000000..c85818390d
--- /dev/null
+++ b/MediaBrowser.Model/Dto/ItemLayout.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+
+namespace MediaBrowser.Model.Dto
+{
+ public static class ItemLayout
+ {
+ public static double? GetDisplayAspectRatio(BaseItemDto item)
+ {
+ List<BaseItemDto> items = new List<BaseItemDto>();
+ items.Add(item);
+ return GetDisplayAspectRatio(items);
+ }
+
+ public static double? GetDisplayAspectRatio(List<BaseItemDto> items)
+ {
+ List<double> values = new List<double>();
+
+ foreach (BaseItemDto item in items)
+ {
+ if (item.PrimaryImageAspectRatio.HasValue)
+ {
+ values.Add(item.PrimaryImageAspectRatio.Value);
+ }
+ }
+
+ if (values.Count == 0)
+ {
+ return null;
+ }
+
+ values.Sort();
+
+ double halfDouble = values.Count;
+ halfDouble /= 2;
+ int half = Convert.ToInt32(Math.Floor(halfDouble));
+
+ double result;
+
+ if (values.Count % 2 > 0)
+ result = values[half];
+ else
+ result = (values[half - 1] + values[half]) / 2.0;
+
+ // If really close to 2:3 (poster image), just return 2:3
+ if (Math.Abs(0.66666666667 - result) <= .15)
+ {
+ return 0.66666666667;
+ }
+
+ // If really close to 16:9 (episode image), just return 16:9
+ if (Math.Abs(1.777777778 - result) <= .2)
+ {
+ return 1.777777778;
+ }
+
+ // If really close to 1 (square image), just return 1
+ if (Math.Abs(1 - result) <= .15)
+ {
+ return 1.0;
+ }
+
+ // If really close to 4:3 (poster image), just return 2:3
+ if (Math.Abs(1.33333333333 - result) <= .15)
+ {
+ return 1.33333333333;
+ }
+
+ return result;
+ }
+ }
+}