jellyfin-server/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs

84 lines
2.7 KiB
C#
Raw Normal View History

#pragma warning disable CS1591
using System;
2015-08-20 23:55:23 +00:00
using System.Globalization;
using System.Text;
using MediaBrowser.Controller.LiveTv;
2015-07-20 18:32:55 +00:00
2016-11-03 23:35:19 +00:00
namespace Emby.Server.Implementations.LiveTv.EmbyTV
2015-07-20 18:32:55 +00:00
{
2021-05-15 19:49:04 +00:00
internal static class RecordingHelper
2015-07-20 18:32:55 +00:00
{
public static DateTime GetStartTime(TimerInfo timer)
{
return timer.StartDate.AddSeconds(-timer.PrePaddingSeconds);
}
2016-09-15 06:23:39 +00:00
public static string GetRecordingName(TimerInfo info)
{
2015-08-20 23:55:23 +00:00
var name = info.Name;
2016-09-15 06:23:39 +00:00
if (info.IsProgramSeries)
2015-07-20 18:32:55 +00:00
{
2015-08-26 02:13:28 +00:00
var addHyphen = true;
2015-08-20 23:55:23 +00:00
if (info.SeasonNumber.HasValue && info.EpisodeNumber.HasValue)
{
name += string.Format(
CultureInfo.InvariantCulture,
" S{0}E{1}",
info.SeasonNumber.Value.ToString("00", CultureInfo.InvariantCulture),
info.EpisodeNumber.Value.ToString("00", CultureInfo.InvariantCulture));
2015-08-26 02:13:28 +00:00
addHyphen = false;
2015-08-20 23:55:23 +00:00
}
else if (info.OriginalAirDate.HasValue)
{
2018-09-12 17:26:21 +00:00
if (info.OriginalAirDate.Value.Date.Equals(info.StartDate.Date))
{
name += " " + GetDateString(info.StartDate);
}
else
{
name += " " + info.OriginalAirDate.Value.ToLocalTime().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
2018-09-12 17:26:21 +00:00
}
2015-08-20 23:55:23 +00:00
}
2016-08-29 18:42:53 +00:00
else
{
2018-09-12 17:26:21 +00:00
name += " " + GetDateString(info.StartDate);
2016-08-29 18:42:53 +00:00
}
2015-08-21 02:36:30 +00:00
if (!string.IsNullOrWhiteSpace(info.EpisodeTitle))
2015-08-20 23:55:23 +00:00
{
var tmpName = name;
2016-03-01 04:24:42 +00:00
if (addHyphen)
{
tmpName += " -";
2016-03-01 04:24:42 +00:00
}
tmpName += " " + info.EpisodeTitle;
// Since the filename will be used with file ext. (.mp4, .ts, etc)
if (Encoding.UTF8.GetByteCount(tmpName) < 250)
{
name = tmpName;
}
2015-08-20 23:55:23 +00:00
}
2015-07-20 18:32:55 +00:00
}
2015-09-22 01:05:33 +00:00
else if (info.IsMovie && info.ProductionYear != null)
2015-07-20 18:32:55 +00:00
{
2015-08-20 23:55:23 +00:00
name += " (" + info.ProductionYear + ")";
2015-07-20 18:32:55 +00:00
}
2015-09-22 01:05:33 +00:00
else
{
2018-09-12 17:26:21 +00:00
name += " " + GetDateString(info.StartDate);
2015-09-22 01:05:33 +00:00
}
2015-08-20 23:55:23 +00:00
2015-08-21 02:36:30 +00:00
return name;
2015-07-20 18:32:55 +00:00
}
2018-09-12 17:26:21 +00:00
private static string GetDateString(DateTime date)
{
2021-05-15 19:49:04 +00:00
return date.ToLocalTime().ToString("yyyy_MM_dd_HH_mm_ss", CultureInfo.InvariantCulture);
2018-09-12 17:26:21 +00:00
}
2015-07-20 18:32:55 +00:00
}
}