using System; using System.Text.RegularExpressions; namespace ytLive.Services; /// /// TASK 32·3 — naming the broadcast that resumes a dropped show. A resumed stream is a NEW broadcast /// with a new VOD (YouTube cannot resume a completed one), so the title has to say so; otherwise the /// channel grows two identically named videos and the creator has to explain it. /// Pure, because the interesting cases are the boring ones: a title already marked, a second drop /// in the same session, and YouTube's 100-character limit. /// public static class BroadcastTitle { public const int MaxLength = 100; private static readonly Regex ResumeMarker = new(@"\s*\(resumed(?: \d+)?\)\s*$", RegexOptions.IgnoreCase | RegexOptions.Compiled); /// The title for resume number (1 = first re-air). /// Any existing marker is replaced rather than stacked, and the base is truncated so the whole /// title fits YouTube's limit. public static string ForResume(string? title, int resumeCount) { var baseTitle = ResumeMarker.Replace(title ?? string.Empty, string.Empty).Trim(); if (baseTitle.Length == 0) baseTitle = "LlamaCasty"; var marker = resumeCount <= 1 ? " (resumed)" : $" (resumed {Math.Max(2, resumeCount)})"; var room = MaxLength - marker.Length; if (baseTitle.Length > room) baseTitle = baseTitle[..room].TrimEnd(); return baseTitle + marker; } }