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); } }
public IptvInfo ReadInfo(ChannelLocation info, string channel) { if (string.IsNullOrWhiteSpace(info.Host)) { _log.Warn("No valid host given"); return(null); } var data = ReadData(info, channel); return(data); }
public void FindNpo2() { var location = new ChannelLocation { Host = "224.0.251.125", Port = 8250, Protocol = "rtp" }; var info = _iptvChannel.ReadInfo(location, "Npo2"); info.Number.Should().Be(662); info.Name.Should().Be("NPO 2 HD glas"); }
public void FindRtl5() { var location = new ChannelLocation { Host = "224.0.251.135", Port = 8270, Protocol = "rtp" }; var info = _iptvChannel.ReadInfo(location, "Rtl5"); info.Number.Should().Be(665); info.Name.Should().Be("RTL5 HD glas"); }
private ChannelLocation ExtractLocation(IList <string> messageBlock) { /* * m=video 8248 RTP/AVPF 96 * i=Original Source Stream * c=IN IP4 224.0.251.124/255 * b=AS:12750 */ var portAndProtocol = messageBlock.First(m => m.StartsWith("m=video")).Substring(8).Split(' '); var address = messageBlock.First(m => m.StartsWith("c=IN IP4")).Substring(9); var bitrate = messageBlock.First(m => m.StartsWith("b=AS:")).Substring(5); //Generate URL var port = portAndProtocol[0]; //Extract RTP from RTP/AVPF if (portAndProtocol[1].Contains("/")) { portAndProtocol[1] = portAndProtocol[1].Substring(0, portAndProtocol[1].IndexOf('/')); } var protocol = portAndProtocol[1]; //Extract /255 from 224.0.251.124/255 if (address.Contains("/")) { address = address.Substring(0, address.IndexOf('/')); } var location = new ChannelLocation { Protocol = protocol.ToLower(), Host = address, Port = int.Parse(port), Bitrate = int.Parse(bitrate) }; return(location); }
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); } }