using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using ErsatzTV.Core.Domain; using static LanguageExt.Prelude; namespace ErsatzTV.Core.Iptv { public class ChannelGuide { private readonly List _channels; private readonly string _host; private readonly string _scheme; public ChannelGuide(string scheme, string host, List channels) { _scheme = scheme; _host = host; _channels = channels; } public string ToXml() { var sb = new StringBuilder(); sb.AppendLine(""); sb.AppendLine(""); foreach (Channel channel in _channels) { sb.AppendLine($""); sb.AppendLine($"{channel.Name}"); sb.AppendLine( !string.IsNullOrWhiteSpace(channel.Logo) ? $"" : $""); sb.AppendLine(""); } foreach (Channel channel in _channels) { foreach (PlayoutItem playoutItem in channel.Playouts.Collect(p => p.Items).OrderBy(i => i.Start)) { string start = playoutItem.Start.ToString("yyyyMMddHHmmss zzz").Replace(":", string.Empty); string stop = playoutItem.Finish.ToString("yyyyMMddHHmmss zzz").Replace(":", string.Empty); MediaMetadata metadata = Optional(playoutItem.MediaItem.Metadata).IfNone( new MediaMetadata { Title = Path.GetFileName(playoutItem.MediaItem.Path) }); sb.AppendLine( $""); sb.AppendLine($"{metadata.Title}"); sb.AppendLine(""); sb.AppendLine(""); int season = Optional(metadata.SeasonNumber).IfNone(0); int episode = Optional(metadata.EpisodeNumber).IfNone(0); if (season > 0 && episode > 0) { sb.AppendLine($"{season - 1}.{episode - 1}.0/1"); } // sb.AppendLine(""); sb.AppendLine($"{metadata.Description}"); if (!string.IsNullOrWhiteSpace(metadata.ContentRating)) { sb.AppendLine(""); sb.AppendLine($"{metadata.ContentRating}"); sb.AppendLine(""); } sb.AppendLine(""); } } sb.AppendLine(""); return sb.ToString(); } } }