Add Windows desktop version
This commit is contained in:
83
windows/StreamPlayer.Desktop/Services/SectionBuilder.cs
Normal file
83
windows/StreamPlayer.Desktop/Services/SectionBuilder.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using StreamPlayer.Desktop.Models;
|
||||
|
||||
namespace StreamPlayer.Desktop.Services;
|
||||
|
||||
public static class SectionBuilder
|
||||
{
|
||||
public static IReadOnlyList<ChannelSection> BuildSections()
|
||||
{
|
||||
var sections = new List<ChannelSection>
|
||||
{
|
||||
new("Eventos en vivo", SectionType.Events, Array.Empty<StreamChannel>())
|
||||
};
|
||||
|
||||
var grouped = ChannelRepository.GetChannels()
|
||||
.GroupBy(channel => DeriveGroupName(channel.Name))
|
||||
.ToDictionary(group => group.Key, group => (IReadOnlyList<StreamChannel>)group.ToList());
|
||||
|
||||
if (grouped.TryGetValue("ESPN", out var espnGroup))
|
||||
{
|
||||
sections.Add(new ChannelSection("ESPN", SectionType.Channels, espnGroup));
|
||||
grouped.Remove("ESPN");
|
||||
}
|
||||
|
||||
foreach (var key in grouped.Keys.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
var channels = grouped[key];
|
||||
if (channels.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
sections.Add(new ChannelSection(key, SectionType.Channels, channels));
|
||||
}
|
||||
|
||||
sections.Add(new ChannelSection("Todos los canales", SectionType.Channels, ChannelRepository.GetChannels()));
|
||||
return sections;
|
||||
}
|
||||
|
||||
private static string DeriveGroupName(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
return "General";
|
||||
}
|
||||
string upper = name.ToUpperInvariant();
|
||||
if (upper.StartsWith("ESPN", StringComparison.Ordinal))
|
||||
{
|
||||
return "ESPN";
|
||||
}
|
||||
if (upper.Contains("FOX SPORTS", StringComparison.Ordinal))
|
||||
{
|
||||
return "Fox Sports";
|
||||
}
|
||||
if (upper.Contains("FOX", StringComparison.Ordinal))
|
||||
{
|
||||
return "Fox";
|
||||
}
|
||||
if (upper.Contains("TNT", StringComparison.Ordinal))
|
||||
{
|
||||
return "TNT";
|
||||
}
|
||||
if (upper.Contains("DAZN", StringComparison.Ordinal))
|
||||
{
|
||||
return "DAZN";
|
||||
}
|
||||
if (upper.Contains("TUDN", StringComparison.Ordinal))
|
||||
{
|
||||
return "TUDN";
|
||||
}
|
||||
if (upper.Contains("TYC", StringComparison.Ordinal))
|
||||
{
|
||||
return "TyC";
|
||||
}
|
||||
if (upper.Contains("GOL", StringComparison.Ordinal))
|
||||
{
|
||||
return "Gol";
|
||||
}
|
||||
int spaceIndex = upper.IndexOf(' ');
|
||||
return spaceIndex > 0 ? upper[..spaceIndex] : upper;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user