private void ParseDoc()
        {
            XmlDocument xmlDoc;
             XmlNode rootNode;

             try
             {
                 //remove <!DOCTYPE tv SYSTEM "xmltv.dtd"> string, 'cause xmldocument doesn't support it
                 m_Content = m_Content.Remove(44, 32);

                 //load content into xmldoc
                 xmlDoc = new XmlDocument();
                 xmlDoc.LoadXml(m_Content);

                 foreach (XmlNode commNode in xmlDoc.SelectNodes("//comment()"))
                 {
                     commNode.ParentNode.RemoveChild(commNode);
                 }

                 rootNode = xmlDoc.DocumentElement;

                 if ((rootNode == null) ||!rootNode.Name.Equals("tv"))
                 {
                     throw new Exception("TV tag not found. XML file not well formed.");
                 }

                 if (!rootNode.FirstChild.Name.Equals("programme"))
                 {
                    throw new Exception("programme tag not found. XML file not well formed.");
                 }

                 //enough of the checking, let's parse the file already!

                 //create an holder collection for our programmes
                 ProgrammeCollection progColl = new ProgrammeCollection();

                 foreach (XmlNode programmeNodes in rootNode.SelectNodes("programme"))
                 {
                     //define defaults
                     string _title = "unknown title";
                     string _lang = "unknown lang";
                     string _descr = "no description";
                     string _date ="unknown date";
                     string _type ="unknown type";
                     string _channel = "unknown channel";

                     XmlNode nodTitle = programmeNodes.SelectSingleNode("title");
                     XmlNode nodDesc = programmeNodes.SelectSingleNode("desc");
                     XmlNode nodDate = programmeNodes.SelectSingleNode("date");

                     XmlNodeList nodCategories = programmeNodes.SelectNodes("category");
                     if (nodCategories.Count > 0)
                     {
                         foreach (XmlNode nodCategory in nodCategories)
                         {
                             _type += nodCategory.InnerText + ",";
                         }

                     }
                     if (nodTitle != null)
                     {
                         _title = nodTitle.InnerText;
                     }

                     if (nodDesc != null)
                     {
                         _descr = nodDesc.InnerText;
                     }

                     if (nodDate != null)
                     {
                         _date = nodDate.InnerText;
                     }

                     //get parameters
                     _channel = programmeNodes.Attributes.GetNamedItem("channel").Value;
                     DateTime _startTime = ConvertTime(programmeNodes.Attributes.GetNamedItem("start").Value);
                     DateTime _stopTime = ConvertTime(programmeNodes.Attributes.GetNamedItem("stop").Value);
                     _lang = programmeNodes.SelectSingleNode("title").Attributes.GetNamedItem("lang").Value;

                     //create an programme object with above parameters
                     Programme progXML = new Programme(_channel,
                                                        _date,
                                                        _type,
                                                        _title,
                                                        _lang,
                                                        _startTime,
                                                        _stopTime,
                                                        _descr);

                     progColl.Add(progXML);

                 }

                 parsedProgs = progColl;
             }
             catch (XmlException ex)
             {

                 throw new Exception("Error parsing XML file. Msg: " + ex.Message);
             }
        }
Example #2
0
        public ProgrammeCollection GetCurrentShows()
        {
            ProgrammeCollection _onNow = new ProgrammeCollection();
            DateTime _now = DateTime.Now;

            foreach (Programme _prog in this)
            {
                //test, remove when working
                int test;
                test = _prog.StartTime.CompareTo(_now);
                string test2 = test.ToString();

                int _currentPos = this.InnerList.IndexOf(_prog);

                if (_prog.StartTime < _now && this[_currentPos + 1].StartTime > _now)
                {
                    _onNow.Add(_prog); //add show on right now
                }
                else
                {
                    //do nada
                }
            }

            return _onNow;
        }
Example #3
0
        private ProgrammeCollection GetProgrammes()
        {
            const String nl = "\r\n";

            XMLTVParser parser;
            String strXMLFileContents = "";
            String tvdbURI = prefs.XMLTVSourceURI;
            ProgrammeCollection parsedObj = new ProgrammeCollection();

            string[] kanaler = prefs.ChannelList;

            try
            {
                Cursor.Current = Cursors.WaitCursor;

                for (int i = 0; i < kanaler.Length ;i++ )
                {
                    string uri = tvdbURI + kanaler[i].ToString();
                    string strFileName;

                    Leecher _leech = new Leecher(uri);
                    //LOG: String.Format("Starting download of file: {0}", uri) + nl+ nl ;

                    _leech.GetListings(false);

                    strFileName = _leech.PathToFile;

                    if (strFileName.EndsWith(".xml.gz"))
                    {
                        //LOG: this
                        // decompress the gziped file to string, and send content to xmltv parser
                        GzipDecompressor gzPack = new GzipDecompressor();
                        strXMLFileContents = gzPack.Decompress(strFileName);

                    }
                    else
                    {
                        if (strFileName.EndsWith(".xml"))
                        {
                            //LOG: this
                            //no need for decompression, read filestream into string at once...
                            StreamReader st = new StreamReader(strFileName);
                            strXMLFileContents = st.ReadToEnd();
                        }
                        else
                            throw new Exception("Unknow filetype. Must be XML or XML.GZ");

                    }

                    //LOG: this "File downloaded: " + Path.GetFileName(strFileName) + nl + nl;

                    parser = new XMLTVParser(strXMLFileContents);
                    foreach (Programme oProg in parser.ParsedProgrammes)
                    {
                        parsedObj.Add(oProg);
                    }

                }

            }
            catch (Exception downloadExcepetion)
            {
                MessageBox.Show(downloadExcepetion.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
            Cursor.Current = Cursors.Default;

            return parsedObj;
        }
Example #4
0
        public ProgrammeCollection GetCurrentShows()
        {
            ProgrammeCollection _onNow = new ProgrammeCollection();
            DateTime _now = DateTime.Now;

            foreach (Programme _prog in this)
            {
                int _currentPos = this.InnerList.IndexOf(_prog);

                if (_prog.StartTime < _now && this[_currentPos + 1].StartTime > _now)
                {
                    _onNow.Add(_prog); //add show on right now
                }
                else
                {
                    //do nada
                }

            }

            return _onNow;
        }