Exemplo n.º 1
0
        public void Merge(ProgramData data)
        {
            if (data != null)
            {
                // Preference not yet set?
                if (this._preference == null)
                {
                    this._preference = new DataPreference();
                }

                if (data._preference == null)
                {
                    data._preference = new DataPreference();
                }

                // Merge values with Preference
                if (data._title != string.Empty &&
                    (this._title == string.Empty || data._preference.Title > this._preference.Title))
                {
                    this._title            = data._title;
                    this._preference.Title = data._preference.Title;
                }

                if (data._subTitle != string.Empty &&
                    (this._subTitle == string.Empty || data._preference.Subtitle > this._preference.Subtitle))
                {
                    this._subTitle            = data._subTitle;
                    this._preference.Subtitle = data._preference.Subtitle;
                }

                if (data._description != string.Empty &&
                    (this._description == string.Empty || data._preference.Description > this._preference.Description))
                {
                    this._description            = data._description;
                    this._preference.Description = data._preference.Description;
                }

                if (data._genre != string.Empty &&
                    (this._genre == string.Empty || data._preference.Genre > this._preference.Genre))
                {
                    this._genre            = data._genre;
                    this._preference.Genre = data._preference.Genre;
                }

                if (data._repeat)
                {
                    this._repeat = data._repeat;
                }

                if (data._subtitles)
                {
                    this._subtitles = data._subtitles;
                }

                if (data._episode > 0)
                {
                    this._episode = data._episode;
                }

                if (data._season > 0)
                {
                    this._season = data._season;
                }

                // Merge values without pPreference
                if (data._channelId != string.Empty && this._channelId == string.Empty)
                {
                    this._channelId = data._channelId;
                }

                // Do not merge Date/Time ... causes
                //if (data._startTime != null && this._startTime == null)
                //  this._startTime = data._startTime;

                //if (data._endTime != null && this._endTime == null)
                //  this._endTime = data._endTime;
            }
        }
Exemplo n.º 2
0
    /// <summary>
    /// Gets the data from a linked page
    /// </summary>
    /// <param name="data">ref to ProgramData</param>
    /// <returns>true if data was correctly parsed otherwise false</returns>
    public bool GetLinkedData(ref ProgramData data)
    {
      // check if the Data has a sublink request set
      if (data.SublinkRequest != null)
      {
        // find template matches
        int count = _sublinkParser.ParseUrl(data.SublinkRequest);

        if (count > 0)
        {
          // get first match -> only the first match is supported for sublink templates
          ProgramData subdata = (ProgramData)_sublinkParser.GetData(0);
          if (subdata != null)
          {
            subdata.Preference = _sublinkPreference;

            data.Merge(subdata);

            return true;
          }
        }
      }
      return false;
    }
Exemplo n.º 3
0
    /// <summary>
    /// Gets the data.
    /// </summary>
    /// <param name="index">The index.</param>
    /// <returns></returns>
    public IParserData GetData(int index)
    {
      // Perform any search and remove requests
      // Searches can search over the whole data 
      // optionally removing text so it will not be parsed with the main data
      ProgramData searchData = null;
      if (_template.searchList != null && _template.searchList.Count > 0)
      {
        searchData = new ProgramData();
        for (int i = 0; i < _template.searchList.Count; i++)
        {
          WebSearchData search = _template.searchList[i];
          string result = _listingParser.SearchRegex(index, search.Match, search.Remove);
          if (result != null)
          {
            searchData.SetElement(search.Field, result);
          }
        }
      }

      // Get the parsed data at index
      ProgramData data = ((ProgramData)_listingParser.GetData(index));
      if (data != null)
      {
        // Set the data preference -> important for merging data (eg data from sublink page)
        data.Preference = new DataPreference(_listingPreference);

        // If search data exists merge.
        if (searchData != null)
        {
          data.Merge(searchData);
        }

        // If there is a sublink parser, check for a matching sublink
        // sublink is not parsed here, because that may not be required 
        // the URL for the sublink will be built and stored for future use see GetLinkedData()
        if (_sublinkParser != null)
        {
          HTTPRequest sublinkRequest = new HTTPRequest(_sublinkRequest);
// Minimum delay disabled because of a bug it wasn't being used anyway (always 0) and
// possibly not needed to start using now.
// Enabling has serious impact on grabspeed.
//          if (sublinkRequest.Delay < 500)
//          {
//            sublinkRequest.Delay = 500;
//          }
          if (_listingParser.GetHyperLink(index, _sublinkMatch, ref sublinkRequest))
          {
            data.SublinkRequest = sublinkRequest;
          }
        }
      }
      return data;
    }
