RecordingHelper.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.KeepUntil = series.KeepUntil;
  26. timer.Priority = series.Priority;
  27. timer.Name = parent.Name;
  28. timer.Overview = parent.Overview;
  29. timer.SeriesTimerId = series.Id;
  30. CopyProgramInfoToTimerInfo(parent, timer);
  31. return timer;
  32. }
  33. public static void CopyProgramInfoToTimerInfo(ProgramInfo programInfo, TimerInfo timerInfo)
  34. {
  35. timerInfo.SeasonNumber = programInfo.SeasonNumber;
  36. timerInfo.EpisodeNumber = programInfo.EpisodeNumber;
  37. timerInfo.IsMovie = programInfo.IsMovie;
  38. timerInfo.IsKids = programInfo.IsKids;
  39. timerInfo.IsNews = programInfo.IsNews;
  40. timerInfo.IsSports = programInfo.IsSports;
  41. timerInfo.ProductionYear = programInfo.ProductionYear;
  42. timerInfo.EpisodeTitle = programInfo.EpisodeTitle;
  43. timerInfo.OriginalAirDate = programInfo.OriginalAirDate;
  44. timerInfo.IsProgramSeries = programInfo.IsSeries;
  45. timerInfo.HomePageUrl = programInfo.HomePageUrl;
  46. timerInfo.CommunityRating = programInfo.CommunityRating;
  47. timerInfo.ShortOverview = programInfo.ShortOverview;
  48. timerInfo.OfficialRating = programInfo.OfficialRating;
  49. }
  50. public static string GetRecordingName(TimerInfo info)
  51. {
  52. var name = info.Name;
  53. if (info.IsProgramSeries)
  54. {
  55. var addHyphen = true;
  56. if (info.SeasonNumber.HasValue && info.EpisodeNumber.HasValue)
  57. {
  58. name += string.Format(" S{0}E{1}", info.SeasonNumber.Value.ToString("00", CultureInfo.InvariantCulture), info.EpisodeNumber.Value.ToString("00", CultureInfo.InvariantCulture));
  59. addHyphen = false;
  60. }
  61. else if (info.OriginalAirDate.HasValue)
  62. {
  63. name += " " + info.OriginalAirDate.Value.ToString("yyyy-MM-dd");
  64. }
  65. else
  66. {
  67. name += " " + DateTime.Now.ToString("yyyy-MM-dd");
  68. }
  69. if (!string.IsNullOrWhiteSpace(info.EpisodeTitle))
  70. {
  71. if (addHyphen)
  72. {
  73. name += " -";
  74. }
  75. name += " " + info.EpisodeTitle;
  76. }
  77. }
  78. else if (info.IsMovie && info.ProductionYear != null)
  79. {
  80. name += " (" + info.ProductionYear + ")";
  81. }
  82. else
  83. {
  84. name += " " + info.StartDate.ToString("yyyy-MM-dd") + " " + info.Id;
  85. }
  86. return name;
  87. }
  88. }
  89. }