Esempio n. 1
0
 public void SetData(PrgInfo prg)
 {
     txtDescription.Text    = prg.Description;
     lbCountry.Text         = prg.Country;
     lbTitleEPG.Text        = prg.Title;
     lbStars.Text           = prg.Stars;
     lbStartTime.Text       = prg.StartTime.ToShortTimeString();
     lbEndTime.Text         = prg.StopTime.ToShortTimeString();
     logoPRG.LoadCompleted -= logoEPGLoaded;
     lbRatings.Text         = prg.Rating.Replace("Ratings:", "");
     foreach (string cat in prg.Categories)
     {
         lbCategories.Text += cat + ",";
     }
     if (lbCategories.Text.EndsWith(","))
     {
         lbCategories.Text = lbCategories.Text.Substring(0, lbCategories.Text.Length - 1);
     }
     logoPRG.Image = Image.FromFile("./resources/images/nochannel.png");
     if (!string.IsNullOrEmpty(prg.Logo))
     {
         logoPRG.LoadAsync(prg.Logo);
         logoPRG.LoadCompleted += logoEPGLoaded;
     }
     VisibleChannel(true);
 }
        public PrgInfo GetCurrentProgramm(ChannelInfo channel)
        {
            PrgInfo        result        = null;
            DateTime       nowDate       = DateTime.Now;
            List <PrgInfo> listProgramms = null;

            try
            {
                listProgramms = DB[channel.TVGId][nowDate.Year][nowDate.Month][nowDate.Day];
            } catch (Exception ex)
            {
                listProgramms = new List <PrgInfo>();
            }

            foreach (PrgInfo prg in listProgramms)
            {
                if (prg.StartTime <= nowDate)
                {
                    if (prg.StopTime >= nowDate)
                    {
                        result = prg;
                        break;
                    }
                }
            }
            return(result);
        }
 private void DefaultEpgLabels()
 {
     lbTitleEPG.Text    = "-";
     lbDescription.Text = "-";
     lbEndTime.Text     = "-";
     lbStars.Text       = "-";
     lbStartTime.Text   = "-";
     lbYear.Text        = "-";
     currentPrg         = null;
 }
        private void FillChannelInfo(PrgInfo prg)
        {
            lbTitleEPG.Text = prg.Title;
            string description = prg.Description;

            if (description.Length > 200 || description.Split('\n').Length > 3)
            {
                description = description.Substring(0, 190) + " ...";
            }
            lbDescription.Text = description;
            lbStars.Text       = prg.Stars;
            lbStartTime.Text   = prg.StartTime.ToShortTimeString();
            lbEndTime.Text     = prg.StopTime.ToShortTimeString();

            currentPrg = prg;
        }
        private void SetEPG(ChannelInfo channel)
        {
            if (channel.ChannelType == ChType.CHANNEL)
            {
                VisibleEPGLabes(true);

                EPG_DB epg = EPG_DB.Get();
                if (epg.Loaded == EPG_STATUS.Loaded)
                {
                    PrgInfo prg = epg.GetCurrentProgramm(channel);
                    if (prg != null)
                    {
                        FillChannelInfo(prg);
                    }
                    else
                    {
                        DefaultEpgLabels();
                    }
                }
                else
                {
                    DefaultEpgLabels();
                }
            }
            else
            {
                DefaultEpgLabels();
                VisibleEPGLabes(false);
                dynamic result = Utils.GetFilmInfo(channel, "es");
                fillFilmResults = result["results"];
                JObject filmMatch = null;
                if (result["results"].Count > 0)
                {
                    filmMatch = result["results"][0];
                }
                filmInfo = filmMatch;
                DrawMovieInfo();
            }
        }
        private void Parse()
        {
            EPGEventArgs epgEvent = new EPGEventArgs();

            epgEvent.Error = false;
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\amiiptvepg.xml");
                XmlNodeList list_programs = doc.SelectNodes("/tv/programme");
                foreach (XmlNode prg in list_programs)
                {
                    PrgInfo prginfo      = new PrgInfo();
                    string  formatString = "yyyyMMddHHmmss";
                    prginfo.StartTime = DateTime.ParseExact(prg.Attributes["start"].Value.Split(' ')[0], formatString, CultureInfo.InvariantCulture);
                    prginfo.StopTime  = DateTime.ParseExact(prg.Attributes["stop"].Value.Split(' ')[0], formatString, CultureInfo.InvariantCulture);
                    string channelID = prg.Attributes["channel"].Value;

                    prginfo.Title = prg.SelectSingleNode("title").InnerText;
                    try
                    {
                        prginfo.Description = prg.SelectSingleNode("desc").InnerText;
                    }
                    catch (Exception ex)
                    {
                        prginfo.Description = "No Description";
                    }

                    XmlNodeList categories = prg.SelectNodes("category");
                    foreach (XmlNode cat in categories)
                    {
                        if (prginfo.Categories == null)
                        {
                            prginfo.Categories = new List <string>();
                        }
                        prginfo.Categories.Add(cat.InnerText);
                    }
                    try
                    {
                        prginfo.Stars = prg.SelectSingleNode("star-rating").InnerText;
                    }
                    catch (Exception ex)
                    {
                        prginfo.Stars = "-";
                    }

                    try
                    {
                        prginfo.Logo = prg.SelectSingleNode("icon").Attributes["src"].InnerText;
                    }
                    catch (Exception ex)
                    {
                        prginfo.Logo = null;
                    }
                    try
                    {
                        prginfo.Country = prg.SelectSingleNode("country").InnerText;
                    }
                    catch (Exception ex)
                    {
                        prginfo.Country = "-";
                    }
                    try
                    {
                        prginfo.Rating = prg.SelectSingleNode("review").InnerText;
                    }
                    catch (Exception ex)
                    {
                        prginfo.Rating = "-";
                    }

                    if (!DB.ContainsKey(channelID))
                    {
                        DB[channelID] = new Dictionary <int, Dictionary <int, Dictionary <int, List <PrgInfo> > > >();
                    }
                    if (!DB[channelID].ContainsKey(prginfo.StartTime.Year))
                    {
                        DB[channelID][prginfo.StartTime.Year] = new Dictionary <int, Dictionary <int, List <PrgInfo> > >();
                    }
                    if (!DB[channelID][prginfo.StartTime.Year].ContainsKey(prginfo.StartTime.Month))
                    {
                        DB[channelID][prginfo.StartTime.Year][prginfo.StartTime.Month] = new Dictionary <int, List <PrgInfo> >();
                    }
                    if (!DB[channelID][prginfo.StartTime.Year][prginfo.StartTime.Month].ContainsKey(prginfo.StartTime.Day))
                    {
                        DB[channelID][prginfo.StartTime.Year][prginfo.StartTime.Month][prginfo.StartTime.Day] = new List <PrgInfo>();
                    }
                    DB[channelID][prginfo.StartTime.Year][prginfo.StartTime.Month][prginfo.StartTime.Day].Add(prginfo);
                }
                using (StreamWriter file = File.CreateText(System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\amiiptvepgCache.json"))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Serialize(file, DB);
                }
                epgEventFinish(this, epgEvent);
                Loaded = true;
            }catch (Exception ex)
            {
                File.Delete(System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\amiiptvepg.xml");
                epgEvent.Error = true;
                epgEventFinish(this, epgEvent);
                Loaded = false;
            }
        }