EpgChannelData.cs 2.1 KB

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