From 2b7d139b5b6a86bc742cfcd2312379d5c70f7529 Mon Sep 17 00:00:00 2001 From: JaanTaponen Date: Sun, 17 Apr 2022 16:46:01 +0300 Subject: [PATCH 1/2] Fix XMLTV edge case where title & sub-title causes a too long filename error Limit the series title to 241 bytes (so file extensions can be added). If the end result is longer, the title will be dropped and only series name with timestamp is used. --- .../LiveTv/EmbyTV/RecordingHelper.cs | 14 +++++++++++--- .../LiveTv/RecordingHelperTests.cs | 11 +++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs index 32245f899e..87f94cb085 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs @@ -3,6 +3,7 @@ using System; using System.Globalization; using MediaBrowser.Controller.LiveTv; +using System.Text; namespace Emby.Server.Implementations.LiveTv.EmbyTV { @@ -48,12 +49,19 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV if (!string.IsNullOrWhiteSpace(info.EpisodeTitle)) { + var tmpName = name; if (addHyphen) { - name += " -"; + tmpName += " -"; + } + // Calculate the length of the resulting filename + var recordingNameLength = Encoding.UTF8.GetByteCount(tmpName) + Encoding.UTF8.GetByteCount(info.EpisodeTitle); + // Since the filename will be used with file ext. (.mp4, .ts, etc) + if (recordingNameLength < 250) + { + tmpName += " " + info.EpisodeTitle; + name = tmpName; } - - name += " " + info.EpisodeTitle; } } else if (info.IsMovie && info.ProductionYear != null) diff --git a/tests/Jellyfin.Server.Implementations.Tests/LiveTv/RecordingHelperTests.cs b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/RecordingHelperTests.cs index 09aec82b07..f107b1ef97 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/LiveTv/RecordingHelperTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/RecordingHelperTests.cs @@ -85,6 +85,17 @@ namespace Jellyfin.Server.Implementations.Tests.LiveTv EpisodeTitle = "The VCR Illumination" }); + data.Add( + "Lorem ipsum dolor sit amet: consect 2018_12_06_21_06_00", + new TimerInfo + { + Name = "Lorem ipsum dolor sit amet: consect", + IsProgramSeries = true, + StartDate = new DateTime(2018, 12, 6, 21, 6, 0, DateTimeKind.Local), + OriginalAirDate = new DateTime(2018, 12, 6), + EpisodeTitle = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor" + }); + return data; } From b6a2640f22ddfc76a871a1f3bf5fdc223b3b2db4 Mon Sep 17 00:00:00 2001 From: Jaan Taponen Date: Sat, 30 Apr 2022 22:24:11 +0300 Subject: [PATCH 2/2] Update Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs Co-authored-by: Joe Rogers <1337joe@users.noreply.github.com> --- .../LiveTv/EmbyTV/RecordingHelper.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs index 87f94cb085..6ad9ccdf6e 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/RecordingHelper.cs @@ -54,12 +54,11 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV { tmpName += " -"; } - // Calculate the length of the resulting filename - var recordingNameLength = Encoding.UTF8.GetByteCount(tmpName) + Encoding.UTF8.GetByteCount(info.EpisodeTitle); + + tmpName += " " + info.EpisodeTitle; // Since the filename will be used with file ext. (.mp4, .ts, etc) - if (recordingNameLength < 250) + if (Encoding.UTF8.GetByteCount(tmpName) < 250) { - tmpName += " " + info.EpisodeTitle; name = tmpName; } }