RecordingHelper.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using MediaBrowser.Common.Extensions;
  2. using MediaBrowser.Controller.LiveTv;
  3. using System;
  4. using System.Text;
  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. return timer;
  30. }
  31. public static string GetRecordingName(TimerInfo timer, ProgramInfo info)
  32. {
  33. if (info == null)
  34. {
  35. return (timer.ProgramId + ".ts");
  36. }
  37. var fancyName = info.Name;
  38. if (info.ProductionYear != null)
  39. {
  40. fancyName += "_(" + info.ProductionYear + ")";
  41. }
  42. if (info.IsSeries)
  43. {
  44. fancyName += "_" + info.EpisodeTitle.Replace("Season: ", "S").Replace(" Episode: ", "E");
  45. }
  46. if (info.IsHD ?? false)
  47. {
  48. fancyName += "_HD";
  49. }
  50. if (info.OriginalAirDate != null)
  51. {
  52. fancyName += "_" + info.OriginalAirDate.Value.ToString("yyyy-MM-dd");
  53. }
  54. return RemoveSpecialCharacters(fancyName) + ".ts";
  55. }
  56. public static string RemoveSpecialCharacters(string str)
  57. {
  58. StringBuilder sb = new StringBuilder();
  59. foreach (char c in str)
  60. {
  61. if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '.' || c == '_' || c == '-' || c == ' ')
  62. {
  63. sb.Append(c);
  64. }
  65. }
  66. return sb.ToString();
  67. }
  68. }
  69. }