RecordingHelper.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using MediaBrowser.Common.Extensions;
  2. using MediaBrowser.Controller.LiveTv;
  3. using System;
  4. using System.Globalization;
  5. namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
  6. {
  7. internal class RecordingHelper
  8. {
  9. public static DateTime GetStartTime(TimerInfo timer)
  10. {
  11. return timer.StartDate.AddSeconds(-timer.PrePaddingSeconds);
  12. }
  13. public static TimerInfo CreateTimer(ProgramInfo parent, SeriesTimerInfo series)
  14. {
  15. var timer = new TimerInfo();
  16. timer.ChannelId = parent.ChannelId;
  17. timer.Id = (series.Id + parent.Id).GetMD5().ToString("N");
  18. timer.StartDate = parent.StartDate;
  19. timer.EndDate = parent.EndDate;
  20. timer.ProgramId = parent.Id;
  21. timer.PrePaddingSeconds = series.PrePaddingSeconds;
  22. timer.PostPaddingSeconds = series.PostPaddingSeconds;
  23. timer.IsPostPaddingRequired = series.IsPostPaddingRequired;
  24. timer.IsPrePaddingRequired = series.IsPrePaddingRequired;
  25. timer.Priority = series.Priority;
  26. timer.Name = parent.Name;
  27. timer.Overview = parent.Overview;
  28. timer.SeriesTimerId = series.Id;
  29. CopyProgramInfoToTimerInfo(parent, timer);
  30. return timer;
  31. }
  32. public static void CopyProgramInfoToTimerInfo(ProgramInfo programInfo, TimerInfo timerInfo)
  33. {
  34. timerInfo.SeasonNumber = programInfo.SeasonNumber;
  35. timerInfo.EpisodeNumber = programInfo.EpisodeNumber;
  36. timerInfo.IsMovie = programInfo.IsMovie;
  37. timerInfo.IsKids = programInfo.IsKids;
  38. timerInfo.IsSports = programInfo.IsSports;
  39. timerInfo.ProductionYear = programInfo.ProductionYear;
  40. timerInfo.EpisodeTitle = programInfo.EpisodeTitle;
  41. timerInfo.OriginalAirDate = programInfo.OriginalAirDate;
  42. timerInfo.IsProgramSeries = programInfo.IsSeries;
  43. timerInfo.HomePageUrl = programInfo.HomePageUrl;
  44. timerInfo.CommunityRating = programInfo.CommunityRating;
  45. timerInfo.ShortOverview = programInfo.ShortOverview;
  46. timerInfo.OfficialRating = programInfo.OfficialRating;
  47. }
  48. public static string GetRecordingName(TimerInfo info)
  49. {
  50. var name = info.Name;
  51. if (info.IsProgramSeries)
  52. {
  53. var addHyphen = true;
  54. if (info.SeasonNumber.HasValue && info.EpisodeNumber.HasValue)
  55. {
  56. name += string.Format(" S{0}E{1}", info.SeasonNumber.Value.ToString("00", CultureInfo.InvariantCulture), info.EpisodeNumber.Value.ToString("00", CultureInfo.InvariantCulture));
  57. addHyphen = false;
  58. }
  59. else if (info.OriginalAirDate.HasValue)
  60. {
  61. name += " " + info.OriginalAirDate.Value.ToString("yyyy-MM-dd");
  62. }
  63. else
  64. {
  65. name += " " + DateTime.Now.ToString("yyyy-MM-dd");
  66. }
  67. if (!string.IsNullOrWhiteSpace(info.EpisodeTitle))
  68. {
  69. if (addHyphen)
  70. {
  71. name += " -";
  72. }
  73. name += " " + info.EpisodeTitle;
  74. }
  75. }
  76. else if (info.IsMovie && info.ProductionYear != null)
  77. {
  78. name += " (" + info.ProductionYear + ")";
  79. }
  80. else
  81. {
  82. name += " " + info.StartDate.ToString("yyyy-MM-dd") + " " + info.Id;
  83. }
  84. return name;
  85. }
  86. }
  87. }