AirTimeComparer.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Entities.TV;
  3. using MediaBrowser.Controller.Sorting;
  4. using MediaBrowser.Model.Querying;
  5. using System;
  6. namespace MediaBrowser.Server.Implementations.Sorting
  7. {
  8. public class AirTimeComparer : IBaseItemComparer
  9. {
  10. /// <summary>
  11. /// Compares the specified x.
  12. /// </summary>
  13. /// <param name="x">The x.</param>
  14. /// <param name="y">The y.</param>
  15. /// <returns>System.Int32.</returns>
  16. public int Compare(BaseItem x, BaseItem y)
  17. {
  18. return DateTime.Compare(GetValue(x), GetValue(y));
  19. }
  20. /// <summary>
  21. /// Gets the value.
  22. /// </summary>
  23. /// <param name="x">The x.</param>
  24. /// <returns>System.String.</returns>
  25. private DateTime GetValue(BaseItem x)
  26. {
  27. var series = x as Series;
  28. if (series == null)
  29. {
  30. var season = x as Season;
  31. if (season != null)
  32. {
  33. series = season.Series;
  34. }
  35. else
  36. {
  37. var episode = x as Episode;
  38. if (episode != null)
  39. {
  40. series = episode.Series;
  41. }
  42. }
  43. }
  44. if (series != null)
  45. {
  46. DateTime result;
  47. if (DateTime.TryParse(series.AirTime, out result))
  48. {
  49. return result;
  50. }
  51. }
  52. return DateTime.MinValue;
  53. }
  54. /// <summary>
  55. /// Gets the name.
  56. /// </summary>
  57. /// <value>The name.</value>
  58. public string Name
  59. {
  60. get { return ItemSortBy.AirTime; }
  61. }
  62. }
  63. }