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; }
/// <summary> /// Parses the XML files with tv listing. Called after the downloader thread has finished. /// </summary> private void parseFiles(string[] _files) { foreach (string file in _files) { string _fileName = prefs.XMLFileStoragePath + file; XMLTVParser parser; String strXMLFileContents = ""; if (_fileName.EndsWith(".xml.gz")) { //LOG: this // decompress the gziped file to string, and send content to xmltv parser GzipDecompressor gzPack = new GzipDecompressor(); strXMLFileContents = gzPack.Decompress(_fileName); } else { if (_fileName.EndsWith(".xml")) { //LOG: this //no need for decompression, read filestream into string at once... StreamReader st = new StreamReader(_fileName); 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); } } }