RecordingHelper.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. }
  44. public static string GetRecordingName(TimerInfo info)
  45. {
  46. var name = info.Name;
  47. if (info.IsProgramSeries)
  48. {
  49. var addHyphen = true;
  50. if (info.SeasonNumber.HasValue && info.EpisodeNumber.HasValue)
  51. {
  52. name += string.Format(" S{0}E{1}", info.SeasonNumber.Value.ToString("00", CultureInfo.InvariantCulture), info.EpisodeNumber.Value.ToString("00", CultureInfo.InvariantCulture));
  53. addHyphen = false;
  54. }
  55. else if (info.OriginalAirDate.HasValue)
  56. {
  57. name += " " + info.OriginalAirDate.Value.ToString("yyyy-MM-dd");
  58. }
  59. else
  60. {
  61. name += " " + DateTime.Now.ToString("yyyy-MM-dd");
  62. }
  63. if (!string.IsNullOrWhiteSpace(info.EpisodeTitle))
  64. {
  65. if (addHyphen)
  66. {
  67. name += " -";
  68. }
  69. name += " " + info.EpisodeTitle;
  70. }
  71. }
  72. else if (info.IsMovie && info.ProductionYear != null)
  73. {
  74. name += " (" + info.ProductionYear + ")";
  75. }
  76. else
  77. {
  78. name += " " + info.StartDate.ToString("yyyy-MM-dd") + " " + info.Id;
  79. }
  80. return name;
  81. }
  82. }
  83. }