/// <summary> /// Grabs the epg for a card. /// </summary> /// <param name="epgCard">The epg card.</param> private void GrabEpgOnCard(EpgCard epgCard) { CardType type = _tvController.Type(epgCard.Card.IdCard); //skip analog and webstream cards if (type == CardType.Analog || type == CardType.RadioWebStream) { return; } while (TransponderList.Instance.GetNextTransponder() != null) { //skip transponders which are in use if (TransponderList.Instance.CurrentTransponder.InUse) { continue; } //check if card type is the same as the channel type of the transponder if (type == CardType.Atsc && TransponderList.Instance.CurrentTransponder.TuningDetail.ChannelType != 1) { continue; } if (type == CardType.DvbC && TransponderList.Instance.CurrentTransponder.TuningDetail.ChannelType != 2) { continue; } if (type == CardType.DvbS && TransponderList.Instance.CurrentTransponder.TuningDetail.ChannelType != 3) { continue; } if (type == CardType.DvbT && TransponderList.Instance.CurrentTransponder.TuningDetail.ChannelType != 4) { continue; } if (type == CardType.DvbIP && TransponderList.Instance.CurrentTransponder.TuningDetail.ChannelType != 7) { continue; } //find next channel to grab while (TransponderList.Instance.CurrentTransponder.GetNextChannel() != null) { //get the channel Channel ch = TransponderList.Instance.CurrentTransponder.CurrentChannel; //check if its time to grab the epg for this channel TimeSpan ts = DateTime.Now - TransponderList.Instance.CurrentTransponder.CurrentChannel.LastGrabTime; if (ts.TotalMinutes < _epgReGrabAfter) { //Log.Epg("Skip card:#{0} transponder #{1}/{2} channel: {3} - Less than regrab time", // epgCard.Card.IdCard, TransponderList.Instance.CurrentIndex + 1, TransponderList.Instance.Count, ch.DisplayName); continue; // less then 2 hrs ago } if (epgCard.Card.canTuneTvChannel(ch.IdChannel)) { Log.Epg("Grab for card:#{0} transponder #{1}/{2} channel: {3}", epgCard.Card.IdCard, TransponderList.Instance.CurrentIndex + 1, TransponderList.Instance.Count, ch.DisplayName); //start grabbing epgCard.GrabEpg(); return; } } } }
/// <summary> /// Starts the epg grabber with a specified timer interval /// </summary> public void Start(double timerInterval) { TvBusinessLayer layer = new TvBusinessLayer(); if (layer.GetSetting("idleEPGGrabberEnabled", "yes").Value != "yes") { Log.Epg("EPG: grabber disabled"); return; } if (_isRunning) { return; } Setting s = layer.GetSetting("timeoutEPGRefresh", "240"); if (Int32.TryParse(s.Value, out _epgReGrabAfter) == false) { _epgReGrabAfter = 240; } TransponderList.Instance.RefreshTransponders(); if (TransponderList.Instance.Count == 0) { return; } Log.Epg("EPG: EpgGrabber initialized for {0} transponders, timerInterval {1}s", TransponderList.Instance.Count, timerInterval / 1000); _isRunning = true; IList <Card> cards = Card.ListAll(); if (_epgCards != null) { foreach (EpgCard epgCard in _epgCards) { epgCard.Dispose(); } } _epgCards = new List <EpgCard>(); foreach (Card card in cards) { if (!card.Enabled || !card.GrabEPG) { continue; } try { RemoteControl.HostName = card.ReferencedServer().HostName; if (!_tvController.CardPresent(card.IdCard)) { continue; } } catch (Exception e) { Log.Error("card: unable to start job for card {0} at:{0}", e.Message, card.Name, card.ReferencedServer().HostName); } EpgCard epgCard = new EpgCard(_tvController, card); _epgCards.Add(epgCard); } _epgCards.Sort(new EpgCardPriorityComparer()); _epgTimer.Interval = timerInterval; _epgTimer.Enabled = true; }