public void LoadXml(XmlReader r) { //<Data> // <Series> // <id>...</id> // etc. // </Series> // <Episode> // <id>...</id> // blah blah // </Episode> // <Episode> // <id>...</id> // blah blah // </Episode> // ... //</Data> try { r.Read(); if (r.Name != "Series") { return; } r.Read(); while (!r.EOF) { if ((r.Name == "Series") && (!r.IsStartElement())) { break; } if (r.Name == "id") { this.TVDBCode = r.ReadElementContentAsInt(); } else if (r.Name == "SeriesName") { this.Name = XMLHelper.ReadStringFixQuotesAndSpaces(r); } else if (r.Name == "lastupdated") { this.Srv_LastUpdated = r.ReadElementContentAsLong(); } else if ((r.Name == "Language") || (r.Name == "language")) { string ignore = r.ReadElementContentAsString(); } else if ((r.Name == "LanguageId") || (r.Name == "languageId")) { this.LanguageId = r.ReadElementContentAsInt(); } else if (r.Name == "TimeZone") { this.ShowTimeZone = r.ReadElementContentAsString(); } else if (r.Name == "Airs_Time") { this.AirsTime = DateTime.Parse("20:00"); string theTime = r.ReadElementContentAsString(); try { if (!string.IsNullOrEmpty(theTime)) { this.Items["Airs_Time"] = theTime; DateTime airsTime; if (DateTime.TryParse(theTime, out airsTime) | DateTime.TryParse(theTime.Replace('.', ':'), out airsTime)) { this.AirsTime = airsTime; } else { this.AirsTime = null; } } } catch (FormatException) { logger.Trace("Failed to parse time: {0} ", theTime); } } else if (r.Name == "FirstAired") { string theDate = r.ReadElementContentAsString(); try { this.FirstAired = DateTime.ParseExact(theDate, "yyyy-MM-dd", new System.Globalization.CultureInfo("")); this.Items["FirstAired"] = this.FirstAired.Value.ToString("yyyy-MM-dd"); this.Items["Year"] = this.FirstAired.Value.ToString("yyyy"); } catch { logger.Trace("Failed to parse date: {0} ", theDate); this.FirstAired = null; this.Items["FirstAired"] = ""; this.Items["Year"] = ""; } } else { string name = r.Name; this.Items[name] = r.ReadElementContentAsString(); } // r->ReadOuterXml(); // skip } // while } // try catch (XmlException e) { string message = "Error processing data from TheTVDB for a show."; if (this.TVDBCode != -1) { message += "\r\nTheTVDB Code: " + this.TVDBCode; } if (!string.IsNullOrEmpty(this.Name)) { message += "\r\nName: " + this.Name; } message += "\r\nLanguage: \"" + this.LanguageId + "\""; message += "\r\n" + e.Message; logger.Error(e, message); throw new TVDBException(e.Message); } }
public Banner(SeriesInfo ser, Season seas, int?codeHint, XmlReader r, CommandLineArgs args) { // <Banner> // <id>708811</id> // <BannerPath>seasonswide/79488-5.jpg</BannerPath> // <BannerType>season</BannerType> // <BannerType2>seasonwide</BannerType2> // <Language>en</Language> // <Rating/> // <RatingCount>0</RatingCount> // <Season>5</Season> // blah blah // </Banner> try { this.SetDefaults(ser, seas); this.SeriesID = (int)codeHint; r.Read(); if (r.Name != "Banner") { return; } r.Read(); while (!r.EOF) { if ((r.Name == "Banner") && (!r.IsStartElement())) { break; } if (r.Name == "id") { this.BannerId = r.ReadElementContentAsInt(); } else if (r.Name == "seriesid") { this.SeriesID = r.ReadElementContentAsInt(); // thetvdb series id } else if (r.Name == "seasonid") { this.SeasonID = r.ReadElementContentAsInt(); } else if (r.Name == "BannerPath") { this.BannerPath = XMLHelper.ReadStringFixQuotesAndSpaces(r); } else if (r.Name == "BannerType") { this.BannerType = r.ReadElementContentAsString(); } else if (r.Name == "LanguageId") { this.LanguageId = r.ReadElementContentAsInt(); } else if (r.Name == "Resolution") { this.Resolution = r.ReadElementContentAsString(); } else if (r.Name == "Rating") { String sn = r.ReadElementContentAsString(); double.TryParse(sn, out this.Rating); } else if (r.Name == "RatingCount") { this.RatingCount = r.ReadElementContentAsInt(); } else if (r.Name == "Season") { this.SeasonID = r.ReadElementContentAsInt(); } else if (r.Name == "ThumbnailPath") { this.ThumbnailPath = r.ReadElementContentAsString(); } else { if ((r.IsEmptyElement) || !r.IsStartElement()) { r.ReadOuterXml(); } else { r.Read(); } } } } catch (XmlException e) { string message = "Error processing data from TheTVDB for a banner."; if (this.SeriesID != -1) { message += "\r\nSeries ID: " + this.SeriesID; } if (this.BannerId != -1) { message += "\r\nBanner ID: " + this.BannerId; } if (!string.IsNullOrEmpty(this.BannerPath)) { message += "\r\nBanner Path: " + this.BannerPath; } message += "\r\n" + e.Message; if (!args.Unattended) { MessageBox.Show(message, "TVRename", MessageBoxButtons.OK, MessageBoxIcon.Error); } throw new TVDBException(e.Message); } }
public Episode(SeriesInfo ser, Season seas, XmlReader r, CommandLineArgs args) { // <Episode> // <id>...</id> // blah blah // </Episode> try { this.SetDefaults(ser, seas); r.Read(); if (r.Name != "Episode") { return; } r.Read(); while (!r.EOF) { if ((r.Name == "Episode") && (!r.IsStartElement())) { break; } if (r.Name == "id") { this.EpisodeID = r.ReadElementContentAsInt(); } else if (r.Name == "seriesid") { this.SeriesID = r.ReadElementContentAsInt(); // thetvdb series id } else if (r.Name == "seasonid") { this.SeasonID = r.ReadElementContentAsInt(); } else if (r.Name == "EpisodeNumber") { this.EpNum = r.ReadElementContentAsInt(); } else if (r.Name == "SeasonNumber") { String sn = r.ReadElementContentAsString(); int.TryParse(sn, out this.ReadSeasonNum); } else if (r.Name == "lastupdated") { this.Srv_LastUpdated = r.ReadElementContentAsInt(); } else if (r.Name == "Overview") { this.Overview = XMLHelper.ReadStringFixQuotesAndSpaces(r); } else if (r.Name == "Rating") { this.EpisodeRating = XMLHelper.ReadStringFixQuotesAndSpaces(r); } else if (r.Name == "GuestStars") { this.EpisodeGuestStars = XMLHelper.ReadStringFixQuotesAndSpaces(r); } else if (r.Name == "EpisodeDirector") { this.EpisodeDirector = XMLHelper.ReadStringFixQuotesAndSpaces(r); } else if (r.Name == "Writer") { this.Writer = XMLHelper.ReadStringFixQuotesAndSpaces(r); } else if (r.Name == "EpisodeName") { this.Name = XMLHelper.ReadStringFixQuotesAndSpaces(r); } else if (r.Name == "FirstAired") { try { String contents = r.ReadElementContentAsString(); if (contents == "") { logger.Info("Please confirm, but we are assuming that " + this.Name + "(episode Id =" + this.EpisodeID + ") has no airdate"); this.FirstAired = null; } else { this.FirstAired = DateTime.ParseExact(contents, "yyyy-MM-dd", new System.Globalization.CultureInfo("")); } } catch { this.FirstAired = null; } } else { if ((r.IsEmptyElement) || !r.IsStartElement()) { r.ReadOuterXml(); } else { XmlReader r2 = r.ReadSubtree(); r2.Read(); string name = r2.Name; this.Items[name] = r2.ReadElementContentAsString(); r.Read(); } } } } catch (XmlException e) { string message = "Error processing data from TheTVDB for an episode."; if (this.SeriesID != -1) { message += "\r\nSeries ID: " + this.SeriesID; } if (this.EpisodeID != -1) { message += "\r\nEpisode ID: " + this.EpisodeID; } if (this.EpNum != -1) { message += "\r\nEpisode Number: " + this.EpNum; } if (!string.IsNullOrEmpty(this.Name)) { message += "\r\nName: " + this.Name; } logger.Error(e, message); throw new TVDBException(e.Message); } }