EpgChannelData.cs 1.9 KB

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