//StringNiceName(int season) //{ // // something like "Simpsons (S3)" // return String.Concat(ShowName," (S",season,")"); //} public void WriteXMLSettings(XmlWriter writer) { writer.WriteStartElement("ShowItem"); XMLHelper.WriteElementToXML(writer, "UseCustomShowName", this.UseCustomShowName); XMLHelper.WriteElementToXML(writer, "CustomShowName", this.CustomShowName); XMLHelper.WriteElementToXML(writer, "ShowNextAirdate", this.ShowNextAirdate); XMLHelper.WriteElementToXML(writer, "TVDBID", this.TVDBCode); XMLHelper.WriteElementToXML(writer, "AutoAddNewSeasons", this.AutoAddNewSeasons); XMLHelper.WriteElementToXML(writer, "FolderBase", this.AutoAdd_FolderBase); XMLHelper.WriteElementToXML(writer, "FolderPerSeason", this.AutoAdd_FolderPerSeason); XMLHelper.WriteElementToXML(writer, "SeasonFolderName", this.AutoAdd_SeasonFolderName); XMLHelper.WriteElementToXML(writer, "DoRename", this.DoRename); XMLHelper.WriteElementToXML(writer, "DoMissingCheck", this.DoMissingCheck); XMLHelper.WriteElementToXML(writer, "CountSpecials", this.CountSpecials); XMLHelper.WriteElementToXML(writer, "DVDOrder", this.DVDOrder); XMLHelper.WriteElementToXML(writer, "ForceCheckNoAirdate", this.ForceCheckNoAirdate); XMLHelper.WriteElementToXML(writer, "ForceCheckFuture", this.ForceCheckFuture); XMLHelper.WriteElementToXML(writer, "UseSequentialMatch", this.UseSequentialMatch); XMLHelper.WriteElementToXML(writer, "PadSeasonToTwoDigits", this.PadSeasonToTwoDigits); XMLHelper.WriteElementToXML(writer, "BannersLastUpdatedOnDisk", this.BannersLastUpdatedOnDisk); writer.WriteStartElement("IgnoreSeasons"); foreach (int i in this.IgnoreSeasons) { XMLHelper.WriteElementToXML(writer, "Ignore", i); } writer.WriteEndElement(); writer.WriteStartElement("AliasNames"); foreach (string str in this.AliasNames) { XMLHelper.WriteElementToXML(writer, "Alias", str); } writer.WriteEndElement(); XMLHelper.WriteElementToXML(writer, "CustomSearchURL", this.CustomSearchURL); foreach (KeyValuePair <int, List <ShowRule> > kvp in this.SeasonRules) { if (kvp.Value.Count > 0) { writer.WriteStartElement("Rules"); XMLHelper.WriteAttributeToXML(writer, "SeasonNumber", kvp.Key); foreach (ShowRule r in kvp.Value) { r.WriteXML(writer); } writer.WriteEndElement(); // Rules } } foreach (KeyValuePair <int, List <String> > kvp in this.ManualFolderLocations) { if (kvp.Value.Count > 0) { writer.WriteStartElement("SeasonFolders"); XMLHelper.WriteAttributeToXML(writer, "SeasonNumber", kvp.Key); foreach (string s in kvp.Value) { writer.WriteStartElement("Folder"); XMLHelper.WriteAttributeToXML(writer, "Location", s); writer.WriteEndElement(); // Folder } writer.WriteEndElement(); // Rules } } writer.WriteEndElement(); // ShowItem }
public bool Go(ref bool pause, TVRenameStats stats) { XmlWriterSettings settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = true }; // "try" and silently fail. eg. when file is use by other... XmlWriter writer; try { // XmlWriter writer = XmlWriter.Create(this.Where.FullName, settings); writer = XmlWriter.Create(this.Where.FullName, settings); if (writer == null) { return(false); } } catch (Exception) { this.Done = true; return(true); } if (this.Episode != null) // specific episode { // See: http://xbmc.org/wiki/?title=Import_-_Export_Library#TV_Episodes writer.WriteStartElement("episodedetails"); XMLHelper.WriteElementToXML(writer, "title", this.Episode.Name); XMLHelper.WriteElementToXML(writer, "rating", this.Episode.EpisodeRating); XMLHelper.WriteElementToXML(writer, "season", this.Episode.SeasonNumber); XMLHelper.WriteElementToXML(writer, "episode", this.Episode.EpNum); XMLHelper.WriteElementToXML(writer, "plot", this.Episode.Overview); writer.WriteStartElement("aired"); if (this.Episode.FirstAired != null) { writer.WriteValue(this.Episode.FirstAired.Value.ToString("yyyy-MM-dd")); } writer.WriteEndElement(); if (this.Episode.SI != null) { WriteInfo(writer, this.Episode.SI, "ContentRating", "mpaa"); } //Director(s) if (!String.IsNullOrEmpty(this.Episode.EpisodeDirector)) { string EpDirector = this.Episode.EpisodeDirector; if (!string.IsNullOrEmpty(EpDirector)) { foreach (string Daa in EpDirector.Split('|')) { if (string.IsNullOrEmpty(Daa)) { continue; } XMLHelper.WriteElementToXML(writer, "director", Daa); } } } //Writers(s) if (!String.IsNullOrEmpty(this.Episode.Writer)) { string EpWriter = this.Episode.Writer; if (!string.IsNullOrEmpty(EpWriter)) { XMLHelper.WriteElementToXML(writer, "credits", EpWriter); } } // Guest Stars... if (!String.IsNullOrEmpty(this.Episode.EpisodeGuestStars)) { string RecurringActors = ""; if (this.Episode.SI != null) { RecurringActors = this.Episode.SI.TheSeries().GetItem("Actors"); } string GuestActors = this.Episode.EpisodeGuestStars; if (!string.IsNullOrEmpty(GuestActors)) { foreach (string Gaa in GuestActors.Split('|')) { if (string.IsNullOrEmpty(Gaa)) { continue; } // Skip if the guest actor is also in the overal recurring list if (!string.IsNullOrEmpty(RecurringActors) && RecurringActors.Contains(Gaa)) { continue; } writer.WriteStartElement("actor"); XMLHelper.WriteElementToXML(writer, "name", Gaa); writer.WriteEndElement(); // actor } } } // actors... if (this.Episode.SI != null) { string actors = this.Episode.SI.TheSeries().GetItem("Actors"); if (!string.IsNullOrEmpty(actors)) { foreach (string aa in actors.Split('|')) { if (string.IsNullOrEmpty(aa)) { continue; } writer.WriteStartElement("actor"); XMLHelper.WriteElementToXML(writer, "name", aa); writer.WriteEndElement(); // actor } } } writer.WriteEndElement(); // episodedetails } else if (this.SI != null) // show overview (tvshow.nfo) { // http://www.xbmc.org/wiki/?title=Import_-_Export_Library#TV_Shows writer.WriteStartElement("tvshow"); XMLHelper.WriteElementToXML(writer, "title", this.SI.ShowName); XMLHelper.WriteElementToXML(writer, "episodeguideurl", TheTVDB.BuildURL(true, true, this.SI.TVDBCode, TheTVDB.Instance.RequestLanguage)); WriteInfo(writer, this.SI, "Overview", "plot"); string genre = this.SI.TheSeries().GetItem("Genre"); if (!string.IsNullOrEmpty(genre)) { genre = genre.Trim('|'); genre = genre.Replace("|", " / "); XMLHelper.WriteElementToXML(writer, "genre", genre); } WriteInfo(writer, this.SI, "FirstAired", "premiered"); WriteInfo(writer, this.SI, "Year", "year"); WriteInfo(writer, this.SI, "Rating", "rating"); WriteInfo(writer, this.SI, "Status", "status"); // actors... string actors = this.SI.TheSeries().GetItem("Actors"); if (!string.IsNullOrEmpty(actors)) { foreach (string aa in actors.Split('|')) { if (string.IsNullOrEmpty(aa)) { continue; } writer.WriteStartElement("actor"); XMLHelper.WriteElementToXML(writer, "name", aa); writer.WriteEndElement(); // actor } } WriteInfo(writer, this.SI, "ContentRating", "mpaa"); WriteInfo(writer, this.SI, "IMDB_ID", "id", "moviedb", "imdb"); XMLHelper.WriteElementToXML(writer, "tvdbid", this.SI.TheSeries().TVDBCode); string rt = this.SI.TheSeries().GetItem("Runtime"); if (!string.IsNullOrEmpty(rt)) { XMLHelper.WriteElementToXML(writer, "runtime", rt + " minutes"); } writer.WriteEndElement(); // tvshow } try { writer.Close(); } catch (Exception e) { this.ErrorText = e.Message; this.Error = true; this.Done = true; return(false); } this.Done = true; return(true); }
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 == "Director") { 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 == "") { System.Diagnostics.Debug.Print("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; } message += "\r\n" + e.Message; if (!args.Unattended) { MessageBox.Show(message, "TVRename", MessageBoxButtons.OK, MessageBoxIcon.Error); } throw new TVDBException(e.Message); } }
public void Write(XmlWriter writer) { XMLHelper.WriteElementToXML(writer, "Ignore", this.FileAndPath); }
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.tempTimeZone = 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 TheTVDB.TVDBException(e.Message); } }