| | 1 | | #pragma warning disable CS1591 |
| | 2 | |
|
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using MediaBrowser.Controller.LiveTv; |
| | 6 | |
|
| | 7 | | namespace Jellyfin.LiveTv.Listings |
| | 8 | | { |
| | 9 | | internal class EpgChannelData |
| | 10 | | { |
| | 11 | | private readonly Dictionary<string, ChannelInfo> _channelsById; |
| | 12 | |
|
| | 13 | | private readonly Dictionary<string, ChannelInfo> _channelsByNumber; |
| | 14 | |
|
| | 15 | | private readonly Dictionary<string, ChannelInfo> _channelsByName; |
| | 16 | |
|
| | 17 | | public EpgChannelData(IEnumerable<ChannelInfo> channels) |
| | 18 | | { |
| 0 | 19 | | _channelsById = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase); |
| 0 | 20 | | _channelsByNumber = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase); |
| 0 | 21 | | _channelsByName = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase); |
| | 22 | |
|
| 0 | 23 | | foreach (var channel in channels) |
| | 24 | | { |
| 0 | 25 | | _channelsById[channel.Id] = channel; |
| | 26 | |
|
| 0 | 27 | | if (!string.IsNullOrEmpty(channel.Number)) |
| | 28 | | { |
| 0 | 29 | | _channelsByNumber[channel.Number] = channel; |
| | 30 | | } |
| | 31 | |
|
| 0 | 32 | | var normalizedName = NormalizeName(channel.Name ?? string.Empty); |
| 0 | 33 | | if (!string.IsNullOrWhiteSpace(normalizedName)) |
| | 34 | | { |
| 0 | 35 | | _channelsByName[normalizedName] = channel; |
| | 36 | | } |
| | 37 | | } |
| 0 | 38 | | } |
| | 39 | |
|
| | 40 | | public ChannelInfo? GetChannelById(string id) |
| 0 | 41 | | => _channelsById.GetValueOrDefault(id); |
| | 42 | |
|
| | 43 | | public ChannelInfo? GetChannelByNumber(string number) |
| 0 | 44 | | => _channelsByNumber.GetValueOrDefault(number); |
| | 45 | |
|
| | 46 | | public ChannelInfo? GetChannelByName(string name) |
| 0 | 47 | | => _channelsByName.GetValueOrDefault(name); |
| | 48 | |
|
| | 49 | | public static string NormalizeName(string value) |
| | 50 | | { |
| 0 | 51 | | return value.Replace(" ", string.Empty, StringComparison.Ordinal).Replace("-", string.Empty, StringCompariso |
| | 52 | | } |
| | 53 | | } |
| | 54 | | } |