コード例 #1
0
        private void FillProgramWithDataFromDetailLink(string Url, ProgramTvDto programTv, bool isNextDay)
        {
            string          detailHtml      = HtmlImporter.GetHtml(Url);
            Regex           regexNames      = new Regex(Settings.Default.NameRegex);
            MatchCollection matchNames      = regexNames.Matches(detailHtml);
            Regex           regexTypes      = new Regex(Settings.Default.TypeRegex);
            MatchCollection matchTypes      = regexTypes.Matches(detailHtml);
            Regex           regexDuration   = new Regex(Settings.Default.DurationRegex);
            MatchCollection matchesDuration = regexDuration.Matches(detailHtml);

            programTv.name = matchNames[0].Result("$1");
            if (matchTypes.Count > 0)
            {
                programTv.type_name = matchTypes[0].Result("$1");
            }
            else
            {
                programTv.type_name = "Brak";
            }
        }
コード例 #2
0
        private List <ProgramTvDto> GetProgramFromOneDay(string url, DateTime currentDate)
        {
            List <ProgramTvDto> programList = new List <ProgramTvDto>();
            string          html = HtmlImporter.GetHtml(url);
            string          detailLink, detailURL;
            ProgramTvDto    programTv = new ProgramTvDto();
            Regex           regexDetailLink = new Regex(Settings.Default.DetailLink);
            MatchCollection matchDetailsLinks = regexDetailLink.Matches(html);
            Regex           regexTimeStarts = new Regex(Settings.Default.TimeStartRegex);
            MatchCollection matchTimeStarts = regexTimeStarts.Matches(html);
            TimeSpan        programTime = new TimeSpan(0, 0, 0, 0), prevProgramTime = new TimeSpan(0, 0, 0, 0);
            bool            isNextDay = false, isDayAdded = false;

            /*iterujemy od 1 bo na 1 pozycji zbędny element*/
            for (int i = 1; i < matchDetailsLinks.Count; i++)
            {
                programTv = new ProgramTvDto();
                //godzina staru
                prevProgramTime = programTime;
                programTime     = TimeSpan.Parse(matchTimeStarts[i - 1].Result("$1"));
                if (isNextDay && !isDayAdded && currentDate.Add(programTime.Subtract(prevProgramTime)).Hour < 12)
                {
                    programTv.start_date = currentDate = currentDate.AddDays(1);
                    isDayAdded           = true;
                }
                programTv.start_date = currentDate = currentDate.Add(programTime.Subtract(prevProgramTime));

                if (currentDate.Hour > 12)
                {
                    isNextDay = true;
                }
                programList.Add(programTv);
                //detail link
                detailLink = matchDetailsLinks[i].Result("$2");
                detailURL  = string.Concat(Settings.Default.BaseUrl, detailLink);
                FillProgramWithDataFromDetailLink(detailURL, programTv, isNextDay);
                programTv.id_chan = ChannelId;
            }
            return(programList);
        }