예제 #1
0
        /// <summary>
        /// Gets the program given index number.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>the tv program data</returns>
        private ProgramData GetProgram(int index)
        {
            ProgramData guideData = (ProgramData)_parser.GetData(index);

            if (guideData == null ||
                guideData.StartTime == null || guideData.Title == string.Empty)
            {
                return(null);
            }

            // Set ChannelId
            guideData.ChannelId = _strID;

            if (_grabber.Actions != null && guideData.IsRemoved(_grabber.Actions))
            {
                _discarded++;
                return(null);
            }

            //Log.Debug("WebEPG: Guide, Program title: {0}", guideData.Title);
            //Log.Debug("WebEPG: Guide, Program start: {0}:{1} - {2}/{3}/{4}", guideData.StartTime.Hour, guideData.StartTime.Minute, guideData.StartTime.Day, guideData.StartTime.Month, guideData.StartTime.Year);
            //if (guideData.EndTime != null)
            //  Log.Debug("WebEPG: Guide, Program end  : {0}:{1} - {2}/{3}/{4}", guideData.EndTime.Hour, guideData.EndTime.Minute, guideData.EndTime.Day, guideData.EndTime.Month, guideData.EndTime.Year);
            //Log.Debug("WebEPG: Guide, Program desc.: {0}", guideData.Description);
            //Log.Debug("WebEPG: Guide, Program genre: {0}", guideData.Genre);

            // Adjust Time
            if (guideData.StartTime.Day == 0 || guideData.StartTime.Month == 0 || guideData.StartTime.Year == 0)
            {
                if (!_timeControl.CheckAdjustTime(ref guideData))
                {
                    _discarded++;
                    return(null);
                }
            }

            //Set TimeZone
            guideData.StartTime.TimeZone = _siteTimeZone;
            if (guideData.EndTime != null)
            {
                guideData.EndTime.TimeZone = _siteTimeZone;
                Log.Info("WebEPG: Guide, Program Info: {0} / {1} - {2}",
                         guideData.StartTime.ToLocalLongDateTime(), guideData.EndTime.ToLocalLongDateTime(), guideData.Title);
            }
            else
            {
                Log.Info("WebEPG: Guide, Program Info: {0} - {1}", guideData.StartTime.ToLocalLongDateTime(),
                         guideData.Title);
            }

            if (guideData.StartTime.ToLocalTime() < _grabStart.AddHours(-2))
            {
                Log.Info("WebEPG: Program starts in the past, ignoring it.");
                _discarded++;
                return(null);
            }

            // Check TV db if program exists
            if (_dblookup)
            {
                Program dbProg = dbProgram(guideData.Title, guideData.StartTime.ToLocalTime());
                if (dbProg != null)
                {
                    Log.Info("WebEPG: Program already in db");
                    Channel chan = Broker.TryRetrieveInstance <Channel>(new Key(true, "ExternalId", _strID));
                    if (chan != null)
                    {
                        ProgramData dbProgramData = new ProgramData();
                        dbProgramData.InitFromProgram(dbProg);
                        dbProgramData.ChannelId = _strID;
                        return(dbProgramData);
                    }
                }
            }

            // SubLink
            if (guideData.HasSublink())
            {
                if (_parser is WebParser)
                {
                    // added: delay info
                    Log.Info("WebEPG: SubLink Request {0} - Delay: {1}ms", guideData.SublinkRequest.ToString(),
                             guideData.SublinkRequest.Delay);

                    WebParser webParser = (WebParser)_parser;

                    if (!webParser.GetLinkedData(ref guideData))
                    {
                        Log.Info("WebEPG: Getting sublinked data failed");
                    }
                    else
                    {
                        Log.Debug("WebEPG: Getting sublinked data sucessful");
                    }
                }
            }

            if (_grabber.Actions != null)
            {
                guideData.Replace(_grabber.Actions);
            }

            return(guideData /*.ToTvProgram()*/);
        }