示例#1
0
 private void ReadDataFromSocket(ChannelLocation channelLocation, IptvInfo info, int retries = 3)
 {
     try
     {
         using (var s = _socketFactory())
         {
             var start    = DateTime.Now;
             var previous = new byte[0];
             s.Open(channelLocation.Host, channelLocation.Port);
             var count = 0;
             while (NotAllDataFound(info) && count < MaxCycles)
             {
                 var data = s.Receive();
                 UpdateInfo(info, previous, data);
                 previous = data;
                 count++;
             }
             var end = DateTime.Now;
             _log.Debug($"Found IPTV Info after {(int) (end - start).TotalMilliseconds}ms");
         }
     }
     catch (SocketException)
     {
         if (retries == 0)
         {
             throw;
         }
         _log.Info($"Failed to read data from {channelLocation.Url}, retry ({retries}x allowed)");
         ReadDataFromSocket(channelLocation, info, retries - 1);
     }
 }
示例#2
0
 private bool NotAllDataFound(IptvInfo info)
 {
     if (OnlySearchForKeys && info.Number.HasValue)
     {
         return(false);
     }
     return(!info.Complete());
 }
示例#3
0
        private void UpdateInfo(IptvInfo info, byte[] previous, byte[] current)
        {
            var data = new byte[previous.Length + current.Length];

            previous.CopyTo(data, 0);
            current.CopyTo(data, previous.Length);

            if (FindChannelInfo(data, out string provider, out string name))
            {
                info.Provider = provider;
                info.Name     = name;
            }

            if (!info.Number.HasValue && FindChannelNumber(data, out int channel))
            {
                info.Number = channel;
            }
        }
示例#4
0
        private IptvInfo ReadData(ChannelLocation channelLocation, string channel)
        {
            var info = new IptvInfo {
                Url = channelLocation.Url
            };

            try
            {
                _log.Debug($"Try to read data from {channelLocation.Url} for {channel}");

                ReadDataFromSocket(channelLocation, info);

                _log.Info($"Found IPTV Info for {channel} at {channelLocation.Url}: {info.Provider} - {info.Name} (key: {info.Number})");

                return(info);
            }
            catch (Exception ex)
            {
                _log.Warn($"Failed to read data from {channelLocation.Url} for {channel}");
                _log.Debug($"Failed to read data from {channelLocation.Url}: {ex.Message}", ex);
                return(null);
            }
        }