* Add instance id support * actually use env variable for instance ID * Default to ersatztv.org for instance id * simplify * fix ordering * update changelog --------- Co-authored-by: Jason Dove <1695733+jasongdove@users.noreply.github.com>
26 lines
776 B
C#
26 lines
776 B
C#
using System.Globalization;
|
|
|
|
namespace ErsatzTV.Core.Iptv;
|
|
|
|
public static class ChannelIdentifier
|
|
{
|
|
public static string LegacyFromNumber(string channelNumber) => $"{channelNumber}.etv";
|
|
|
|
public static string FromNumber(string channelNumber)
|
|
{
|
|
// get rid of any decimal (only two are allowed)
|
|
var number = (int)(decimal.Parse(channelNumber, CultureInfo.InvariantCulture) * 100);
|
|
var id = 0;
|
|
while (number != 0)
|
|
{
|
|
id += number % 10 + 48;
|
|
number /= 10;
|
|
}
|
|
|
|
string instanceId = SystemEnvironment.InstanceId;
|
|
return !string.IsNullOrWhiteSpace(instanceId)
|
|
? $"C{channelNumber}.{id}.{instanceId}.ersatztv.org"
|
|
: $"C{channelNumber}.{id}.ersatztv.org";
|
|
}
|
|
}
|