EpgChannelData.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. public EpgChannelData(IEnumerable<ChannelInfo> channels)
  10. {
  11. ChannelsById = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase);
  12. ChannelsByNumber = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase);
  13. ChannelsByName = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase);
  14. foreach (var channel in channels)
  15. {
  16. ChannelsById[channel.Id] = channel;
  17. if (!string.IsNullOrEmpty(channel.Number))
  18. {
  19. ChannelsByNumber[channel.Number] = channel;
  20. }
  21. var normalizedName = NormalizeName(channel.Name ?? string.Empty);
  22. if (!string.IsNullOrWhiteSpace(normalizedName))
  23. {
  24. ChannelsByName[normalizedName] = channel;
  25. }
  26. }
  27. }
  28. private Dictionary<string, ChannelInfo> ChannelsById { get; set; }
  29. private Dictionary<string, ChannelInfo> ChannelsByNumber { get; set; }
  30. private Dictionary<string, ChannelInfo> ChannelsByName { get; set; }
  31. public ChannelInfo GetChannelById(string id)
  32. {
  33. ChannelsById.TryGetValue(id, out var result);
  34. return result;
  35. }
  36. public ChannelInfo GetChannelByNumber(string number)
  37. {
  38. ChannelsByNumber.TryGetValue(number, out var result);
  39. return result;
  40. }
  41. public ChannelInfo GetChannelByName(string name)
  42. {
  43. ChannelsByName.TryGetValue(name, out var result);
  44. return result;
  45. }
  46. public static string NormalizeName(string value)
  47. {
  48. return value.Replace(" ", string.Empty, StringComparison.Ordinal).Replace("-", string.Empty, StringComparison.Ordinal);
  49. }
  50. }
  51. }