aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Sorting
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Server.Implementations/Sorting')
-rw-r--r--MediaBrowser.Server.Implementations/Sorting/AlbumArtistComparer.cs46
-rw-r--r--MediaBrowser.Server.Implementations/Sorting/AlbumComparer.cs46
-rw-r--r--MediaBrowser.Server.Implementations/Sorting/ArtistComparer.cs46
-rw-r--r--MediaBrowser.Server.Implementations/Sorting/CommunityRatingComparer.cs29
-rw-r--r--MediaBrowser.Server.Implementations/Sorting/DateCreatedComparer.cs33
-rw-r--r--MediaBrowser.Server.Implementations/Sorting/DatePlayedComparer.cs56
-rw-r--r--MediaBrowser.Server.Implementations/Sorting/PremiereDateComparer.cs52
-rw-r--r--MediaBrowser.Server.Implementations/Sorting/ProductionYearComparer.cs52
-rw-r--r--MediaBrowser.Server.Implementations/Sorting/RandomComparer.cs33
-rw-r--r--MediaBrowser.Server.Implementations/Sorting/RuntimeComparer.cs32
-rw-r--r--MediaBrowser.Server.Implementations/Sorting/SortNameComparer.cs33
11 files changed, 458 insertions, 0 deletions
diff --git a/MediaBrowser.Server.Implementations/Sorting/AlbumArtistComparer.cs b/MediaBrowser.Server.Implementations/Sorting/AlbumArtistComparer.cs
new file mode 100644
index 000000000..e045cdfc8
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Sorting/AlbumArtistComparer.cs
@@ -0,0 +1,46 @@
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities.Audio;
+using MediaBrowser.Controller.Sorting;
+using MediaBrowser.Model.Dto;
+using System;
+
+namespace MediaBrowser.Server.Implementations.Sorting
+{
+ /// <summary>
+ /// Class AlbumArtistComparer
+ /// </summary>
+ public class AlbumArtistComparer : IBaseItemComparer
+ {
+ /// <summary>
+ /// Compares the specified x.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <param name="y">The y.</param>
+ /// <returns>System.Int32.</returns>
+ public int Compare(BaseItem x, BaseItem y)
+ {
+ return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase);
+ }
+
+ /// <summary>
+ /// Gets the value.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <returns>System.String.</returns>
+ private string GetValue(BaseItem x)
+ {
+ var audio = x as Audio;
+
+ return audio == null ? string.Empty : audio.AlbumArtist;
+ }
+
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ public string Name
+ {
+ get { return ItemSortBy.AlbumArtist; }
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/Sorting/AlbumComparer.cs b/MediaBrowser.Server.Implementations/Sorting/AlbumComparer.cs
new file mode 100644
index 000000000..24e1f40da
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Sorting/AlbumComparer.cs
@@ -0,0 +1,46 @@
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities.Audio;
+using MediaBrowser.Controller.Sorting;
+using MediaBrowser.Model.Dto;
+using System;
+
+namespace MediaBrowser.Server.Implementations.Sorting
+{
+ /// <summary>
+ /// Class AlbumComparer
+ /// </summary>
+ public class AlbumComparer : IBaseItemComparer
+ {
+ /// <summary>
+ /// Compares the specified x.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <param name="y">The y.</param>
+ /// <returns>System.Int32.</returns>
+ public int Compare(BaseItem x, BaseItem y)
+ {
+ return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase);
+ }
+
+ /// <summary>
+ /// Gets the value.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <returns>System.String.</returns>
+ private string GetValue(BaseItem x)
+ {
+ var audio = x as Audio;
+
+ return audio == null ? string.Empty : audio.Album;
+ }
+
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ public string Name
+ {
+ get { return ItemSortBy.Album; }
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/Sorting/ArtistComparer.cs b/MediaBrowser.Server.Implementations/Sorting/ArtistComparer.cs
new file mode 100644
index 000000000..278a39785
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Sorting/ArtistComparer.cs
@@ -0,0 +1,46 @@
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities.Audio;
+using MediaBrowser.Controller.Sorting;
+using MediaBrowser.Model.Dto;
+using System;
+
+namespace MediaBrowser.Server.Implementations.Sorting
+{
+ /// <summary>
+ /// Class ArtistComparer
+ /// </summary>
+ public class ArtistComparer : IBaseItemComparer
+ {
+ /// <summary>
+ /// Compares the specified x.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <param name="y">The y.</param>
+ /// <returns>System.Int32.</returns>
+ public int Compare(BaseItem x, BaseItem y)
+ {
+ return string.Compare(GetValue(x), GetValue(y), StringComparison.CurrentCultureIgnoreCase);
+ }
+
+ /// <summary>
+ /// Gets the value.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <returns>System.String.</returns>
+ private string GetValue(BaseItem x)
+ {
+ var audio = x as Audio;
+
+ return audio == null ? string.Empty : audio.Artist;
+ }
+
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ public string Name
+ {
+ get { return ItemSortBy.Artist; }
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/Sorting/CommunityRatingComparer.cs b/MediaBrowser.Server.Implementations/Sorting/CommunityRatingComparer.cs
new file mode 100644
index 000000000..2e1b73ccf
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Sorting/CommunityRatingComparer.cs
@@ -0,0 +1,29 @@
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Sorting;
+using MediaBrowser.Model.Dto;
+
+namespace MediaBrowser.Server.Implementations.Sorting
+{
+ public class CommunityRatingComparer : IBaseItemComparer
+ {
+ /// <summary>
+ /// Compares the specified x.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <param name="y">The y.</param>
+ /// <returns>System.Int32.</returns>
+ public int Compare(BaseItem x, BaseItem y)
+ {
+ return (x.CommunityRating ?? 0).CompareTo(y.CommunityRating ?? 0);
+ }
+
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ public string Name
+ {
+ get { return ItemSortBy.CommunityRating; }
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/Sorting/DateCreatedComparer.cs b/MediaBrowser.Server.Implementations/Sorting/DateCreatedComparer.cs
new file mode 100644
index 000000000..d340913c9
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Sorting/DateCreatedComparer.cs
@@ -0,0 +1,33 @@
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Sorting;
+using MediaBrowser.Model.Dto;
+using System;
+
+namespace MediaBrowser.Server.Implementations.Sorting
+{
+ /// <summary>
+ /// Class DateCreatedComparer
+ /// </summary>
+ public class DateCreatedComparer : IBaseItemComparer
+ {
+ /// <summary>
+ /// Compares the specified x.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <param name="y">The y.</param>
+ /// <returns>System.Int32.</returns>
+ public int Compare(BaseItem x, BaseItem y)
+ {
+ return DateTime.Compare(x.DateCreated, y.DateCreated);
+ }
+
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ public string Name
+ {
+ get { return ItemSortBy.DateCreated; }
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/Sorting/DatePlayedComparer.cs b/MediaBrowser.Server.Implementations/Sorting/DatePlayedComparer.cs
new file mode 100644
index 000000000..49e464559
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Sorting/DatePlayedComparer.cs
@@ -0,0 +1,56 @@
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Sorting;
+using MediaBrowser.Model.Dto;
+using System;
+
+namespace MediaBrowser.Server.Implementations.Sorting
+{
+ /// <summary>
+ /// Class DatePlayedComparer
+ /// </summary>
+ public class DatePlayedComparer : IUserBaseItemComparer
+ {
+ /// <summary>
+ /// Gets or sets the user.
+ /// </summary>
+ /// <value>The user.</value>
+ public User User { get; set; }
+
+ /// <summary>
+ /// Compares the specified x.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <param name="y">The y.</param>
+ /// <returns>System.Int32.</returns>
+ public int Compare(BaseItem x, BaseItem y)
+ {
+ return GetDate(x).CompareTo(GetDate(y));
+ }
+
+ /// <summary>
+ /// Gets the date.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <returns>DateTime.</returns>
+ private DateTime GetDate(BaseItem x)
+ {
+ var userdata = x.GetUserData(User, false);
+
+ if (userdata != null && userdata.LastPlayedDate.HasValue)
+ {
+ return userdata.LastPlayedDate.Value;
+ }
+
+ return DateTime.MaxValue;
+ }
+
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ public string Name
+ {
+ get { return ItemSortBy.DatePlayed; }
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/Sorting/PremiereDateComparer.cs b/MediaBrowser.Server.Implementations/Sorting/PremiereDateComparer.cs
new file mode 100644
index 000000000..2a8d52405
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Sorting/PremiereDateComparer.cs
@@ -0,0 +1,52 @@
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Sorting;
+using MediaBrowser.Model.Dto;
+using System;
+
+namespace MediaBrowser.Server.Implementations.Sorting
+{
+ /// <summary>
+ /// Class PremiereDateComparer
+ /// </summary>
+ public class PremiereDateComparer : IBaseItemComparer
+ {
+ /// <summary>
+ /// Compares the specified x.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <param name="y">The y.</param>
+ /// <returns>System.Int32.</returns>
+ public int Compare(BaseItem x, BaseItem y)
+ {
+ return GetDate(x).CompareTo(GetDate(y));
+ }
+
+ /// <summary>
+ /// Gets the date.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <returns>DateTime.</returns>
+ private DateTime GetDate(BaseItem x)
+ {
+ if (x.PremiereDate.HasValue)
+ {
+ return x.PremiereDate.Value;
+ }
+
+ if (x.ProductionYear.HasValue)
+ {
+ return new DateTime(x.ProductionYear.Value, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+ }
+ return DateTime.MaxValue;
+ }
+
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ public string Name
+ {
+ get { return ItemSortBy.PremiereDate; }
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/Sorting/ProductionYearComparer.cs b/MediaBrowser.Server.Implementations/Sorting/ProductionYearComparer.cs
new file mode 100644
index 000000000..47a03048c
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Sorting/ProductionYearComparer.cs
@@ -0,0 +1,52 @@
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Sorting;
+using MediaBrowser.Model.Dto;
+
+namespace MediaBrowser.Server.Implementations.Sorting
+{
+ /// <summary>
+ /// Class ProductionYearComparer
+ /// </summary>
+ public class ProductionYearComparer : IBaseItemComparer
+ {
+ /// <summary>
+ /// Compares the specified x.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <param name="y">The y.</param>
+ /// <returns>System.Int32.</returns>
+ public int Compare(BaseItem x, BaseItem y)
+ {
+ return GetValue(x).CompareTo(GetValue(y));
+ }
+
+ /// <summary>
+ /// Gets the date.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <returns>DateTime.</returns>
+ private int GetValue(BaseItem x)
+ {
+ if (x.ProductionYear.HasValue)
+ {
+ return x.ProductionYear.Value;
+ }
+
+ if (x.PremiereDate.HasValue)
+ {
+ return x.PremiereDate.Value.Year;
+ }
+
+ return 0;
+ }
+
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ public string Name
+ {
+ get { return ItemSortBy.ProductionYear; }
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/Sorting/RandomComparer.cs b/MediaBrowser.Server.Implementations/Sorting/RandomComparer.cs
new file mode 100644
index 000000000..e7e98a8a0
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Sorting/RandomComparer.cs
@@ -0,0 +1,33 @@
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Sorting;
+using MediaBrowser.Model.Dto;
+using System;
+
+namespace MediaBrowser.Server.Implementations.Sorting
+{
+ /// <summary>
+ /// Class RandomComparer
+ /// </summary>
+ public class RandomComparer : IBaseItemComparer
+ {
+ /// <summary>
+ /// Compares the specified x.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <param name="y">The y.</param>
+ /// <returns>System.Int32.</returns>
+ public int Compare(BaseItem x, BaseItem y)
+ {
+ return Guid.NewGuid().CompareTo(Guid.NewGuid());
+ }
+
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ public string Name
+ {
+ get { return ItemSortBy.Random; }
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/Sorting/RuntimeComparer.cs b/MediaBrowser.Server.Implementations/Sorting/RuntimeComparer.cs
new file mode 100644
index 000000000..71893ef31
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Sorting/RuntimeComparer.cs
@@ -0,0 +1,32 @@
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Sorting;
+using MediaBrowser.Model.Dto;
+
+namespace MediaBrowser.Server.Implementations.Sorting
+{
+ /// <summary>
+ /// Class RuntimeComparer
+ /// </summary>
+ public class RuntimeComparer : IBaseItemComparer
+ {
+ /// <summary>
+ /// Compares the specified x.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <param name="y">The y.</param>
+ /// <returns>System.Int32.</returns>
+ public int Compare(BaseItem x, BaseItem y)
+ {
+ return (x.RunTimeTicks ?? 0).CompareTo(y.RunTimeTicks ?? 0);
+ }
+
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ public string Name
+ {
+ get { return ItemSortBy.Runtime; }
+ }
+ }
+}
diff --git a/MediaBrowser.Server.Implementations/Sorting/SortNameComparer.cs b/MediaBrowser.Server.Implementations/Sorting/SortNameComparer.cs
new file mode 100644
index 000000000..067f8c453
--- /dev/null
+++ b/MediaBrowser.Server.Implementations/Sorting/SortNameComparer.cs
@@ -0,0 +1,33 @@
+using MediaBrowser.Controller.Entities;
+using System;
+using MediaBrowser.Controller.Sorting;
+using MediaBrowser.Model.Dto;
+
+namespace MediaBrowser.Server.Implementations.Sorting
+{
+ /// <summary>
+ /// Class SortNameComparer
+ /// </summary>
+ public class SortNameComparer : IBaseItemComparer
+ {
+ /// <summary>
+ /// Compares the specified x.
+ /// </summary>
+ /// <param name="x">The x.</param>
+ /// <param name="y">The y.</param>
+ /// <returns>System.Int32.</returns>
+ public int Compare(BaseItem x, BaseItem y)
+ {
+ return string.Compare(x.SortName, y.SortName, StringComparison.CurrentCultureIgnoreCase);
+ }
+
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>The name.</value>
+ public string Name
+ {
+ get { return ItemSortBy.SortName; }
+ }
+ }
+}