* fix validation in new form layout * pin mediatr to last oss version * update dependencies * cleanup code in core * cleanup code in ffmpeg * cleanup code in infra * cleanup code in scanner * cleanup code in application * cleanup main code * cleanup test code * solution-wide code cleanup
48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using System.Globalization;
|
|
using System.Text;
|
|
using System.Xml;
|
|
using Microsoft.IO;
|
|
|
|
namespace ErsatzTV.Core.Iptv;
|
|
|
|
public class ChannelGuide
|
|
{
|
|
private readonly Dictionary<string, string> _channelDataFragments;
|
|
private readonly string _channelsFragment;
|
|
private readonly RecyclableMemoryStreamManager _recyclableMemoryStreamManager;
|
|
|
|
public ChannelGuide(
|
|
RecyclableMemoryStreamManager recyclableMemoryStreamManager,
|
|
string channelsFragment,
|
|
Dictionary<string, string> channelDataFragments)
|
|
{
|
|
_recyclableMemoryStreamManager = recyclableMemoryStreamManager;
|
|
_channelsFragment = channelsFragment;
|
|
_channelDataFragments = channelDataFragments;
|
|
}
|
|
|
|
public string ToXml()
|
|
{
|
|
using RecyclableMemoryStream ms = _recyclableMemoryStreamManager.GetStream();
|
|
using var xml = XmlWriter.Create(ms);
|
|
xml.WriteStartDocument();
|
|
|
|
xml.WriteStartElement("tv");
|
|
xml.WriteAttributeString("generator-info-name", "ersatztv");
|
|
|
|
xml.WriteRaw(_channelsFragment);
|
|
|
|
foreach ((string channelNumber, string channelDataFragment) in _channelDataFragments.OrderBy(kvp =>
|
|
decimal.Parse(kvp.Key, CultureInfo.InvariantCulture)))
|
|
{
|
|
xml.WriteRaw(channelDataFragment);
|
|
}
|
|
|
|
xml.WriteEndElement(); // tv
|
|
xml.WriteEndDocument();
|
|
|
|
xml.Flush();
|
|
return Encoding.UTF8.GetString(ms.ToArray());
|
|
}
|
|
}
|