RecordingHelper.cs 4.2 KB

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