aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/LiveTv/EmbyTV/EpgChannelData.cs
blob: 463d0ed0a3bda5b3573a1a449e07da8c987a0ee2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma warning disable CS1591

using System;
using System.Collections.Generic;
using MediaBrowser.Controller.LiveTv;

namespace Emby.Server.Implementations.LiveTv.EmbyTV
{

    internal class EpgChannelData
    {
        public EpgChannelData(IEnumerable<ChannelInfo> channels)
        {
            ChannelsById = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase);
            ChannelsByNumber = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase);
            ChannelsByName = new Dictionary<string, ChannelInfo>(StringComparer.OrdinalIgnoreCase);

            foreach (var channel in channels)
            {
                ChannelsById[channel.Id] = channel;

                if (!string.IsNullOrEmpty(channel.Number))
                {
                    ChannelsByNumber[channel.Number] = channel;
                }

                var normalizedName = NormalizeName(channel.Name ?? string.Empty);
                if (!string.IsNullOrWhiteSpace(normalizedName))
                {
                    ChannelsByName[normalizedName] = channel;
                }
            }
        }

        private Dictionary<string, ChannelInfo> ChannelsById { get; set; }

        private Dictionary<string, ChannelInfo> ChannelsByNumber { get; set; }

        private Dictionary<string, ChannelInfo> ChannelsByName { get; set; }

        public ChannelInfo GetChannelById(string id)
        {
            ChannelsById.TryGetValue(id, out var result);

            return result;
        }

        public ChannelInfo GetChannelByNumber(string number)
        {
            ChannelsByNumber.TryGetValue(number, out var result);

            return result;
        }

        public ChannelInfo GetChannelByName(string name)
        {
            ChannelsByName.TryGetValue(name, out var result);

            return result;
        }

        public static string NormalizeName(string value)
        {
            return value.Replace(" ", string.Empty, StringComparison.Ordinal).Replace("-", string.Empty, StringComparison.Ordinal);
        }
    }
}