RecordingHelper.cs 3.9 KB

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