* upgrade sdk * fix warnings in ersatztv.ffmpeg * fix warnings in ersatztv.core * fix warnings in ersatztv.infrastructure * fix warnings in ersatztv.application * disable analysis for migrations projects * fix warnings in ersatztv.scanner * fix warnings in ersatztv * upgrade project framework * update github actions and dockerfiles
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());
|
|
}
|
|
}
|