Exemplo n.º 4
0
    public void Merge(ProgramData data)
    {
      if (data != null)
      {
        // Preference not yet set?
        if (this._preference == null)
        {
          this._preference = new DataPreference();
        }

        if (data._preference == null)
        {
          data._preference = new DataPreference();
        }

        // Merge values with Preference
        if (data._title != string.Empty &&
            (this._title == string.Empty || data._preference.Title > this._preference.Title))
        {
          this._title = data._title;
          this._preference.Title = data._preference.Title;
        }

        if (data._subTitle != string.Empty &&
            (this._subTitle == string.Empty || data._preference.Subtitle > this._preference.Subtitle))
        {
          this._subTitle = data._subTitle;
          this._preference.Subtitle = data._preference.Subtitle;
        }

        if (data._description != string.Empty &&
            (this._description == string.Empty || data._preference.Description > this._preference.Description))
        {
          this._description = data._description;
          this._preference.Description = data._preference.Description;
        }

        if (data._genre != string.Empty &&
            (this._genre == string.Empty || data._preference.Genre > this._preference.Genre))
        {
          this._genre = data._genre;
          this._preference.Genre = data._preference.Genre;
        }

        if (data._repeat)
        {
          this._repeat = data._repeat;
        }

        if (data._subtitles)
        {
          this._subtitles = data._subtitles;
        }

        if (data._episode > 0)
        {
          this._episode = data._episode;
        }

        if (data._season > 0)
        {
          this._season = data._season;
        }

        // Merge values without pPreference
        if (data._channelId != string.Empty && this._channelId == string.Empty)
        {
          this._channelId = data._channelId;
        }

        // Do not merge Date/Time ... causes
        //if (data._startTime != null && this._startTime == null)
        //  this._startTime = data._startTime;

        //if (data._endTime != null && this._endTime == null)
        //  this._endTime = data._endTime;
      }
    }
    /// <summary>
    /// Checks and adjusts the start and end times for a program.
    /// </summary>
    /// <param name="guideData">The guide data.</param>
    /// <returns>true if successfull otherwise false</returns>
    public bool CheckAdjustTime(ref ProgramData guideData)
    {
      WorldDateTime guideStartTime = guideData.StartTime;
      WorldDateTime guideEndTime = guideData.EndTime;
      _addDays = 1;

      // Check if the start time day value is set
      if (guideStartTime.Day == 0)
      {
        guideStartTime.Day = _startTime.Day; // Set program day to start day
      }
      else
      {
        // program has day value
        if (guideStartTime.Day != _startTime.Day && _expectedTime != Expect.Start)
        {
          // day value not the same as start time -> increase start time one day
          _grabDay++;
          _startTime = _startTime.AddDays(1);
          _nextDay = false;
          _lastTime = 0;
          _expectedTime = Expect.BeforeMidday;
        }
      }

      // Check and set month and year
      if (guideStartTime.Year == 0)
      {
        guideStartTime.Year = _startTime.Year;
      }
      if (guideStartTime.Month == 0)
      {
        guideStartTime.Month = _startTime.Month;
      }


      // State loop Start, BeforeMidday and AfterMidday
      switch (_expectedTime)
      {
          // Start of a new day - need to work out if the listings start in the morning or afternoon
        case Expect.Start:
          if (OnPerviousDay(guideStartTime.Hour))
          {
            return false; // Guide starts on pervious day ignore these listings.
          }

          if (_newDay)
          {
            _newDay = false;
            //if (guideStartTime.Hour < _startTime.Hour)
            //  return false;

            if (guideStartTime.Hour <= 12)
            {
              _expectedTime = Expect.BeforeMidday;
              goto case Expect.BeforeMidday;
            }

            _expectedTime = Expect.AfterMidday;
            goto case Expect.AfterMidday;
          }

          _expectedTime = Expect.BeforeMidday;
          goto case Expect.BeforeMidday; // Pass into BeforeMidday Code

          // Before Midday
        case Expect.BeforeMidday:
          if (_lastTime > guideStartTime.Hour)
          {
            // last time was before midday, new time is less -> site doesn't have 24 hours or AM/PM
            _expectedTime = Expect.AfterMidday;
          }
          else
          {
            if (guideStartTime.Hour <= 12)
            {
              break; // Time is before midday -> Do nothing
            }
          }

          // Pass into AfterMidday Code
          goto case Expect.AfterMidday;

          // After midday
        case Expect.AfterMidday:
          bool adjusted = false;
          if (guideStartTime.Hour < 12) // Site doesn't have correct time
          {
            guideStartTime.Hour += 12; // starts again at 1:00 without "pm"
            adjusted = true;
          }

          if (_lastTime > guideStartTime.Hour)
          {
            if (_nextDay)
            {
              _addDays++;
              _grabDay++;
              _startTime = _startTime.AddDays(1);
            }
            else
            {
              _nextDay = true;
            }

            if (adjusted)
            {
              guideStartTime.Hour -= 12;
            }

            if (guideStartTime.Hour < 12)
            {
              _expectedTime = Expect.BeforeMidday;
            }
          }

          break;

        default:
          break;
      }

      // store current hour as last hour
      _lastTime = guideStartTime.Hour;

      // Check if orogram has an end time
      if (guideEndTime != null)
      {
        // set Day, Month and Year is not set
        if (guideEndTime.Year == 0)
        {
          guideEndTime.Year = guideStartTime.Year;
        }
        if (guideEndTime.Month == 0)
        {
          guideEndTime.Month = guideStartTime.Month;
        }
        if (guideEndTime.Day == 0)
        {
          guideEndTime.Day = guideStartTime.Day;
        }

        // correct date if required
        if (_nextDay)
        {
          if (guideStartTime.Hour > guideEndTime.Hour)
          {
            // start before midnight end after
            guideEndTime = guideEndTime.AddDays(_addDays + 1);
          }
          else
          {
            guideEndTime = guideEndTime.AddDays(_addDays);
          }
        }
        else
        {
          if (guideStartTime.Hour > guideEndTime.Hour)
          {
            guideEndTime = guideEndTime.AddDays(_addDays);
          }
        }
      }

      // if next day -> correct start date
      if (_nextDay)
      {
        guideStartTime = guideStartTime.AddDays(_addDays);
      }

      //Log.Debug("WebEPG: Guide, Program Debug: [{0} {1}]", _GrabDay, _bNextDay);

      guideData.StartTime = guideStartTime;
      guideData.EndTime = guideEndTime;

      return true;
    }
