Exemplo n.º 1
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, false, search.Remove, search.Replace);
                    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.º 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 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;
    }