Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebParser"/> class.
        /// </summary>
        /// <param name="webTemplate">The web template.</param>
        public WebParser(WebParserTemplate webTemplate)
        {
            // Store the template
            _template = webTemplate;

            // Get default template -> currently only a default is supported
            // In the future template per channel ID can be added.
            HtmlParserTemplate listingTemplate = _template.GetTemplate("default");

            _listingPreference = _template.GetPreference("default");

            // Create dictionary for month strings
            Dictionary <string, int> monthsDict = null;

            if (_template.months != null)
            {
                // template contains months list -> load into dictionary
                monthsDict = new Dictionary <string, int>();
                for (int i = 0; i < _template.months.Length; i++)
                {
                    monthsDict.Add(_template.months[i], i + 1);
                    ;
                }
            }


            // create new Html Parser using default template
            _listingParser = new HtmlParser(listingTemplate, typeof(ProgramData), monthsDict);

            // setup sublink parser if template and config exists
            _sublinkParser = null;
            if (_template.sublinks != null && _template.sublinks.Count > 0)
            {
                // Load first sublink template -> only one supported now
                // future support for multiple sublinks possible
                SublinkInfo        sublink         = _template.sublinks[0];
                HtmlParserTemplate sublinkTemplate = _template.GetTemplate(sublink.template);
                _sublinkPreference = _template.GetPreference(sublinkTemplate.Name);

                if (sublinkTemplate != null)
                {
                    // create sublink parser using template
                    _sublinkParser  = new HtmlParser(sublinkTemplate, typeof(ProgramData));
                    _sublinkMatch   = sublink.search;
                    _sublinkRequest = sublink.url;
                }
            }
        }
Example #2
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;
            }
        }