Exemplo n.º 6
0
 void IEpgDataSink.WriteProgram(ProgramData programData, bool merged)
 {
   if (_currentChannels != null)
   {
     foreach (Channel chan in _currentChannels)
     {
       _channelPrograms.Add(programData.ToTvProgram(chan.IdChannel));
     }
   }
 }
Exemplo n.º 7
0
    void IEpgDataSink.WriteProgram(ProgramData programData, bool merged)
    {
      string channelId = programData.ChannelId;
      if (merged)
      {
        channelId = "[Merged]";
      }

      if (programData.StartTime != null &&
          programData.ChannelId != string.Empty &&
          programData.Title != string.Empty)
      {
        _writer.WriteStartElement("programme");
        TimeSpan t = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
        string tzOff = " " + t.Hours.ToString("+00;-00") + t.Minutes.ToString("00");
        _writer.WriteAttributeString("start", programData.StartTime.ToLocalTime().ToString("yyyyMMddHHmmss") + tzOff);
        if (programData.EndTime != null)
        {
          _writer.WriteAttributeString("stop", programData.EndTime.ToLocalTime().ToString("yyyyMMddHHmmss") + tzOff);
        }
        _writer.WriteAttributeString("channel", _currentChannelName + "-" + channelId);

        _writer.WriteStartElement("title");
        //_writer.WriteAttributeString("lang", "de");
        _writer.WriteString(programData.Title);
        _writer.WriteEndElement();

        if (programData.SubTitle != string.Empty && programData.SubTitle != "unknown")
        {
          _writer.WriteElementString("sub-title", programData.SubTitle);
        }

        if (programData.Description != string.Empty && programData.Description != "unknown")
        {
          _writer.WriteElementString("desc", programData.Description);
        }

        if (programData.Genre != string.Empty && programData.Genre != "-")
        {
          _writer.WriteElementString("category", programData.Genre);
        }

        string episodeNum = string.Empty;
        if (programData.Episode > 0)
        {
          episodeNum += programData.Episode;
        }

        if (programData.Season > 0)
        {
          episodeNum += "." + programData.Season;
        }

        if (episodeNum != string.Empty)
        {
          _writer.WriteElementString("episode-num", episodeNum);
        }

        //if (program.Repeat != string.Empty)
        //{
        //  _writer.WriteElementString("previously-shown", null);
        //}

        /*
          _writer.WriteStartElement("credits");
          _writer.WriteElementString("director", "xxx");
          _writer.WriteElementString("actor", "xxx");
          _writer.WriteElementString("actor", "xxx");
          _writer.WriteElementString("actor", "xxx");
          _writer.WriteEndElement();

          _writer.WriteElementString("date", "xxx");
          _writer.WriteElementString("country", "xxx");
          _writer.WriteElementString("episode-num", "xxx");

          _writer.WriteStartElement("video");
          _writer.WriteElementString("aspect", "xxx");
          _writer.WriteEndElement();

          _writer.WriteStartElement("star-rating");
          _writer.WriteElementString("value", "3/3");
          _writer.WriteEndElement();
          */

        _writer.WriteEndElement();
        _writer.Flush();
      }
    }
Exemplo n.º 8
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()*/;
    }